Package org.apache.juneau.swap
Class FunctionalSwap<T,S>
java.lang.Object
org.apache.juneau.swap.ObjectSwap<T,S>
org.apache.juneau.swap.FunctionalSwap<T,S>
- Type Parameters:
T
- The normal form of the class.S
- The swapped form of the class.
A subclass of
ObjectSwap
that allows swap and unswap methods to be defined as functions.
See Also:
-
Field Summary
Fields inherited from class org.apache.juneau.swap.ObjectSwap
NULL
-
Constructor Summary
ConstructorDescriptionFunctionalSwap
(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T, S> swapFunction) Constructor.FunctionalSwap
(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T, S> swapFunction, ThrowingFunction<S, T> unswapFunction) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionswap
(BeanSession session, T o, String template) Same asObjectSwap.swap(BeanSession, Object)
, but can be used if your swap has a template associated with it.unswap
(BeanSession session, S f, ClassMeta<?> hint, String template) Same asObjectSwap.unswap(BeanSession, Object, ClassMeta)
, but can be used if your swap has a template associated with it.Methods inherited from class org.apache.juneau.swap.ObjectSwap
forMediaTypes, forMediaTypes, getNormalClass, getSwapClass, getSwapClassMeta, isNormalObject, isSwappedObject, match, swap, toString, unswap, withTemplate, withTemplate
-
Constructor Details
-
FunctionalSwap
public FunctionalSwap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T, S> swapFunction) Constructor.- Parameters:
normalClass
- The normal class.swappedClass
- The swapped class.swapFunction
- The function for converting from normal to swapped.
-
FunctionalSwap
public FunctionalSwap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T, S> swapFunction, ThrowingFunction<S, T> unswapFunction) Constructor.- Parameters:
normalClass
- The normal class.swappedClass
- The swapped class.swapFunction
- The function for converting from normal to swapped.unswapFunction
- The function for converting swapped to normal.
-
-
Method Details
-
swap
Description copied from class:ObjectSwap
Same asObjectSwap.swap(BeanSession, Object)
, but can be used if your swap has a template associated with it.- Overrides:
swap
in classObjectSwap<T,
S> - Parameters:
session
- The bean session to use to get the class meta. This is always going to be the same bean context that created this swap.o
- The object to be transformed.template
- The template string associated with this swap.- Returns:
- The transformed object.
- Throws:
Exception
- If a problem occurred trying to convert the output.
-
unswap
Description copied from class:ObjectSwap
Same asObjectSwap.unswap(BeanSession, Object, ClassMeta)
, but can be used if your swap has a template associated with it.- Overrides:
unswap
in classObjectSwap<T,
S> - Parameters:
session
- The bean session to use to get the class meta. This is always going to be the same bean context that created this swap.f
- The transformed object.hint
- If possible, the parser will try to tell you the object type being created. For example, on a serialized date, this may tell you that the object being created must be of typeGregorianCalendar
.
This may benull if the parser cannot make this determination.template
- The template string associated with this swap.- Returns:
- The transformed object.
- Throws:
Exception
- If a problem occurred trying to convert the output.
-