com.devexperts.qd.util
Class ShortString

java.lang.Object
  extended by com.devexperts.qd.util.ShortString

public class ShortString
extends java.lang.Object

Auxiliary class for converting short (up to 8 characters) strings into primitive long values and backwards. The conversion always skips zero characters in the input and never produces them in the output.


Method Summary
static java.lang.String decode(long code)
          Decodes long code into string.
static long encode(byte[] data, int offset, int length)
           
static long encode(java.lang.String str)
          Encodes string up to 8 characters as a long.
static long encode(java.lang.String str, int offset, int length)
          Encodes a portion of a string up to 8 character to long.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encode

public static long encode(java.lang.String str)
Encodes string up to 8 characters as a long. Zero characters (code point 0) are skipped, characters larger than 0xFF are prohibited. All other characters are concatenated together to form the code. The first character of string becomes the most significant byte of the resulting code. For example, "A" encodes as 0x41L, "AB" encodes as 0x4142L, etc. null and "" both encode as 0.

Parameters:
str - the string.
Returns:
the code.
Throws:
java.lang.IllegalArgumentException - if length is greater than 8 or string contains character larger than 0xFF

encode

public static long encode(java.lang.String str,
                          int offset,
                          int length)
Encodes a portion of a string up to 8 character to long. This method is equal to encode(str.substring(offset, offset + length)).

Parameters:
str - the string.
offset - the initial offset of the string.
length - the length of the substring to encode.
Returns:
the code.
Throws:
java.lang.NullPointerException - if str is null.
java.lang.IllegalArgumentException - if length is greater than 8 or string contains character larger than 0xFF
See Also:
encode(String)

encode

public static long encode(byte[] data,
                          int offset,
                          int length)

decode

public static java.lang.String decode(long code)
Decodes long code into string. This method skips zeros bytes in the given code and converts remaining bytes into characters from the most-significant byte to the least-significant one. Thus, all of 0x0000000000000041L, 0x0000004100000000L, and 0x4100000000000000L decode as "A". 0x4142L decodes as "AB", etc. 0 decodes as null.