Utils: Reorder.

This commit is contained in:
Andreas Schildbach
2018-02-22 12:32:15 +01:00
parent 13828ce311
commit aa593f46cd

View File

@@ -17,23 +17,30 @@
package org.bitcoinj.core; package org.bitcoinj.core;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
import com.google.common.io.BaseEncoding;
import com.google.common.primitives.Ints;
import org.spongycastle.crypto.digests.RIPEMD160Digest;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.math.BigInteger; import java.math.BigInteger;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.spongycastle.crypto.digests.RIPEMD160Digest;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
import com.google.common.io.BaseEncoding;
import com.google.common.primitives.Ints;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly; import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
@@ -45,6 +52,8 @@ public class Utils {
/** Joiner for concatenating words with a space inbetween. */ /** Joiner for concatenating words with a space inbetween. */
public static final Joiner SPACE_JOINER = Joiner.on(" "); public static final Joiner SPACE_JOINER = Joiner.on(" ");
/** Hex encoding used throughout the framework. Use with HEX.encode(byte[]) or HEX.decode(CharSequence). */
public static final BaseEncoding HEX = BaseEncoding.base16().lowerCase();
private static BlockingQueue<Boolean> mockSleepQueue; private static BlockingQueue<Boolean> mockSleepQueue;
@@ -141,23 +150,6 @@ public class Utils {
} }
} }
/**
* Hex encoding used throughout the framework. Use with HEX.encode(byte[]) or HEX.decode(CharSequence).
*/
public static final BaseEncoding HEX = BaseEncoding.base16().lowerCase();
/**
* Returns a copy of the given byte array in reverse order.
*/
public static byte[] reverseBytes(byte[] bytes) {
// We could use the XOR trick here but it's easier to understand if we don't. If we find this is really a
// performance issue the matter can be revisited.
byte[] buf = new byte[bytes.length];
for (int i = 0; i < bytes.length; i++)
buf[i] = bytes[bytes.length - 1 - i];
return buf;
}
/** Parse 4 bytes from the byte array (starting at the offset) as unsigned 32-bit integer in little endian format. */ /** Parse 4 bytes from the byte array (starting at the offset) as unsigned 32-bit integer in little endian format. */
public static long readUint32(byte[] bytes, int offset) { public static long readUint32(byte[] bytes, int offset) {
return (bytes[offset] & 0xffl) | return (bytes[offset] & 0xffl) |
@@ -192,6 +184,18 @@ public class Utils {
(bytes[offset + 1] & 0xff); (bytes[offset + 1] & 0xff);
} }
/**
* Returns a copy of the given byte array in reverse order.
*/
public static byte[] reverseBytes(byte[] bytes) {
// We could use the XOR trick here but it's easier to understand if we don't. If we find this is really a
// performance issue the matter can be revisited.
byte[] buf = new byte[bytes.length];
for (int i = 0; i < bytes.length; i++)
buf[i] = bytes[bytes.length - 1 - i];
return buf;
}
/** /**
* Calculates RIPEMD160(SHA256(input)). This is used in Address calculations. * Calculates RIPEMD160(SHA256(input)). This is used in Address calculations.
*/ */
@@ -386,10 +390,6 @@ public class Utils {
return iso8601.format(dateTime); return iso8601.format(dateTime);
} }
public static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("win");
}
// 00000001, 00000010, 00000100, 00001000, ... // 00000001, 00000010, 00000100, 00001000, ...
private static final int[] bitMask = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; private static final int[] bitMask = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
@@ -441,15 +441,6 @@ public class Utils {
} }
} }
private static int isAndroid = -1;
public static boolean isAndroidRuntime() {
if (isAndroid == -1) {
final String runtime = System.getProperty("java.runtime.name");
isAndroid = (runtime != null && runtime.equals("Android Runtime")) ? 1 : 0;
}
return isAndroid == 1;
}
private static class Pair implements Comparable<Pair> { private static class Pair implements Comparable<Pair> {
int item, count; int item, count;
public Pair(int item, int count) { this.count = count; this.item = item; } public Pair(int item, int count) { this.count = count; this.item = item; }
@@ -488,4 +479,17 @@ public class Utils {
} }
return maxItem; return maxItem;
} }
private static int isAndroid = -1;
public static boolean isAndroidRuntime() {
if (isAndroid == -1) {
final String runtime = System.getProperty("java.runtime.name");
isAndroid = (runtime != null && runtime.equals("Android Runtime")) ? 1 : 0;
}
return isAndroid == 1;
}
public static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("win");
}
} }