Polish whitespace and imports

As part of pull request #179, commits 0d922e1, 003249c and d099100
introduced use of Java 8 language features and APIs. Commit c95f5ea
manually reverted these changes (see #184 as to why), but in the process
re-introduced formatting issues originally cleaned up by other commits
in #179. This change fixes those formatting issues.

 - Replace leading tabs with spaces (for reasons detailed in 0827fb5)
 - Add space before opening curly brace
 - Optimize imports using shared .idea/codeStyleSettings.xml (note
   especially expansion of wildcard imports. See rationale in 780393d)
 - Do not align assignments on equals sign
 - Remove unnecessary additional newlines
 - Remove braces from single-line loops and conditionals
This commit is contained in:
Chris Beams 2014-12-30 19:24:49 +01:00
parent c95f5ea75f
commit a155518b41
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
18 changed files with 96 additions and 108 deletions

View File

@ -13,21 +13,17 @@ plugins {
mainClassName = 'org.ethereum.Start' mainClassName = 'org.ethereum.Start'
ext.generatedSrcDir = file('src/gen/java') ext.generatedSrcDir = file('src/gen/java')
sourceSets.main.java.srcDirs += generatedSrcDir sourceSets.main.java.srcDirs += generatedSrcDir
antlr4 { antlr4 {
extraArgs = ['-package', 'org.ethereum.serpent'] extraArgs = ['-package', 'org.ethereum.serpent']
output = file("${generatedSrcDir}/org/ethereum/serpent") output = file("${generatedSrcDir}/org/ethereum/serpent")
} }
compileJava.dependsOn antlr4 compileJava.dependsOn antlr4
configurations { configurations {
compile.extendsFrom antlr4 compile.extendsFrom antlr4
} }

View File

@ -82,7 +82,8 @@ public class Wallet {
Account account = new Account(); Account account = new Account();
String address = Hex.toHexString(account.getEcKey().getAddress()); String address = Hex.toHexString(account.getEcKey().getAddress());
rows.put(address, account); rows.put(address, account);
for (WalletListener listener : listeners) listener.valueChanged(); for (WalletListener listener : listeners)
listener.valueChanged();
} }
public void importKey(byte[] privKey) { public void importKey(byte[] privKey) {
@ -157,9 +158,9 @@ public class Wallet {
} }
public void addTransactions(List<Transaction> transactions) { public void addTransactions(List<Transaction> transactions) {
for (Transaction transaction : transactions) { for (Transaction transaction : transactions) {
this.addTransaction(transaction); this.addTransaction(transaction);
} }
} }
public void removeTransactions(List<Transaction> transactions) { public void removeTransactions(List<Transaction> transactions) {
@ -209,7 +210,7 @@ public class Wallet {
public void processBlock(Block block) { public void processBlock(Block block) {
for (Account account : getAccountCollection()){ for (Account account : getAccountCollection()) {
account.clearAllPendingTransactions(); account.clearAllPendingTransactions();
} }
@ -344,8 +345,8 @@ public class Wallet {
} }
private void notifyListeners() { private void notifyListeners() {
for (WalletListener listener : listeners) for (WalletListener listener : listeners)
listener.valueChanged(); listener.valueChanged();
} }
public interface WalletListener { public interface WalletListener {

View File

@ -74,9 +74,8 @@ public class BlockStore {
setParameter("limit", block.getNumber() - qty). setParameter("limit", block.getNumber() - qty).
setMaxResults(qty).list(); setMaxResults(qty).list();
for (byte[] h : result){ for (byte[] h : result)
hashes.add(h); hashes.add(h);
}
return hashes; return hashes;
} }

View File

@ -61,9 +61,9 @@ public class EthereumImpl implements Ethereum {
} }
@PostConstruct @PostConstruct
public void init(){ public void init() {
worldManager.loadBlockchain(); worldManager.loadBlockchain();
if (CONFIG.listenPort() > 0){ if (CONFIG.listenPort() > 0) {
Executors.newSingleThreadExecutor().submit( Executors.newSingleThreadExecutor().submit(
new Runnable() { public void run() { new Runnable() { public void run() {
peerServer.start(CONFIG.listenPort()); peerServer.start(CONFIG.listenPort());

View File

@ -153,8 +153,8 @@ public class AccountState {
checked.add(key); checked.add(key);
} }
for (DataWord key : expectedKeys){ for (DataWord key : expectedKeys) {
if (!checked.contains(key)){ if (!checked.contains(key)) {
String formatedString = String.format("Account: %s: doesn't exist expected storage key: %s", String formatedString = String.format("Account: %s: doesn't exist expected storage key: %s",
Hex.toHexString(this.address), key.toString()); Hex.toHexString(this.address), key.toString());
results.add(formatedString); results.add(formatedString);

View File

@ -1,6 +1,10 @@
package org.ethereum.manager; package org.ethereum.manager;
import org.ethereum.core.*; import org.ethereum.core.Block;
import org.ethereum.core.Genesis;
import org.ethereum.core.Transaction;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.core.Wallet;
import org.ethereum.crypto.HashUtil; import org.ethereum.crypto.HashUtil;
import org.ethereum.db.BlockStore; import org.ethereum.db.BlockStore;
import org.ethereum.facade.Blockchain; import org.ethereum.facade.Blockchain;

View File

@ -43,15 +43,14 @@ public class BlockHashesMessage extends EthMessage {
parsed = true; parsed = true;
} }
private void encode() { private void encode() {
List<byte[]> encodedElements = new ArrayList<>(); List<byte[]> encodedElements = new ArrayList<>();
encodedElements.add(RLP.encodeByte(BLOCK_HASHES.asByte())); encodedElements.add(RLP.encodeByte(BLOCK_HASHES.asByte()));
for (byte[] blockHash : blockHashes) for (byte[] blockHash : blockHashes)
encodedElements.add(RLP.encodeElement(blockHash)); encodedElements.add(RLP.encodeElement(blockHash));
byte[][] encodedElementArray = encodedElements byte[][] encodedElementArray = encodedElements.toArray(new byte[encodedElements.size()][]);
.toArray(new byte[encodedElements.size()][]); this.encoded = RLP.encodeList(encodedElementArray);
this.encoded = RLP.encodeList(encodedElementArray); }
}
@Override @Override

View File

@ -46,9 +46,8 @@ public class BlocksMessage extends EthMessage {
List<byte[]> encodedElements = new Vector<>(); List<byte[]> encodedElements = new Vector<>();
encodedElements.add(RLP.encodeByte(BLOCKS.asByte())); encodedElements.add(RLP.encodeByte(BLOCKS.asByte()));
for (Block block : blocks){ for (Block block : blocks)
encodedElements.add(block.getEncoded()); encodedElements.add(block.getEncoded());
}
byte[][] encodedElementArray = encodedElements byte[][] encodedElementArray = encodedElements
.toArray(new byte[encodedElements.size()][]); .toArray(new byte[encodedElements.size()][]);

View File

@ -41,15 +41,14 @@ public class GetBlocksMessage extends EthMessage {
parsed = true; parsed = true;
} }
private void encode() { private void encode() {
List<byte[]> encodedElements = new ArrayList<>(); List<byte[]> encodedElements = new ArrayList<>();
encodedElements.add(RLP.encodeByte(GET_BLOCKS.asByte())); encodedElements.add(RLP.encodeByte(GET_BLOCKS.asByte()));
for (byte[] hash : blockHashes) for (byte[] hash : blockHashes)
encodedElements.add(RLP.encodeElement(hash)); encodedElements.add(RLP.encodeElement(hash));
byte[][] encodedElementArray = encodedElements byte[][] encodedElementArray = encodedElements.toArray(new byte[encodedElements.size()][]);
.toArray(new byte[encodedElements.size()][]); this.encoded = RLP.encodeList(encodedElementArray);
this.encoded = RLP.encodeList(encodedElementArray); }
}
@Override @Override
public byte[] getEncoded() { public byte[] getEncoded() {

View File

@ -50,12 +50,11 @@ public class TransactionsMessage extends EthMessage {
} }
private void encode() { private void encode() {
List<byte[]> encodedElements = new ArrayList<>(); List<byte[]> encodedElements = new ArrayList<>();
encodedElements.add(RLP.encodeByte(TRANSACTIONS.asByte())); encodedElements.add(RLP.encodeByte(TRANSACTIONS.asByte()));
for (Transaction tx : transactions) for (Transaction tx : transactions)
encodedElements.add(tx.getEncoded()); encodedElements.add(tx.getEncoded());
byte[][] encodedElementArray = encodedElements byte[][] encodedElementArray = encodedElements.toArray(new byte[encodedElements.size()][]);
.toArray(new byte[encodedElements.size()][]);
this.encoded = RLP.encodeList(encodedElementArray); this.encoded = RLP.encodeList(encodedElementArray);
} }

View File

@ -207,31 +207,32 @@ public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
private void setHandshake(HelloMessage msg, ChannelHandlerContext ctx) { private void setHandshake(HelloMessage msg, ChannelHandlerContext ctx) {
this.handshakeHelloMessage = msg; this.handshakeHelloMessage = msg;
if (msg.getP2PVersion() != P2pHandler.VERSION) if (msg.getP2PVersion() != P2pHandler.VERSION) {
msgQueue.sendMessage(new DisconnectMessage(ReasonCode.INCOMPATIBLE_PROTOCOL)); msgQueue.sendMessage(new DisconnectMessage(ReasonCode.INCOMPATIBLE_PROTOCOL));
else { }
List<Capability> capInCommon = new ArrayList<>(); else {
for (Capability capability : msg.getCapabilities()) { List<Capability> capInCommon = new ArrayList<>();
if (HELLO_MESSAGE.getCapabilities().contains(capability)) { for (Capability capability : msg.getCapabilities()) {
if (capability.getName().equals(Capability.ETH)){ if (HELLO_MESSAGE.getCapabilities().contains(capability)) {
if (capability.getName().equals(Capability.ETH)) {
// Activate EthHandler for this peer // Activate EthHandler for this peer
EthHandler ethHandler = EthHandler ethHandler =
(EthHandler)ctx.pipeline().get(Capability.ETH); (EthHandler) ctx.pipeline().get(Capability.ETH);
ethHandler.setPeerId(msg.getPeerId()); ethHandler.setPeerId(msg.getPeerId());
ethHandler.activate(); ethHandler.activate();
} }
else if (capability.getName().equals(Capability.SHH)){ else if (capability.getName().equals(Capability.SHH)) {
// Activate ShhHandler for this peer // Activate ShhHandler for this peer
ShhHandler shhHandler = ShhHandler shhHandler =
(ShhHandler)ctx.pipeline().get(Capability.SHH); (ShhHandler) ctx.pipeline().get(Capability.SHH);
shhHandler.activate(); shhHandler.activate();
} }
capInCommon.add(capability); capInCommon.add(capability);
} }
} }
adaptMessageIds(capInCommon); adaptMessageIds(capInCommon);
InetAddress address = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress(); InetAddress address = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress();

View File

@ -59,10 +59,9 @@ public class PeerDiscovery {
// Get the ThreadFactory implementation to use // Get the ThreadFactory implementation to use
threadFactory = Executors.defaultThreadFactory(); threadFactory = Executors.defaultThreadFactory();
// creating the ThreadPoolExecutor // creating the ThreadPoolExecutor
executorPool = new ThreadPoolExecutor(CONFIG.peerDiscoveryWorkers(), executorPool = new ThreadPoolExecutor(CONFIG.peerDiscoveryWorkers(), CONFIG.peerDiscoveryWorkers(), 10,
CONFIG.peerDiscoveryWorkers(), 10, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>( TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1000), threadFactory, rejectionHandler);
1000), threadFactory, rejectionHandler);
// start the monitoring thread // start the monitoring thread
monitor = new PeerMonitorThread(executorPool, 1, this); monitor = new PeerMonitorThread(executorPool, 1, this);

View File

@ -108,9 +108,8 @@ public class ChannelManager {
} }
public void reconnect(){ public void reconnect(){
for (Channel channel : channels){ for (Channel channel : channels)
channel.p2pHandler.sendDisconnect(); channel.p2pHandler.sendDisconnect();
}
} }
public void ethSync() { public void ethSync() {

View File

@ -11,8 +11,11 @@ import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
import java.util.*; import java.util.Arrays;
import java.util.stream.Collectors; import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static java.util.Arrays.copyOfRange; import static java.util.Arrays.copyOfRange;
import static org.ethereum.crypto.HashUtil.EMPTY_TRIE_HASH; import static org.ethereum.crypto.HashUtil.EMPTY_TRIE_HASH;
@ -434,17 +437,14 @@ public class TrieImpl implements Trie {
this.scanTree(this.getRootHash(), collectAction); this.scanTree(this.getRootHash(), collectAction);
Set<byte[]> hashSet = collectAction.getCollectedHashes(); Set<byte[]> hashSet = collectAction.getCollectedHashes();
Map<ByteArrayWrapper, Node> nodes = this.getCache().getNodes(); Map<ByteArrayWrapper, Node> nodes = this.getCache().getNodes();
Set<ByteArrayWrapper> toRemoveSet = new HashSet<>(); Set<ByteArrayWrapper> toRemoveSet = new HashSet<>();
for (ByteArrayWrapper key : nodes.keySet()) { for (ByteArrayWrapper key : nodes.keySet())
if (!hashSet.contains(key.getData())) { if (!hashSet.contains(key.getData()))
toRemoveSet.add(key); toRemoveSet.add(key);
}
}
for (ByteArrayWrapper key : toRemoveSet) { for (ByteArrayWrapper key : toRemoveSet) {
this.getCache().delete(key.getData()); this.getCache().delete(key.getData());
if (logger.isTraceEnabled()) if (logger.isTraceEnabled())

View File

@ -130,24 +130,24 @@ public abstract class FastByteComparisons {
*/ */
static final int BYTE_ARRAY_BASE_OFFSET; static final int BYTE_ARRAY_BASE_OFFSET;
static { static {
theUnsafe = (Unsafe) AccessController.doPrivileged( theUnsafe = (Unsafe) AccessController.doPrivileged(
new PrivilegedAction<Object>() { new PrivilegedAction<Object>() {
@Override @Override
public Object run() { public Object run() {
try { try {
Field f = Unsafe.class.getDeclaredField("theUnsafe"); Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true); f.setAccessible(true);
return f.get(null); return f.get(null);
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
// It doesn't matter what we throw; // It doesn't matter what we throw;
// it's swallowed in getBestComparer(). // it's swallowed in getBestComparer().
throw new Error(); throw new Error();
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new Error(); throw new Error();
} }
} }
}); });
BYTE_ARRAY_BASE_OFFSET = theUnsafe.arrayBaseOffset(byte[].class); BYTE_ARRAY_BASE_OFFSET = theUnsafe.arrayBaseOffset(byte[].class);

View File

@ -24,11 +24,10 @@ public class RLPList extends ArrayList<RLPElement> implements RLPElement {
throw new RuntimeException("RLPElement object can't be null"); throw new RuntimeException("RLPElement object can't be null");
if (element instanceof RLPList) { if (element instanceof RLPList) {
RLPList rlpList = (RLPList) element; RLPList rlpList = (RLPList) element;
System.out.print("["); System.out.print("[");
for (RLPElement singleElement : rlpList) { for (RLPElement singleElement : rlpList)
recursivePrint(singleElement); recursivePrint(singleElement);
}
System.out.print("]"); System.out.print("]");
} else { } else {
String hex = ByteUtil.toHexString(element.getRLPData()); String hex = ByteUtil.toHexString(element.getRLPData());

View File

@ -46,9 +46,9 @@ public class LogInfo {
} }
public LogInfo(byte[] address, List<DataWord> topics, byte[] data) { public LogInfo(byte[] address, List<DataWord> topics, byte[] data) {
this.address = (address != null) ? address : new byte[]{} ; this.address = (address != null) ? address : new byte[]{};
this.topics = (topics != null) ? topics : new ArrayList<DataWord>(); this.topics = (topics != null) ? topics : new ArrayList<DataWord>();
this.data = (data != null) ? data : new byte[]{} ; this.data = (data != null) ? data : new byte[]{};
} }
public byte[] getAddress() { public byte[] getAddress() {

View File

@ -77,11 +77,9 @@ public class GitHubJSONTestSuite {
TestRunner runner = new TestRunner(); TestRunner runner = new TestRunner();
List<String> result = runner.runTestCase(testCase); List<String> result = runner.runTestCase(testCase);
if (!result.isEmpty()){ if (!result.isEmpty())
for (String single : result){ for (String single : result)
logger.info(single); logger.info(single);
}
}
Assert.assertTrue(result.isEmpty()); Assert.assertTrue(result.isEmpty());
} }
@ -109,11 +107,9 @@ public class GitHubJSONTestSuite {
TestRunner runner = new TestRunner(); TestRunner runner = new TestRunner();
List<String> result = runner.runTestCase(testCase); List<String> result = runner.runTestCase(testCase);
if (!result.isEmpty()){ if (!result.isEmpty())
for (String single : result){ for (String single : result)
logger.info(single); logger.info(single);
}
}
Assert.assertTrue(result.isEmpty()); Assert.assertTrue(result.isEmpty());
} }
@ -135,11 +131,9 @@ public class GitHubJSONTestSuite {
TestRunner runner = new TestRunner(); TestRunner runner = new TestRunner();
List<String> result = runner.runTestCase(testCase); List<String> result = runner.runTestCase(testCase);
if (!result.isEmpty()){ if (!result.isEmpty())
for (String single : result){ for (String single : result)
logger.info(single); logger.info(single);
}
}
Assert.assertTrue(result.isEmpty()); Assert.assertTrue(result.isEmpty());
} }