java.lang.Object
net.luis.utils.io.codec.struct.ListCodec<C>
- Type Parameters:
C
- The type of elements in the list
A codec for encoding and decoding lists of elements.
This codec uses another codec to encode and decode the elements of the list.
This codec uses another codec to encode and decode the elements of the list.
The list codec can be sized to only accept lists of a certain size range.
The minimum size and maximum size are inclusive.
If the list size is out of range, the codec will return an error during encoding or decoding.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe codec used to encode and decode the elements of the list.private final int
The maximum size of the list (inclusive).private final int
The minimum size of the list (inclusive).Fields inherited from interface net.luis.utils.io.codec.Codec
BOOLEAN, BYTE, BYTE_ARRAY, CHARSET, DOUBLE, DOUBLE_STREAM, FILE, FLOAT, INT_STREAM, INTEGER, LOCAL_DATE, LOCAL_DATE_TIME, LOCAL_TIME, LONG, LONG_STREAM, PATH, SHORT, STRING, URI, URL, UUID, ZONED_DATE_TIME
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new list codec using the given codec for the elements.
The list codec will accept lists of any size.
Do not use this constructor directly, use any of the list factory methods inCodec
instead.Constructs a new list codec using the given codec for the elements and the size range of the list.
Do not use this constructor directly, use any of the list factory methods inCodec
instead. -
Method Summary
Modifier and TypeMethodDescriptiondecodeStart
(@NotNull TypeProvider<R> provider, R value) Decodes the value of the specified type and returns the result.
The result contains the decoded value or an error message.<R> @NotNull Result
<R> encodeStart
(@NotNull TypeProvider<R> provider, R current, @Nullable List<C> value) Encodes the value of the specified type and returns the result.
The result contains the encoded value or an error message.boolean
int
hashCode()
toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.luis.utils.io.codec.Codec
configure, getter, keyable, list, list, list, map, mapFlat, named, noneEmptyList, optional, orElse, orElseGet, stream, validate, withAlternative, xmap
Methods inherited from interface net.luis.utils.io.codec.decoder.Decoder
decode, mapDecoder
Methods inherited from interface net.luis.utils.io.codec.encoder.Encoder
encode, encode, mapEncoder
-
Field Details
-
codec
The codec used to encode and decode the elements of the list. -
minSize
private final int minSizeThe minimum size of the list (inclusive). -
maxSize
private final int maxSizeThe maximum size of the list (inclusive).
-
-
Constructor Details
-
ListCodec
Constructs a new list codec using the given codec for the elements.
The list codec will accept lists of any size.
Do not use this constructor directly, use any of the list factory methods inCodec
instead.- Parameters:
codec
- The codec for the elements- Throws:
NullPointerException
- If the codec is null
-
ListCodec
Constructs a new list codec using the given codec for the elements and the size range of the list.
Do not use this constructor directly, use any of the list factory methods inCodec
instead.- Parameters:
codec
- The codec for the elementsminSize
- The minimum size of the list (inclusive)maxSize
- The maximum size of the list (inclusive)- Throws:
NullPointerException
- If the codec is nullIllegalArgumentException
- If the minimum size is less than zero or greater than the maximum size
-
-
Method Details
-
encodeStart
@NotNull public <R> @NotNull Result<R> encodeStart(@NotNull @NotNull TypeProvider<R> provider, @NotNull R current, @Nullable @Nullable List<C> value) Description copied from interface:Encoder
Encodes the value of the specified type and returns the result.
The result contains the encoded value or an error message.
The current value is the value that is currently encoded.
In the most cases this value should be equal toTypeProvider.empty()
.
In the case of encoding a value that is part of a bigger structure, the current value should be the structure.
- Specified by:
encodeStart
in interfaceEncoder<C>
- Type Parameters:
R
- The type to encode to- Parameters:
provider
- The type providercurrent
- The current valuevalue
- The value to encode- Returns:
- The result
-
decodeStart
@NotNull public <R> @NotNull Result<List<C>> decodeStart(@NotNull @NotNull TypeProvider<R> provider, @Nullable R value) Description copied from interface:Decoder
Decodes the value of the specified type and returns the result.
The result contains the decoded value or an error message.- Specified by:
decodeStart
in interfaceDecoder<C>
- Type Parameters:
R
- The type to decode from- Parameters:
provider
- The type providervalue
- The value to decode- Returns:
- The result
-
equals
-
hashCode
public int hashCode() -
toString
-