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

    Modifier and Type
    Method
    Description
    static int
     
    static long
    Secode a long
    static 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)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • 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
    • encode

      public static String encode(Long longToEncode)
    • 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