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'
ext.generatedSrcDir = file('src/gen/java')
sourceSets.main.java.srcDirs += generatedSrcDir
antlr4 {
extraArgs = ['-package', 'org.ethereum.serpent']
output = file("${generatedSrcDir}/org/ethereum/serpent")
}
compileJava.dependsOn antlr4
configurations {
compile.extendsFrom antlr4
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,10 @@
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.db.BlockStore;
import org.ethereum.facade.Blockchain;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -130,24 +130,24 @@ public abstract class FastByteComparisons {
*/
static final int BYTE_ARRAY_BASE_OFFSET;
static {
theUnsafe = (Unsafe) AccessController.doPrivileged(
new PrivilegedAction<Object>() {
@Override
public Object run() {
try {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return f.get(null);
} catch (NoSuchFieldException e) {
// It doesn't matter what we throw;
// it's swallowed in getBestComparer().
throw new Error();
} catch (IllegalAccessException e) {
throw new Error();
}
}
});
static {
theUnsafe = (Unsafe) AccessController.doPrivileged(
new PrivilegedAction<Object>() {
@Override
public Object run() {
try {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return f.get(null);
} catch (NoSuchFieldException e) {
// It doesn't matter what we throw;
// it's swallowed in getBestComparer().
throw new Error();
} catch (IllegalAccessException e) {
throw new Error();
}
}
});
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");
if (element instanceof RLPList) {
RLPList rlpList = (RLPList) element;
System.out.print("[");
for (RLPElement singleElement : rlpList) {
recursivePrint(singleElement);
}
RLPList rlpList = (RLPList) element;
System.out.print("[");
for (RLPElement singleElement : rlpList)
recursivePrint(singleElement);
System.out.print("]");
} else {
String hex = ByteUtil.toHexString(element.getRLPData());

View File

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

View File

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