Apply "for loop replaceable with enhanced for loop" refactoring.

This commit is contained in:
Andreas Schildbach 2020-09-07 19:34:01 +02:00
parent a966cd38a1
commit 6b6ead07eb
5 changed files with 27 additions and 28 deletions

View file

@ -1087,8 +1087,8 @@ public final class PeerSeedProtos {
@java.lang.Override @java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output) public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException { throws java.io.IOException {
for (int i = 0; i < seed_.size(); i++) { for (PeerSeedData peerSeedData : seed_) {
output.writeMessage(1, seed_.get(i)); output.writeMessage(1, peerSeedData);
} }
if (((bitField0_ & 0x00000001) != 0)) { if (((bitField0_ & 0x00000001) != 0)) {
output.writeUInt64(2, timestamp_); output.writeUInt64(2, timestamp_);
@ -1105,9 +1105,9 @@ public final class PeerSeedProtos {
if (size != -1) return size; if (size != -1) return size;
size = 0; size = 0;
for (int i = 0; i < seed_.size(); i++) { for (PeerSeedData peerSeedData : seed_) {
size += com.google.protobuf.CodedOutputStream size += com.google.protobuf.CodedOutputStream
.computeMessageSize(1, seed_.get(i)); .computeMessageSize(1, peerSeedData);
} }
if (((bitField0_ & 0x00000001) != 0)) { if (((bitField0_ & 0x00000001) != 0)) {
size += com.google.protobuf.CodedOutputStream size += com.google.protobuf.CodedOutputStream

View file

@ -1386,30 +1386,30 @@ public class Transaction extends ChildMessage {
if (!anyoneCanPay) { if (!anyoneCanPay) {
ByteArrayOutputStream bosHashPrevouts = new UnsafeByteArrayOutputStream(256); ByteArrayOutputStream bosHashPrevouts = new UnsafeByteArrayOutputStream(256);
for (int i = 0; i < this.inputs.size(); ++i) { for (TransactionInput input : this.inputs) {
bosHashPrevouts.write(this.inputs.get(i).getOutpoint().getHash().getReversedBytes()); bosHashPrevouts.write(input.getOutpoint().getHash().getReversedBytes());
uint32ToByteStreamLE(this.inputs.get(i).getOutpoint().getIndex(), bosHashPrevouts); uint32ToByteStreamLE(input.getOutpoint().getIndex(), bosHashPrevouts);
} }
hashPrevouts = Sha256Hash.hashTwice(bosHashPrevouts.toByteArray()); hashPrevouts = Sha256Hash.hashTwice(bosHashPrevouts.toByteArray());
} }
if (!anyoneCanPay && signAll) { if (!anyoneCanPay && signAll) {
ByteArrayOutputStream bosSequence = new UnsafeByteArrayOutputStream(256); ByteArrayOutputStream bosSequence = new UnsafeByteArrayOutputStream(256);
for (int i = 0; i < this.inputs.size(); ++i) { for (TransactionInput input : this.inputs) {
uint32ToByteStreamLE(this.inputs.get(i).getSequenceNumber(), bosSequence); uint32ToByteStreamLE(input.getSequenceNumber(), bosSequence);
} }
hashSequence = Sha256Hash.hashTwice(bosSequence.toByteArray()); hashSequence = Sha256Hash.hashTwice(bosSequence.toByteArray());
} }
if (signAll) { if (signAll) {
ByteArrayOutputStream bosHashOutputs = new UnsafeByteArrayOutputStream(256); ByteArrayOutputStream bosHashOutputs = new UnsafeByteArrayOutputStream(256);
for (int i = 0; i < this.outputs.size(); ++i) { for (TransactionOutput output : this.outputs) {
uint64ToByteStreamLE( uint64ToByteStreamLE(
BigInteger.valueOf(this.outputs.get(i).getValue().getValue()), BigInteger.valueOf(output.getValue().getValue()),
bosHashOutputs bosHashOutputs
); );
bosHashOutputs.write(new VarInt(this.outputs.get(i).getScriptBytes().length).encode()); bosHashOutputs.write(new VarInt(output.getScriptBytes().length).encode());
bosHashOutputs.write(this.outputs.get(i).getScriptBytes()); bosHashOutputs.write(output.getScriptBytes());
} }
hashOutputs = Sha256Hash.hashTwice(bosHashOutputs.toByteArray()); hashOutputs = Sha256Hash.hashTwice(bosHashOutputs.toByteArray());
} else if (basicSigHashType == SigHash.SINGLE.value && inputIndex < outputs.size()) { } else if (basicSigHashType == SigHash.SINGLE.value && inputIndex < outputs.size()) {

View file

@ -64,8 +64,7 @@ public class TransactionWitness {
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
stream.write(new VarInt(pushes.size()).encode()); stream.write(new VarInt(pushes.size()).encode());
for (int i = 0; i < pushes.size(); i++) { for (byte[] push : pushes) {
byte[] push = pushes.get(i);
stream.write(new VarInt(push.length).encode()); stream.write(new VarInt(push.length).encode());
stream.write(push); stream.write(push);
} }

View file

@ -79,8 +79,8 @@ public class VersionTally {
return null; return null;
} }
int count = 0; int count = 0;
for (int versionIdx = 0; versionIdx < versionWindow.length; versionIdx++) { for (long l : versionWindow) {
if (versionWindow[versionIdx] >= version) { if (l >= version) {
count++; count++;
} }
} }

View file

@ -102,11 +102,11 @@ public class BtcFormatTest {
@Test @Test
public void symbolCollisionTest() { public void symbolCollisionTest() {
Locale[] locales = BtcFormat.getAvailableLocales(); Locale[] locales = BtcFormat.getAvailableLocales();
for (int i = 0; i < locales.length; ++i) { for (Locale locale : locales) {
String cs = ((DecimalFormat)NumberFormat.getCurrencyInstance(locales[i])). String cs = ((DecimalFormat) NumberFormat.getCurrencyInstance(locale)).
getDecimalFormatSymbols().getCurrencySymbol(); getDecimalFormatSymbols().getCurrencySymbol();
if (cs.contains("฿")) { if (cs.contains("฿")) {
BtcFormat bf = BtcFormat.getSymbolInstance(locales[i]); BtcFormat bf = BtcFormat.getSymbolInstance(locale);
String coin = bf.format(COIN); String coin = bf.format(COIN);
assertTrue(coin.contains("Ƀ")); assertTrue(coin.contains("Ƀ"));
assertFalse(coin.contains("฿")); assertFalse(coin.contains("฿"));
@ -116,19 +116,19 @@ public class BtcFormatTest {
String micro = bf.format(valueOf(100)); String micro = bf.format(valueOf(100));
assertTrue(micro.contains("µɃ")); assertTrue(micro.contains("µɃ"));
assertFalse(micro.contains("฿")); assertFalse(micro.contains("฿"));
BtcFormat ff = BtcFormat.builder().scale(0).locale(locales[i]).pattern("¤#.#").build(); BtcFormat ff = BtcFormat.builder().scale(0).locale(locale).pattern("¤#.#").build();
assertEquals("Ƀ", ((BtcFixedFormat) ff).symbol()); assertEquals("Ƀ", ((BtcFixedFormat) ff).symbol());
assertEquals("Ƀ", ff.coinSymbol()); assertEquals("Ƀ", ff.coinSymbol());
coin = ff.format(COIN); coin = ff.format(COIN);
assertTrue(coin.contains("Ƀ")); assertTrue(coin.contains("Ƀ"));
assertFalse(coin.contains("฿")); assertFalse(coin.contains("฿"));
BtcFormat mlff = BtcFormat.builder().scale(3).locale(locales[i]).pattern("¤#.#").build(); BtcFormat mlff = BtcFormat.builder().scale(3).locale(locale).pattern("¤#.#").build();
assertEquals("₥Ƀ", ((BtcFixedFormat) mlff).symbol()); assertEquals("₥Ƀ", ((BtcFixedFormat) mlff).symbol());
assertEquals("Ƀ", mlff.coinSymbol()); assertEquals("Ƀ", mlff.coinSymbol());
milli = mlff.format(valueOf(10000)); milli = mlff.format(valueOf(10000));
assertTrue(milli.contains("₥Ƀ")); assertTrue(milli.contains("₥Ƀ"));
assertFalse(milli.contains("฿")); assertFalse(milli.contains("฿"));
BtcFormat mcff = BtcFormat.builder().scale(6).locale(locales[i]).pattern("¤#.#").build(); BtcFormat mcff = BtcFormat.builder().scale(6).locale(locale).pattern("¤#.#").build();
assertEquals("µɃ", ((BtcFixedFormat) mcff).symbol()); assertEquals("µɃ", ((BtcFixedFormat) mcff).symbol());
assertEquals("Ƀ", mcff.coinSymbol()); assertEquals("Ƀ", mcff.coinSymbol());
micro = mcff.format(valueOf(100)); micro = mcff.format(valueOf(100));
@ -136,7 +136,7 @@ public class BtcFormatTest {
assertFalse(micro.contains("฿")); assertFalse(micro.contains("฿"));
} }
if (cs.contains("Ƀ")) { // NB: We don't know of any such existing locale, but check anyway. if (cs.contains("Ƀ")) { // NB: We don't know of any such existing locale, but check anyway.
BtcFormat bf = BtcFormat.getInstance(locales[i]); BtcFormat bf = BtcFormat.getInstance(locale);
String coin = bf.format(COIN); String coin = bf.format(COIN);
assertTrue(coin.contains("฿")); assertTrue(coin.contains("฿"));
assertFalse(coin.contains("Ƀ")); assertFalse(coin.contains("Ƀ"));