Class NumericUtils

java.lang.Object
com.atlassian.jira.search.utils.NumericUtils

@Internal public class NumericUtils extends Object
Utility class providing methods for numeric encoding and decoding, specifically porting functionality from Lucene 3.3.0's NumericUtils that was subsequently removed. This class primarily deals with prefix coding of long and double values into character arrays or strings, allowing for efficient storage and retrieval, particularly in Lucene indexes. Copied from lucene-extras
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Expert: The maximum term length (used for char[] buffer size) for encoding long values.
    static final char
    Expert: Longs are stored at lower precision by shifting off lower bits.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    doubleToPrefixCoded(double val)
    Convenience method: this just returns: longToPrefixCoded(doubleToSortableLong(val))
    static String
    This is a convenience method, that returns prefix coded bits of a long without reducing the precision.
    static String
    longToPrefixCoded(long val, int shift)
    Expert: Returns prefix coded bits after reducing the precision by shift bits.
    static int
    longToPrefixCoded(long val, int shift, char[] buffer)
    Expert: Returns prefix coded bits after reducing the precision by shift bits.
    static long
    Returns a long from prefixCoded characters.

    Methods inherited from class java.lang.Object

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

    • SHIFT_START_LONG

      public static final char SHIFT_START_LONG
      Expert: Longs are stored at lower precision by shifting off lower bits. The shift count is stored as SHIFT_START_LONG+shift in the first character
      See Also:
    • BUF_SIZE_LONG

      public static final int BUF_SIZE_LONG
      Expert: The maximum term length (used for char[] buffer size) for encoding long values.
      See Also:
  • Constructor Details

    • NumericUtils

      public NumericUtils()
  • Method Details

    • longToPrefixCoded

      public static int longToPrefixCoded(long val, int shift, char[] buffer)
      Expert: Returns prefix coded bits after reducing the precision by shift bits. This is method is used by NumericTokenStream.
      Parameters:
      val - the numeric value
      shift - how many bits to strip from the right
      buffer - that will contain the encoded chars, must be at least of BUF_SIZE_LONG length
      Returns:
      number of chars written to buffer
    • longToPrefixCoded

      public static String longToPrefixCoded(long val, int shift)
      Expert: Returns prefix coded bits after reducing the precision by shift bits. This is method is used by LongRangeBuilder.
      Parameters:
      val - the numeric value
      shift - how many bits to strip from the right
    • longToPrefixCoded

      public static String longToPrefixCoded(long val)
      This is a convenience method, that returns prefix coded bits of a long without reducing the precision. It can be used to store the full precision value as a stored field in index.

      To decode, use prefixCodedToLong(java.lang.String).

    • prefixCodedToLong

      public static long prefixCodedToLong(String prefixCoded)
      Returns a long from prefixCoded characters. Rightmost bits will be zero for lower precision codes. This method can be used to decode e.g. a stored field.
      Throws:
      NumberFormatException - if the supplied string is not correctly prefix encoded.
      See Also:
    • doubleToPrefixCoded

      public static String doubleToPrefixCoded(double val)
      Convenience method: this just returns: longToPrefixCoded(doubleToSortableLong(val))