Class CharacterArrayEncoding
- All Implemented Interfaces:
Encoding<char[]>
,NaturalSortAware
,Serializable
,Comparator<char[]>
char[]
array type.
Null values are not supported by this class and there is no default value.
We use the same encoding as StringEncoding
.
- See Also:
-
Field Summary
Fields inherited from class io.permazen.encoding.AbstractEncoding
encodingId, typeToken
Fields inherited from interface io.permazen.encoding.Encoding
MAX_ARRAY_DIMENSIONS
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<S> char[]
protected char[]
createArray
(List<Character> elements) Create a new array instance containing the given elements.protected Character
getArrayElement
(char[] array, int index) Get an element from the given array.protected int
getArrayLength
(char[] array) Get the length of the given array.boolean
Determine whether any of this encoding's encoded values start with a0x00
byte.boolean
Determine whether any of this encoding's encoded values start with a0xff
byte.char[]
read
(ByteReader reader) Read a value from the given input.void
skip
(ByteReader reader) Read and discard abyte[]
encoded value from the given input.void
write
(ByteWriter writer, char[] array) Write a value to the given output.Methods inherited from class io.permazen.encoding.ArrayEncoding
compare, equals, fromArrayString, fromString, getElementEncoding, getFixedWidth, hashCode, sortsNaturally, supportsNull, toArrayString, toString
Methods inherited from class io.permazen.encoding.AbstractEncoding
getDefaultValue, getDefaultValueBytes, getEncodingId, getTypeToken, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
Methods inherited from interface io.permazen.encoding.Encoding
decode, encode, getKeyRange, validate, validateAndWrite
-
Constructor Details
-
CharacterArrayEncoding
public CharacterArrayEncoding()
-
-
Method Details
-
read
Description copied from interface:Encoding
Read a value from the given input.- Parameters:
reader
- byte input- Returns:
- decoded value (possibly null)
-
write
Description copied from interface:Encoding
Write a value to the given output.- Parameters:
writer
- byte outputarray
- value to write (possibly null)
-
skip
Description copied from interface:Encoding
Read and discard abyte[]
encoded value from the given input.If the value skipped over is invalid, this method may, but is not required to, throw
IllegalArgumentException
.If the value skipped over is truncated, this method must throw
IndexOutOfBoundsException
.- Parameters:
reader
- byte input
-
hasPrefix0x00
public boolean hasPrefix0x00()Description copied from interface:Encoding
Determine whether any of this encoding's encoded values start with a0x00
byte. Certain optimizations are possible when this is not the case. It is safe for this method to always return true.Note: changing the result of this method may result in an incompatible encoding if this encoding is wrapped in another class.
- Returns:
- true if an encoded value starting with
0x00
exists
-
hasPrefix0xff
public boolean hasPrefix0xff()Description copied from interface:Encoding
Determine whether any of this encoding's encoded values start with a0xff
byte. Certain optimizations are possible when this is not the case. It is safe for this method to always return true.Note: changing the result of this method may result in an incompatible encoding if this encoding is wrapped in another class.
- Returns:
- true if an encoded value starting with
0xff
exists
-
getArrayLength
protected int getArrayLength(char[] array) Description copied from class:ArrayEncoding
Get the length of the given array.- Specified by:
getArrayLength
in classArrayEncoding<char[],
Character> - Parameters:
array
- non-null array- Returns:
- array length
-
getArrayElement
Description copied from class:ArrayEncoding
Get an element from the given array.- Specified by:
getArrayElement
in classArrayEncoding<char[],
Character> - Parameters:
array
- non-null arrayindex
- index of target element inarray
- Returns:
- array element at index
index
-
createArray
Description copied from class:ArrayEncoding
Create a new array instance containing the given elements.- Specified by:
createArray
in classArrayEncoding<char[],
Character> - Parameters:
elements
- content for the new array- Returns:
- newly created array
-
convert
Description copied from interface:Encoding
Attempt to convert a value from the givenEncoding
into a value of thisEncoding
.For a non-null
value
, the implementation inEncoding
first checks whether thevalue
is already a valid value for this encoding; if so, the value is returned. Otherwise, it invokesencoding.
toString(value)
to convertvalue
into aString
, and then attempts to parse that string viathis.
fromString()
; if the parse fails, anIllegalArgumentException
is thrown. Note this means that any value will convert successfully to aString
, as long as it doesn't contain an invalid escape sequence (seeStringEncoding.toString(java.lang.String)
).If
value
is null, the implementation inEncoding
returns null, unless this encoding does not support null values, in which case anIllegalArgumentException
is thrown.Permazen's built-in encodings include the following conversions:
- Non-boolean Primitive types:
- Convert from other non-boolean primitive types as if by the corresponding Java cast
- Convert from boolean by converting to zero (if false) or one (if true)
- Boolean: converts from other primitive types as if by
value != 0
- A
char[]
array and aString
are convertible to each other - A
char
and aString
of length one are convertible to each other (otherString
s are not) - Arrays: converted by converting each array element individually (if possible)
- Non-boolean Primitive types:
-