Package cdc.pstrings
Class PackedString
- java.lang.Object
-
- cdc.pstrings.PackedString
-
- Direct Known Subclasses:
PackedString16,PackedString24,PackedString32,PackedString40,PackedString48,PackedString56,PackedString64,PackedString8,PackedStringN
public abstract class PackedString extends Object
Base abstract class of packed strings.- Author:
- Damien Carbonne
-
-
Constructor Summary
Constructors Constructor Description PackedString()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static Objectconvert(String s)Converts a String to a PackedString, or a String.static Objectconvert(String s, boolean intern)protected static intget(byte[] bytes, int index)Retrieve the index-th byte as an int.(package private) PackedStringintern()static Objectintern(Object o)Converts a (valid) object to an intern version.protected abstract byte[]toBytes()StringtoString()
-
-
-
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
PackedString intern()
-
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- Whenois 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
sis null returns null. - If
sis 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), returnss.
- Parameters:
s- The String to convert.- Returns:
- The conversion of
sto a packed equivalent.
- If
-
-