java.lang.Object
net.luis.utils.io.codec.struct.UnitCodec<C>
- Type Parameters:
C
- The type of the unit value
A codec for encoding and decoding unit values.
This codec does not encode or decode any value, it is used to represent a unit value.
This codec does not encode or decode any value, it is used to represent a unit value.
The unit codec can be used to represent a value that is not encoded or decoded.
This is useful when a codec is required to encode or decode a value, but the value is not needed.
The unit codec will always return the same value when encoding and decoding.
During encoding, the current value is returned.
During decoding, the unit value is returned which is created by a supplier.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe supplier used to create the unit value.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
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondecodeStart
(@Nullable 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
(@Nullable TypeProvider<R> provider, R current, 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
-
supplier
The supplier used to create the unit value.
-
-
Constructor Details
-
UnitCodec
Constructs a new unit codec using the given supplier for the unit value.
Do not use this constructor directly, use any of the unit factory methods inCodec
instead.- Parameters:
supplier
- The supplier used to create the unit value- Throws:
NullPointerException
- If the supplier is null
-
-
Method Details
-
encodeStart
@NotNull public <R> @NotNull Result<R> encodeStart(@Nullable @Nullable TypeProvider<R> provider, @NotNull R current, @Nullable 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<C> decodeStart(@Nullable @Nullable 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
-