Package cdc.pstrings

Class PackedString

    • Constructor Detail

      • PackedString

        public PackedString()
    • Method Detail

      • get

        protected static int get​(byte[] bytes,
                                 int index)
        Retrieve the index-th byte as an int.

        Conversion is done by setting low byte of the resulting int to the extracted value, and setting other bytes to 0.

        Parameters:
        bytes - The bytes array.
        index - The byte index.
        Returns:
        The inex-th byte.
      • toBytes

        protected abstract byte[] toBytes()
        Returns:
        The bytes array of encoded chars.
      • intern

        public static Object intern​(Object o)
        Converts a (valid) object to an intern version.
        Parameters:
        o - The object. Must be null or a String or a PackedString.
        Returns:
        The interned version of o.
        Throws:
        IllegalArgumentException - When o is neither null, nor a String nor a PackedString.
      • convert

        public static Object convert​(String s)
        Converts a String to a PackedString, or a String.
        • If s is null returns null.
        • If s is empty, returns "".
        • Otherwise, tries to encode s as an UTF-8 byte array.
          If this succeeds, stores that array in the more appropriate class.
          If this fails (encoding issue), returns s.
        Normally, if string is legal, UTF-8 encoding should always succeed.
        Parameters:
        s - The String to convert.
        Returns:
        The conversion of s to a packed equivalent.
      • convert

        public static Object convert​(String s,
                                     boolean intern)