Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 0 additions & 86 deletions server/src/main/java/org/elasticsearch/common/Numbers.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,48 +33,6 @@ public final class Numbers {
private static final BigInteger MIN_LONG_VALUE = BigInteger.valueOf(Long.MIN_VALUE);

private Numbers() {

}

/**
* Converts a byte array to an short.
*
* @param arr The byte array to convert to an short
* @return The int converted
*/
public static short bytesToShort(byte[] arr) {
return (short) (((arr[0] & 0xff) << 8) | (arr[1] & 0xff));
}

public static short bytesToShort(BytesRef bytes) {
return (short) (((bytes.bytes[bytes.offset] & 0xff) << 8) | (bytes.bytes[bytes.offset + 1] & 0xff));
}

/**
* Converts a byte array to an int.
*
* @param arr The byte array to convert to an int
* @return The int converted
*/
public static int bytesToInt(byte[] arr) {
return (arr[0] << 24) | ((arr[1] & 0xff) << 16) | ((arr[2] & 0xff) << 8) | (arr[3] & 0xff);
}

public static int bytesToInt(BytesRef bytes) {
return (bytes.bytes[bytes.offset] << 24) | ((bytes.bytes[bytes.offset + 1] & 0xff) << 16) |
((bytes.bytes[bytes.offset + 2] & 0xff) << 8) | (bytes.bytes[bytes.offset + 3] & 0xff);
}

/**
* Converts a byte array to a long.
*
* @param arr The byte array to convert to a long
* @return The long converter
*/
public static long bytesToLong(byte[] arr) {
int high = (arr[0] << 24) | ((arr[1] & 0xff) << 16) | ((arr[2] & 0xff) << 8) | (arr[3] & 0xff);
int low = (arr[4] << 24) | ((arr[5] & 0xff) << 16) | ((arr[6] & 0xff) << 8) | (arr[7] & 0xff);
return (((long) high) << 32) | (low & 0x0ffffffffL);
}

public static long bytesToLong(BytesRef bytes) {
Expand All @@ -85,40 +43,6 @@ public static long bytesToLong(BytesRef bytes) {
return (((long) high) << 32) | (low & 0x0ffffffffL);
}

/**
* Converts a byte array to float.
*
* @param arr The byte array to convert to a float
* @return The float converted
*/
public static float bytesToFloat(byte[] arr) {
return Float.intBitsToFloat(bytesToInt(arr));
}

public static float bytesToFloat(BytesRef bytes) {
return Float.intBitsToFloat(bytesToInt(bytes));
}

/**
* Converts a byte array to double.
*
* @param arr The byte array to convert to a double
* @return The double converted
*/
public static double bytesToDouble(byte[] arr) {
return Double.longBitsToDouble(bytesToLong(arr));
}

public static double bytesToDouble(BytesRef bytes) {
return Double.longBitsToDouble(bytesToLong(bytes));
}

/**
* Converts an int to a byte array.
*
* @param val The int to convert to a byte array
* @return The byte array converted
*/
public static byte[] intToBytes(int val) {
byte[] arr = new byte[4];
arr[0] = (byte) (val >>> 24);
Expand Down Expand Up @@ -160,16 +84,6 @@ public static byte[] longToBytes(long val) {
return arr;
}

/**
* Converts a float to a byte array.
*
* @param val The float to convert to a byte array
* @return The byte array converted
*/
public static byte[] floatToBytes(float val) {
return intToBytes(Float.floatToRawIntBits(val));
}

/**
* Converts a double to a byte array.
*
Expand Down