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

View File

@ -211,26 +211,24 @@ public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
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)) {
msg.getCapabilities().stream()
.filter(capability -> HELLO_MESSAGE.getCapabilities().contains(capability))
.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 ethHandler =
(EthHandler) ctx.pipeline().get(Capability.ETH);
ethHandler.setPeerId(msg.getPeerId());
ethHandler.activate();
} else if (capability.getName().equals(Capability.SHH)) {
// Activate ShhHandler for this peer
ShhHandler shhHandler =
(ShhHandler) ctx.pipeline().get(Capability.SHH);
shhHandler.activate();
}
capInCommon.add(capability);
}
}
ethHandler.setPeerId(msg.getPeerId());
ethHandler.activate();
} else if (capability.getName().equals(Capability.SHH)) {
// Activate ShhHandler for this peer
ShhHandler shhHandler =
(ShhHandler) ctx.pipeline().get(Capability.SHH);
shhHandler.activate();
}
capInCommon.add(capability);
});
adaptMessageIds(capInCommon);
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;
System.out.print("[");
for (RLPElement singleElement : rlpList) {
recursivePrint(singleElement);
}
rlpList.forEach(org.ethereum.util.RLPList::recursivePrint);
System.out.print("]");
} else {
String hex = ByteUtil.toHexString(element.getRLPData());

View File

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