java.lang.Object
net.luis.utils.io.codec.struct.EitherCodec<F,S>
- Type Parameters:
F
- The type of the first valueS
- The type of the second value
A codec for encoding and decoding values of type
This codec uses two other codecs to encode and decode the values of the first and second type.
Either
.This codec uses two other codecs to encode and decode the values of the first and second type.
The first codec is used to encode and decode the values of the first type.
The second codec is used to encode and decode the values of the second type.
The first codec is decoded first and if it fails, the second codec is used to decode the value.
Note: If the first codec is a string codec, it will always succeed, so the second codec will never be used.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe codec used to encode and decode the values of the first type.The codec used to encode and decode the values of the second type.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
(@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 Either<F, S> 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
-
firstCodec
The codec used to encode and decode the values of the first type. -
secondCodec
The codec used to encode and decode the values of the second type.
-
-
Constructor Details
-
EitherCodec
@Internal public EitherCodec(@NotNull @NotNull Codec<F> firstCodec, @NotNull @NotNull Codec<S> secondCodec) Constructs a new either codec using the given codecs for the first and second type.
Do not use this constructor directly, use any of the either factory methods inCodec
instead.- Parameters:
firstCodec
- The first codecsecondCodec
- The second codec- Throws:
NullPointerException
- If the first or second codec is null
-
-
Method Details
-
encodeStart
@NotNull public <R> @NotNull Result<R> encodeStart(@NotNull @NotNull TypeProvider<R> provider, @NotNull R current, @Nullable @Nullable Either<F, S> 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<F>
- 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<Either<F,S>> 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<F>
- 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
-