Collapse foreach loops using Iterable#forEach
This commit is contained in:
parent
003249cb77
commit
0d922e1b30
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue