Package gov.nasa.jpl.aerie.json
Interface Convert<S,T>
- Type Parameters:
S- the "source" type of the conversionT- the "target" type of the conversion
public interface Convert<S,T>
An infallible two-way conversion between types
S and T.
When round-tripping a value of type T through S and back, the result must be equal to the
original value. That is, Objects.equals(from(to(t)), t) must always be true.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <S,T> Convert <S, T> Constructs a conversion from two individual transformations.Extends this two-way conversion to a new target type by chaining with another conversion.Converts a value forward from the source type to the target type.static <T> Convert<T, T> identity()Constructs a trivial conversion between a type and itself.invert()Inverts this two-way conversion, swapping its source and target types.Converts a value backward to the source type from the target type.
-
Method Details
-
from
Converts a value forward from the source type to the target type.- Parameters:
source- the value to convert- Returns:
- the converted value
-
to
Converts a value backward to the source type from the target type.- Parameters:
target- the value to convert- Returns:
- the converted value
-
between
Constructs a conversion from two individual transformations. The first function must be a left inverse of the second, i.e.Objects.equals(from(to(t)), t)must always be true.- Type Parameters:
S- the "source" type of the conversionT- the "target" type of the conversion- Parameters:
from- an infallible transformation from the source type to the target typeto- an infallible transformation to the source type from the target type
-
identity
Constructs a trivial conversion between a type and itself.This is most useful as an initial value when accumulating multiple conversions together.
- Type Parameters:
T- the type to trivially convert into itself- Returns:
- a trivial two-way conversion from a type to itself
-
compose
Extends this two-way conversion to a new target type by chaining with another conversion.- Type Parameters:
X- the new "target" type- Parameters:
other- a conversion from this target type to the new target type- Returns:
- a combined conversion from this source type to the new target type
-
invert
Inverts this two-way conversion, swapping its source and target types.- Returns:
- a two-way conversion with the same logic as this one, but with its source and target types swapped
-