mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 17:26:28 +01:00
Apply "for loop replaceable with enhanced for loop" refactoring.
This commit is contained in:
parent
a966cd38a1
commit
6b6ead07eb
5 changed files with 27 additions and 28 deletions
|
@ -1087,8 +1087,8 @@ public final class PeerSeedProtos {
|
|||
@java.lang.Override
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
for (int i = 0; i < seed_.size(); i++) {
|
||||
output.writeMessage(1, seed_.get(i));
|
||||
for (PeerSeedData peerSeedData : seed_) {
|
||||
output.writeMessage(1, peerSeedData);
|
||||
}
|
||||
if (((bitField0_ & 0x00000001) != 0)) {
|
||||
output.writeUInt64(2, timestamp_);
|
||||
|
@ -1105,9 +1105,9 @@ public final class PeerSeedProtos {
|
|||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
for (int i = 0; i < seed_.size(); i++) {
|
||||
for (PeerSeedData peerSeedData : seed_) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeMessageSize(1, seed_.get(i));
|
||||
.computeMessageSize(1, peerSeedData);
|
||||
}
|
||||
if (((bitField0_ & 0x00000001) != 0)) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
|
|
|
@ -1386,30 +1386,30 @@ public class Transaction extends ChildMessage {
|
|||
|
||||
if (!anyoneCanPay) {
|
||||
ByteArrayOutputStream bosHashPrevouts = new UnsafeByteArrayOutputStream(256);
|
||||
for (int i = 0; i < this.inputs.size(); ++i) {
|
||||
bosHashPrevouts.write(this.inputs.get(i).getOutpoint().getHash().getReversedBytes());
|
||||
uint32ToByteStreamLE(this.inputs.get(i).getOutpoint().getIndex(), bosHashPrevouts);
|
||||
for (TransactionInput input : this.inputs) {
|
||||
bosHashPrevouts.write(input.getOutpoint().getHash().getReversedBytes());
|
||||
uint32ToByteStreamLE(input.getOutpoint().getIndex(), bosHashPrevouts);
|
||||
}
|
||||
hashPrevouts = Sha256Hash.hashTwice(bosHashPrevouts.toByteArray());
|
||||
}
|
||||
|
||||
if (!anyoneCanPay && signAll) {
|
||||
ByteArrayOutputStream bosSequence = new UnsafeByteArrayOutputStream(256);
|
||||
for (int i = 0; i < this.inputs.size(); ++i) {
|
||||
uint32ToByteStreamLE(this.inputs.get(i).getSequenceNumber(), bosSequence);
|
||||
for (TransactionInput input : this.inputs) {
|
||||
uint32ToByteStreamLE(input.getSequenceNumber(), bosSequence);
|
||||
}
|
||||
hashSequence = Sha256Hash.hashTwice(bosSequence.toByteArray());
|
||||
}
|
||||
|
||||
if (signAll) {
|
||||
ByteArrayOutputStream bosHashOutputs = new UnsafeByteArrayOutputStream(256);
|
||||
for (int i = 0; i < this.outputs.size(); ++i) {
|
||||
for (TransactionOutput output : this.outputs) {
|
||||
uint64ToByteStreamLE(
|
||||
BigInteger.valueOf(this.outputs.get(i).getValue().getValue()),
|
||||
BigInteger.valueOf(output.getValue().getValue()),
|
||||
bosHashOutputs
|
||||
);
|
||||
bosHashOutputs.write(new VarInt(this.outputs.get(i).getScriptBytes().length).encode());
|
||||
bosHashOutputs.write(this.outputs.get(i).getScriptBytes());
|
||||
bosHashOutputs.write(new VarInt(output.getScriptBytes().length).encode());
|
||||
bosHashOutputs.write(output.getScriptBytes());
|
||||
}
|
||||
hashOutputs = Sha256Hash.hashTwice(bosHashOutputs.toByteArray());
|
||||
} else if (basicSigHashType == SigHash.SINGLE.value && inputIndex < outputs.size()) {
|
||||
|
|
|
@ -64,8 +64,7 @@ public class TransactionWitness {
|
|||
|
||||
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
|
||||
stream.write(new VarInt(pushes.size()).encode());
|
||||
for (int i = 0; i < pushes.size(); i++) {
|
||||
byte[] push = pushes.get(i);
|
||||
for (byte[] push : pushes) {
|
||||
stream.write(new VarInt(push.length).encode());
|
||||
stream.write(push);
|
||||
}
|
||||
|
|
|
@ -79,8 +79,8 @@ public class VersionTally {
|
|||
return null;
|
||||
}
|
||||
int count = 0;
|
||||
for (int versionIdx = 0; versionIdx < versionWindow.length; versionIdx++) {
|
||||
if (versionWindow[versionIdx] >= version) {
|
||||
for (long l : versionWindow) {
|
||||
if (l >= version) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,11 +102,11 @@ public class BtcFormatTest {
|
|||
@Test
|
||||
public void symbolCollisionTest() {
|
||||
Locale[] locales = BtcFormat.getAvailableLocales();
|
||||
for (int i = 0; i < locales.length; ++i) {
|
||||
String cs = ((DecimalFormat)NumberFormat.getCurrencyInstance(locales[i])).
|
||||
getDecimalFormatSymbols().getCurrencySymbol();
|
||||
for (Locale locale : locales) {
|
||||
String cs = ((DecimalFormat) NumberFormat.getCurrencyInstance(locale)).
|
||||
getDecimalFormatSymbols().getCurrencySymbol();
|
||||
if (cs.contains("฿")) {
|
||||
BtcFormat bf = BtcFormat.getSymbolInstance(locales[i]);
|
||||
BtcFormat bf = BtcFormat.getSymbolInstance(locale);
|
||||
String coin = bf.format(COIN);
|
||||
assertTrue(coin.contains("Ƀ"));
|
||||
assertFalse(coin.contains("฿"));
|
||||
|
@ -116,27 +116,27 @@ public class BtcFormatTest {
|
|||
String micro = bf.format(valueOf(100));
|
||||
assertTrue(micro.contains("µɃ"));
|
||||
assertFalse(micro.contains("฿"));
|
||||
BtcFormat ff = BtcFormat.builder().scale(0).locale(locales[i]).pattern("¤#.#").build();
|
||||
assertEquals("Ƀ", ((BtcFixedFormat)ff).symbol());
|
||||
BtcFormat ff = BtcFormat.builder().scale(0).locale(locale).pattern("¤#.#").build();
|
||||
assertEquals("Ƀ", ((BtcFixedFormat) ff).symbol());
|
||||
assertEquals("Ƀ", ff.coinSymbol());
|
||||
coin = ff.format(COIN);
|
||||
assertTrue(coin.contains("Ƀ"));
|
||||
assertFalse(coin.contains("฿"));
|
||||
BtcFormat mlff = BtcFormat.builder().scale(3).locale(locales[i]).pattern("¤#.#").build();
|
||||
assertEquals("₥Ƀ", ((BtcFixedFormat)mlff).symbol());
|
||||
BtcFormat mlff = BtcFormat.builder().scale(3).locale(locale).pattern("¤#.#").build();
|
||||
assertEquals("₥Ƀ", ((BtcFixedFormat) mlff).symbol());
|
||||
assertEquals("Ƀ", mlff.coinSymbol());
|
||||
milli = mlff.format(valueOf(10000));
|
||||
assertTrue(milli.contains("₥Ƀ"));
|
||||
assertFalse(milli.contains("฿"));
|
||||
BtcFormat mcff = BtcFormat.builder().scale(6).locale(locales[i]).pattern("¤#.#").build();
|
||||
assertEquals("µɃ", ((BtcFixedFormat)mcff).symbol());
|
||||
BtcFormat mcff = BtcFormat.builder().scale(6).locale(locale).pattern("¤#.#").build();
|
||||
assertEquals("µɃ", ((BtcFixedFormat) mcff).symbol());
|
||||
assertEquals("Ƀ", mcff.coinSymbol());
|
||||
micro = mcff.format(valueOf(100));
|
||||
assertTrue(micro.contains("µɃ"));
|
||||
assertFalse(micro.contains("฿"));
|
||||
}
|
||||
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);
|
||||
assertTrue(coin.contains("฿"));
|
||||
assertFalse(coin.contains("Ƀ"));
|
||||
|
|
Loading…
Add table
Reference in a new issue