Class StringHelper


  • public abstract class StringHelper
    extends java.lang.Object
    Methods for manipulating strings.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private StringHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int bytesDifference​(BytesRef priorTerm, BytesRef currentTerm)
      Compares two BytesRef, element by element, and returns the number of elements common to both arrays (from the start of each).
      static boolean endsWith​(BytesRef ref, BytesRef suffix)
      Returns true iff the ref ends with the given suffix.
      static java.lang.String idToString​(byte[] id)
      Helper method to render an ID as a string, for debugging
      static BytesRef intsRefToBytesRef​(IntsRef ints)
      Just converts each int in the incoming IntsRef to each byte in the returned BytesRef, throwing IllegalArgumentException if any int value is out of bounds for a byte.
      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 of currentTerm needed for use as a sort key.
      static boolean startsWith​(byte[] ref, BytesRef prefix)
      Returns true iff the ref starts with the given prefix.
      static boolean startsWith​(BytesRef ref, BytesRef prefix)
      Returns true iff the ref starts with the given prefix.
      • Methods inherited from class java.lang.Object

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

      • nextId

        private static java.math.BigInteger nextId
      • mask128

        private static final java.math.BigInteger mask128
      • idLock

        private static final java.lang.Object idLock
    • Constructor Detail

      • StringHelper

        private StringHelper()
    • Method Detail

      • bytesDifference

        public static int bytesDifference​(BytesRef priorTerm,
                                          BytesRef currentTerm)
        Compares two BytesRef, 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.
        Parameters:
        priorTerm - The first BytesRef to compare
        currentTerm - The second BytesRef to compare
        Returns:
        The number of common elements (from the start of each).
      • sortKeyLength

        public static int sortKeyLength​(BytesRef priorTerm,
                                        BytesRef currentTerm)
        Returns the length of currentTerm needed for use as a sort key. so that BytesRef.compareTo(BytesRef) still returns the same result. This method assumes currentTerm comes after priorTerm.
      • startsWith

        public static boolean startsWith​(byte[] ref,
                                         BytesRef prefix)
        Returns true iff the ref starts with the given prefix. Otherwise false.
        Parameters:
        ref - the byte[] to test
        prefix - the expected prefix
        Returns:
        Returns true iff the ref starts with the given prefix. Otherwise false.
      • startsWith

        public static boolean startsWith​(BytesRef ref,
                                         BytesRef prefix)
        Returns true iff the ref starts with the given prefix. Otherwise false.
        Parameters:
        ref - the BytesRef to test
        prefix - the expected prefix
        Returns:
        Returns true iff the ref starts with the given prefix. Otherwise false.
      • endsWith

        public static boolean endsWith​(BytesRef ref,
                                       BytesRef suffix)
        Returns true iff the ref ends with the given suffix. Otherwise false.
        Parameters:
        ref - the BytesRef to test
        suffix - the expected suffix
        Returns:
        Returns true iff the ref ends with the given suffix. Otherwise false.
      • 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 java.lang.String idToString​(byte[] id)
        Helper method to render an ID as a string, for debugging

        Returns 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.

      • intsRefToBytesRef

        public static BytesRef intsRefToBytesRef​(IntsRef ints)
        Just converts each int in the incoming IntsRef to each byte in the returned BytesRef, throwing IllegalArgumentException if any int value is out of bounds for a byte.