public abstract class Fields
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Fields.ByteArrayComparator
Compares byte arrays lexicographically.
|
Constructor and Description |
---|
Fields() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
boolToString(boolean b)
Converts a boolean to a String of either "true" or "false".
|
static boolean |
byteArrayEqual(byte[] a,
byte[] b) |
static boolean |
byteArrayEqual(byte[] a,
byte[] b,
int aoff,
int boff,
int len) |
static double[] |
bytesToDoubles(byte[] data) |
static double[] |
bytesToDoubles(byte[] data,
int offset,
int length) |
static int |
bytesToInt(byte[] buf) |
static int |
bytesToInt(byte[] buf,
int offset)
Convert an array of bytes to a single int.
|
static int[] |
bytesToInts(byte[] buf) |
static int[] |
bytesToInts(byte[] buf,
int offset,
int length) |
static long |
bytesToLong(byte[] buf)
Convert an array of bytes to a single long.
|
static long |
bytesToLong(byte[] buf,
int offset)
Convert an array of bytes to a single long.
|
static long[] |
bytesToLongs(byte[] buf)
Convert an array of bytes to an array of longs.
|
static long[] |
bytesToLongs(byte[] buf,
int offset,
int length)
Convert an array of bytes to an array of longs.
|
static short |
bytesToShort(byte[] buf,
int offset)
Convert an array of bytes to a single int.
|
static java.lang.String |
commaList(java.lang.Object[] addr) |
static java.lang.String |
commaList(java.lang.Object[] addr,
char comma) |
static java.lang.String[] |
commaList(java.lang.String ls) |
static java.lang.String |
commaList(java.lang.String[] ls) |
static int |
compare(java.util.Date a,
java.util.Date b) |
static int |
compare(double x,
double y)
Avoid issues with NaN's.
|
static int |
compare(float x,
float y)
Avoid issues with NaN's.
|
static int |
compare(int x,
int y)
Avoid issues with overflow, 2's complement.
|
static int |
compare(long x,
long y)
Avoid issues with overflow, 2's complement.
|
static int |
compareBytes(byte[] b1,
byte[] b2) |
static int |
compareBytes(byte[] a,
byte[] b,
int aoff,
int boff,
int len) |
static int |
compareObjectID(java.lang.Object o1,
java.lang.Object o2) |
static int |
compareVersion(java.lang.String x,
java.lang.String y)
Compare two versions.
|
static byte[] |
copyToArray(java.nio.ByteBuffer buf)
Copy all of the remaining bytes in the buffer to a byte array.
|
static long |
dateTime(java.lang.String date)
Parses a time and date value, using a very strict format.
|
static byte[] |
doublesToBytes(double[] doubles) |
static int |
hashCode(byte[] b) |
static int |
hashCode(byte[] b,
int ptr,
int length)
A generic hashcode suited for byte arrays that are more or less random.
|
static int |
hexToInt(java.lang.String hex)
Converts a hex string into an int.
|
static long |
hexToLong(java.lang.String hex)
Converts a hex string into a long.
|
static byte[] |
intsToBytes(int[] ints) |
static byte[] |
intsToBytes(int[] ints,
int offset,
int length) |
static byte[] |
intToBytes(int x) |
static java.lang.String |
intToString(int val,
boolean isSize) |
static java.lang.String |
intToString(int val,
Dimension dimension) |
static long |
longHashCode(byte[] b)
Long version of above Not believed to be secure in any sense of the word :)
|
static long |
longHashCode(byte[] b,
int offset,
int length)
Long version of above Not believed to be secure in any sense of the word :)
|
static byte[] |
longsToBytes(long[] longs)
Convert an array of longs to an array of bytes, using a
consistent endianness.
|
static byte[] |
longToBytes(long x) |
static java.lang.String |
longToString(long val,
boolean isSize) |
static java.lang.String |
numberList(long[] ls) |
static long[] |
numberList(java.lang.String ls) |
static int |
parseInt(java.lang.String s)
Parse a human-readable string possibly including SI and ICE units into an integer.
|
static int |
parseInt(java.lang.String s,
Dimension dimension) |
static int |
parseInt(java.lang.String s,
int defaultValue) |
static long |
parseLong(java.lang.String s)
Parse a human-readable string possibly including SI and ICE units into a long.
|
static long |
parseLong(java.lang.String s,
long defaultValue) |
static short |
parseShort(java.lang.String s)
Parse a human-readable string possibly including SI and ICE units into a short.
|
static long |
parseShort(java.lang.String s,
short defaultValue) |
static java.lang.String |
secToDateTime(long time) |
static byte[] |
shortToBytes(short x) |
static java.lang.String |
shortToString(short val,
boolean isSize) |
static boolean |
stringToBool(java.lang.String s)
Find the boolean value of the field.
|
static boolean |
stringToBool(java.lang.String s,
boolean def)
Finds the boolean value of the field, by doing a caseless match with the
strings "true" and "false".
|
static java.lang.String |
textList(java.lang.String[] ls,
char ch) |
static java.lang.String |
trimLines(java.lang.String str)
Remove empty lines and trim head/trailing space
|
static java.lang.String |
trimPerSecond(java.lang.String limit) |
public static long hexToLong(java.lang.String hex) throws java.lang.NumberFormatException
hex
- A string in capital or lower case hex, of no more then 16
characters.java.lang.NumberFormatException
- if the string is more than 16 characters long, or if any
character is not in the set [0-9a-fA-f]public static int hexToInt(java.lang.String hex) throws java.lang.NumberFormatException
hex
- A string in capital or lower case hex, of no more then 16
characters.java.lang.NumberFormatException
- if the string is more than 16 characters long, or if any
character is not in the set [0-9a-fA-f]public static boolean stringToBool(java.lang.String s, boolean def)
s
- The stringdef
- The default value if the string can't be parsed. If the
default is true, it checks that the string is not "false"; if
it is false, it checks whether the string is "true".public static boolean stringToBool(java.lang.String s) throws java.lang.NumberFormatException
s
- java.lang.NumberFormatException
public static java.lang.String boolToString(boolean b)
b
- the boolean value to convert.public static java.lang.String[] commaList(java.lang.String ls)
public static java.lang.String commaList(java.lang.String[] ls)
public static java.lang.String textList(java.lang.String[] ls, char ch)
public static long[] numberList(java.lang.String ls) throws java.lang.NumberFormatException
java.lang.NumberFormatException
public static java.lang.String numberList(long[] ls)
public static long dateTime(java.lang.String date) throws java.lang.NumberFormatException
java.lang.NumberFormatException
public static java.lang.String secToDateTime(long time)
public static int compareBytes(byte[] b1, byte[] b2)
public static int compareBytes(byte[] a, byte[] b, int aoff, int boff, int len)
public static boolean byteArrayEqual(byte[] a, byte[] b)
public static boolean byteArrayEqual(byte[] a, byte[] b, int aoff, int boff, int len)
public static int hashCode(byte[] b)
public static int hashCode(byte[] b, int ptr, int length)
public static long longHashCode(byte[] b)
public static long longHashCode(byte[] b, int offset, int length)
public static java.lang.String commaList(java.lang.Object[] addr)
public static java.lang.String commaList(java.lang.Object[] addr, char comma)
addr
- public static byte[] longsToBytes(long[] longs)
public static long[] bytesToLongs(byte[] buf)
public static long[] bytesToLongs(byte[] buf, int offset, int length)
buf
- length
- offset
- public static long bytesToLong(byte[] buf)
public static long bytesToLong(byte[] buf, int offset)
public static int bytesToInt(byte[] buf)
public static int bytesToInt(byte[] buf, int offset)
public static short bytesToShort(byte[] buf, int offset)
public static int[] bytesToInts(byte[] buf, int offset, int length)
public static int[] bytesToInts(byte[] buf)
public static byte[] longToBytes(long x)
public static byte[] intsToBytes(int[] ints)
public static byte[] intsToBytes(int[] ints, int offset, int length)
public static byte[] intToBytes(int x)
public static byte[] shortToBytes(short x)
public static long parseLong(java.lang.String s, long defaultValue)
public static int parseInt(java.lang.String s, int defaultValue)
public static long parseShort(java.lang.String s, short defaultValue)
public static short parseShort(java.lang.String s) throws java.lang.NumberFormatException
java.lang.NumberFormatException
- if the string is not parseablepublic static java.lang.String trimPerSecond(java.lang.String limit)
public static int parseInt(java.lang.String s, Dimension dimension) throws java.lang.NumberFormatException
java.lang.NumberFormatException
public static int parseInt(java.lang.String s) throws java.lang.NumberFormatException
java.lang.NumberFormatException
- if the string is not parseablepublic static long parseLong(java.lang.String s) throws java.lang.NumberFormatException
java.lang.NumberFormatException
- if the string is not parseablepublic static java.lang.String longToString(long val, boolean isSize)
public static java.lang.String intToString(int val, Dimension dimension)
public static java.lang.String intToString(int val, boolean isSize)
public static java.lang.String shortToString(short val, boolean isSize)
public static double[] bytesToDoubles(byte[] data, int offset, int length)
public static byte[] doublesToBytes(double[] doubles)
public static double[] bytesToDoubles(byte[] data)
public static java.lang.String trimLines(java.lang.String str)
str
- string to be trimmedpublic static int compareVersion(java.lang.String x, java.lang.String y)
public static int compareObjectID(java.lang.Object o1, java.lang.Object o2)
public static final int compare(int x, int y)
public static final int compare(long x, long y)
public static final int compare(double x, double y)
public static final int compare(float x, float y)
public static final int compare(java.util.Date a, java.util.Date b)
public static byte[] copyToArray(java.nio.ByteBuffer buf)
buf
- The input buffer. Position will be at the limit when returning.