Package org.apache.lucene.util
Class StringHelper
- java.lang.Object
-
- org.apache.lucene.util.StringHelper
-
public abstract class StringHelper extends Object
Methods for manipulating strings.- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
-
Field Summary
Fields Modifier and Type Field Description static int
GOOD_FAST_HASH_SEED
Pass this as the seed tomurmurhash3_x86_32(byte[], int, int, int)
.static int
ID_LENGTH
length in bytes of an ID
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static int
bytesDifference(BytesRef priorTerm, BytesRef currentTerm)
Compares twoBytesRef
, element by element, and returns the number of elements common to both arrays (from the start of each).static int
compare(int count, byte[] a, int aOffset, byte[] b, int bOffset)
Deprecated.Use FutureArrays.compareUnsigned instead.static boolean
endsWith(BytesRef ref, BytesRef suffix)
Returnstrue
iff the ref ends with the given suffix.static String
idToString(byte[] id)
Helper method to render an ID as a string, for debuggingstatic BytesRef
intsRefToBytesRef(IntsRef ints)
static int
murmurhash3_x86_32(byte[] data, int offset, int len, int seed)
Returns the MurmurHash3_x86_32 hash.static int
murmurhash3_x86_32(BytesRef bytes, int seed)
static byte[]
randomId()
Generates a non-cryptographic globally unique id.static int
sortKeyLength(BytesRef priorTerm, BytesRef currentTerm)
Returns the length ofcurrentTerm
needed for use as a sort key.static boolean
startsWith(byte[] ref, BytesRef prefix)
Returnstrue
iff the ref starts with the given prefix.static boolean
startsWith(BytesRef ref, BytesRef prefix)
Returnstrue
iff the ref starts with the given prefix.
-
-
-
Field Detail
-
GOOD_FAST_HASH_SEED
public static final int GOOD_FAST_HASH_SEED
Pass this as the seed tomurmurhash3_x86_32(byte[], int, int, int)
.
-
ID_LENGTH
public static final int ID_LENGTH
length in bytes of an ID- See Also:
- Constant Field Values
-
-
Method Detail
-
bytesDifference
public static int bytesDifference(BytesRef priorTerm, BytesRef currentTerm)
Compares twoBytesRef
, element by element, and returns the number of elements common to both arrays (from the start of each). This method assumes currentTerm comes after priorTerm.
-
sortKeyLength
public static int sortKeyLength(BytesRef priorTerm, BytesRef currentTerm)
Returns the length ofcurrentTerm
needed for use as a sort key. so thatBytesRef.compareTo(BytesRef)
still returns the same result. This method assumes currentTerm comes after priorTerm.
-
startsWith
public static boolean startsWith(byte[] ref, BytesRef prefix)
Returnstrue
iff the ref starts with the given prefix. Otherwisefalse
.- Parameters:
ref
- thebyte[]
to testprefix
- the expected prefix- Returns:
- Returns
true
iff the ref starts with the given prefix. Otherwisefalse
.
-
startsWith
public static boolean startsWith(BytesRef ref, BytesRef prefix)
Returnstrue
iff the ref starts with the given prefix. Otherwisefalse
.- Parameters:
ref
- theBytesRef
to testprefix
- the expected prefix- Returns:
- Returns
true
iff the ref starts with the given prefix. Otherwisefalse
.
-
endsWith
public static boolean endsWith(BytesRef ref, BytesRef suffix)
Returnstrue
iff the ref ends with the given suffix. Otherwisefalse
.- Parameters:
ref
- theBytesRef
to testsuffix
- the expected suffix- Returns:
- Returns
true
iff the ref ends with the given suffix. Otherwisefalse
.
-
murmurhash3_x86_32
public static int murmurhash3_x86_32(byte[] data, int offset, int len, int seed)
Returns the MurmurHash3_x86_32 hash. Original source/tests at https://github.com/yonik/java_util/
-
murmurhash3_x86_32
public static int murmurhash3_x86_32(BytesRef bytes, int seed)
-
randomId
public static byte[] randomId()
Generates a non-cryptographic globally unique id.
-
idToString
public static String idToString(byte[] id)
Helper method to render an ID as a string, for debuggingReturns the string
(null)
if the id is null. Otherwise, returns a string representation for debugging. Never throws an exception. The returned string may indicate if the id is definitely invalid.
-
compare
@Deprecated public static int compare(int count, byte[] a, int aOffset, byte[] b, int bOffset)
Deprecated.Use FutureArrays.compareUnsigned instead.Compares a fixed length slice of two byte arrays interpreted as big-endian unsigned values. Returns positive int if a > b, negative int if a < b and 0 if a == b
-
-