Collapse foreach loops using Iterable#forEach

This commit is contained in:
Chris Beams 2014-12-27 03:02:53 +01:00
parent 003249cb77
commit 0d922e1b30
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
4 changed files with 25 additions and 40 deletions

View File

@ -82,7 +82,7 @@ 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(); listeners.forEach(Wallet.WalletListener::valueChanged);
} }
public void importKey(byte[] privKey) { public void importKey(byte[] privKey) {
@ -158,9 +158,7 @@ public class Wallet {
} }
public void addTransactions(List<Transaction> transactions) { public void addTransactions(List<Transaction> transactions) {
for (Transaction transaction : transactions) { transactions.forEach(this::addTransaction);
this.addTransaction(transaction);
}
} }
public void removeTransactions(List<Transaction> transactions) { public void removeTransactions(List<Transaction> transactions) {
@ -210,9 +208,7 @@ public class Wallet {
public void processBlock(Block block) { public void processBlock(Block block) {
for (Account account : getAccountCollection()) { getAccountCollection().forEach(org.ethereum.core.Account::clearAllPendingTransactions);
account.clearAllPendingTransactions();
}
notifyListeners(); notifyListeners();
} }
@ -345,8 +341,7 @@ public class Wallet {
} }
private void notifyListeners() { private void notifyListeners() {
for (WalletListener listener : listeners) listeners.forEach(Wallet.WalletListener::valueChanged);
listener.valueChanged();
} }
public interface WalletListener { public interface WalletListener {

View File

@ -211,26 +211,24 @@ public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
msgQueue.sendMessage(new DisconnectMessage(ReasonCode.INCOMPATIBLE_PROTOCOL)); msgQueue.sendMessage(new DisconnectMessage(ReasonCode.INCOMPATIBLE_PROTOCOL));
else { else {
List<Capability> capInCommon = new ArrayList<>(); List<Capability> capInCommon = new ArrayList<>();
for (Capability capability : msg.getCapabilities()) { msg.getCapabilities().stream()
if (HELLO_MESSAGE.getCapabilities().contains(capability)) { .filter(capability -> HELLO_MESSAGE.getCapabilities().contains(capability))
if (capability.getName().equals(Capability.ETH)) { .forEach(capability -> {
if (capability.getName().equals(Capability.ETH)) {
// Activate EthHandler for this peer
EthHandler ethHandler =
(EthHandler) ctx.pipeline().get(Capability.ETH);
// Activate EthHandler for this peer ethHandler.setPeerId(msg.getPeerId());
EthHandler ethHandler = ethHandler.activate();
(EthHandler) ctx.pipeline().get(Capability.ETH); } else if (capability.getName().equals(Capability.SHH)) {
// Activate ShhHandler for this peer
ethHandler.setPeerId(msg.getPeerId()); ShhHandler shhHandler =
ethHandler.activate(); (ShhHandler) ctx.pipeline().get(Capability.SHH);
} else if (capability.getName().equals(Capability.SHH)) { shhHandler.activate();
}
// Activate ShhHandler for this peer capInCommon.add(capability);
ShhHandler shhHandler = });
(ShhHandler) ctx.pipeline().get(Capability.SHH);
shhHandler.activate();
}
capInCommon.add(capability);
}
}
adaptMessageIds(capInCommon); adaptMessageIds(capInCommon);
InetAddress address = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress(); InetAddress address = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress();

View File

@ -26,9 +26,7 @@ public class RLPList extends ArrayList<RLPElement> implements RLPElement {
RLPList rlpList = (RLPList) element; RLPList rlpList = (RLPList) element;
System.out.print("["); System.out.print("[");
for (RLPElement singleElement : rlpList) { rlpList.forEach(org.ethereum.util.RLPList::recursivePrint);
recursivePrint(singleElement);
}
System.out.print("]"); System.out.print("]");
} else { } else {
String hex = ByteUtil.toHexString(element.getRLPData()); String hex = ByteUtil.toHexString(element.getRLPData());

View File

@ -78,9 +78,7 @@ public class GitHubJSONTestSuite {
List<String> result = runner.runTestCase(testCase); List<String> result = runner.runTestCase(testCase);
if (!result.isEmpty()) { if (!result.isEmpty()) {
for (String single : result) { result.forEach(logger::info);
logger.info(single);
}
} }
Assert.assertTrue(result.isEmpty()); Assert.assertTrue(result.isEmpty());
@ -110,9 +108,7 @@ public class GitHubJSONTestSuite {
List<String> result = runner.runTestCase(testCase); List<String> result = runner.runTestCase(testCase);
if (!result.isEmpty()) { if (!result.isEmpty()) {
for (String single : result) { result.forEach(logger::info);
logger.info(single);
}
} }
Assert.assertTrue(result.isEmpty()); Assert.assertTrue(result.isEmpty());
@ -136,9 +132,7 @@ public class GitHubJSONTestSuite {
List<String> result = runner.runTestCase(testCase); List<String> result = runner.runTestCase(testCase);
if (!result.isEmpty()) { if (!result.isEmpty()) {
for (String single : result) { result.forEach(logger::info);
logger.info(single);
}
} }
Assert.assertTrue(result.isEmpty()); Assert.assertTrue(result.isEmpty());