Package com.atlassian.jira.search.utils
Class NumericUtils
java.lang.Object
com.atlassian.jira.search.utils.NumericUtils
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
FieldsModifier and TypeFieldDescriptionstatic final intExpert: The maximum term length (used forchar[]buffer size) for encodinglongvalues.static final charExpert: Longs are stored at lower precision by shifting off lower bits. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringdoubleToPrefixCoded(double val) Convenience method: this just returns: longToPrefixCoded(doubleToSortableLong(val))static StringlongToPrefixCoded(long val) This is a convenience method, that returns prefix coded bits of a long without reducing the precision.static StringlongToPrefixCoded(long val, int shift) Expert: Returns prefix coded bits after reducing the precision byshiftbits.static intlongToPrefixCoded(long val, int shift, char[] buffer) Expert: Returns prefix coded bits after reducing the precision byshiftbits.static longprefixCodedToLong(String prefixCoded) Returns a long from prefixCoded characters.
-
Field Details
-
SHIFT_START_LONG
public static final char SHIFT_START_LONGExpert: Longs are stored at lower precision by shifting off lower bits. The shift count is stored asSHIFT_START_LONG+shiftin the first character- See Also:
-
BUF_SIZE_LONG
public static final int BUF_SIZE_LONGExpert: The maximum term length (used forchar[]buffer size) for encodinglongvalues.- 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 byshiftbits. This is method is used byNumericTokenStream.- Parameters:
val- the numeric valueshift- how many bits to strip from the rightbuffer- that will contain the encoded chars, must be at least ofBUF_SIZE_LONGlength- Returns:
- number of chars written to buffer
-
longToPrefixCoded
Expert: Returns prefix coded bits after reducing the precision byshiftbits. This is method is used byLongRangeBuilder.- Parameters:
val- the numeric valueshift- how many bits to strip from the right
-
longToPrefixCoded
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
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
Convenience method: this just returns: longToPrefixCoded(doubleToSortableLong(val))
-