public class ShortString extends Object
Modifier and Type | Method and Description |
---|---|
static String |
decode(long code)
Decodes long code into string.
|
static int |
decodeInt(long code)
Decodes short string into integer.
|
static long |
encode(byte[] data,
int offset,
int length)
Encodes a portion of a byte array up to 8 character to a long.
|
static long |
encode(char[] data,
int offset,
int length)
Encodes a portion of a char array up to 8 character to a long.
|
static long |
encode(String str)
Encodes string up to 8 characters as a long.
|
static long |
encode(String str,
int offset,
int length)
Encodes a portion of a string up to 8 character to a long.
|
static long |
encodeInt(int value)
Encodes integer number as a short string - up to 8 characters represented as a long.
|
public static long encode(String str)
"A"
encodes as 0x41L
, "AB"
encodes as 0x4142L
, etc.
null
and ""
both encode as 0
.str
- the string.IllegalArgumentException
- if length is greater than 8 or string contains character larger than 0xFFpublic static long encode(String str, int offset, int length)
encode
(str.substring
(offset, offset + length))
.str
- the string.offset
- the initial offset of the substring.length
- the length of the substring to encode.NullPointerException
- if str
is null.IllegalArgumentException
- if length is greater than 8 or string contains character larger than 0xFFencode(String)
public static long encode(char[] data, int offset, int length)
encode
(new String
(data, offset, length))
.data
- the char array.offset
- the initial offset of the substring.length
- the length of the substring to encode.NullPointerException
- if str
is null.IllegalArgumentException
- if length is greater than 8 or string contains character larger than 0xFFencode(String)
public static long encode(byte[] data, int offset, int length)
encode
(new String
(data, 0, offset, length))
.data
- the byte array.offset
- the initial offset of the substring.length
- the length of the substring to encode.NullPointerException
- if str
is null.IllegalArgumentException
- if length is greater than 8encode(String)
public static String decode(long code)
0x0000000000000041L
,
0x0000004100000000L
, and 0x4100000000000000L
decode as "A"
.
0x4142L
decodes as "AB"
, etc.
0
decodes as null
.code
- the code.public static long encodeInt(int value)
encode
(Integer.toString
(value))
.value
- the number.IllegalArgumentException
- if number is lesser than -9999999 or larger than 99999999public static int decodeInt(long code)
Integer.parseInt
(decode
(code))
.code
- the code.NumberFormatException
- if the code does not contain a parsable integerCopyright © 2002–2025 Devexperts LLC. All rights reserved.