Package org.alfresco.util
Class NumericEncoder
- java.lang.Object
-
- org.alfresco.util.NumericEncoder
-
public class NumericEncoder extends Object
Support to encode numeric types in the lucene index. To support range queries in the lucene index numeric types need to be indexed specially. This has been addressed for int and long types for lucene and limited support (via scaling) for float and double. The implementation splits an int, long, float or double into the sign bit, optional exponent and mantissa either from the int or long format or its IEEE 754 byte representation. To index content so small negative numbers are indexed correctly and are after big negative numbers in range queries. The algorithm finds the sign, if the number is negative, then the mantissa and exponent are XORed against the appropriate masks. This reverses the order. As negative numbers appear first in the list their sign bit is 0 and positive numbers are 1.- Author:
- Andy Hind
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
decodeInt(String hex)
static long
decodeLong(String hex)
Secode a longstatic String
encode(double doubleToEncode)
Encode a double into a string that orders correctly according to string comparison.static String
encode(float floatToEncode)
Encode a float into a string that orders correctly according to string comparison.static String
encode(int intToEncode)
Encode an integer into a string that orders correctly using string comparison Integer.MIN_VALUE encodes as 00000000 and MAX_VALUE as ffffffff.static String
encode(long longToEncode)
Encode a long into a string that orders correctly using string comparison Long.MIN_VALUE encodes as 0000000000000000 and MAX_VALUE as ffffffffffffffff.static String
encode(Long longToEncode)
-
-
-
Method Detail
-
encode
public static String encode(int intToEncode)
Encode an integer into a string that orders correctly using string comparison Integer.MIN_VALUE encodes as 00000000 and MAX_VALUE as ffffffff.- Parameters:
intToEncode
- int- Returns:
- the encoded string
-
encode
public static String encode(long longToEncode)
Encode a long into a string that orders correctly using string comparison Long.MIN_VALUE encodes as 0000000000000000 and MAX_VALUE as ffffffffffffffff.- Parameters:
longToEncode
- long- Returns:
- - the encoded string
-
decodeLong
public static long decodeLong(String hex)
Secode a long- Parameters:
hex
- String- Returns:
- - the decoded string
-
decodeInt
public static int decodeInt(String hex)
-
encode
public static String encode(float floatToEncode)
Encode a float into a string that orders correctly according to string comparison. Note that there is no negative NaN but there are codings that imply this. So NaN and -Infinity may not compare as expected.- Parameters:
floatToEncode
- float- Returns:
- - the encoded string
-
encode
public static String encode(double doubleToEncode)
Encode a double into a string that orders correctly according to string comparison. Note that there is no negative NaN but there are codings that imply this. So NaN and -Infinity may not compare as expected.- Parameters:
doubleToEncode
- double- Returns:
- the encoded string
-
-