net.sf.javagimmicks.transform8.Transforming Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gimmicks Show documentation
Show all versions of gimmicks Show documentation
Utility classes, APIs and tools for Java
package net.sf.javagimmicks.transform8;
import java.util.function.Function;
import javax.xml.transform.Transformer;
/**
* An interface for objects that carry a {@link Function} for internally
* transforming objects.
*
* @param
* the source object type of the contained {@link Function}
* @param
* the target object type of the contained {@link Function}
*/
public interface Transforming
{
/**
* Returns the internal {@link Function}
*
* @return the internal {@link Function}
*/
public Function getTransformerFunction();
/**
* Returns the {@link Transformer} of a given object if it is
* {@link Transforming}.
*
* @param transforming
* the object to drag the {@link Transformer} out from
* @return the {@link Transformer} contained in the given object
* @throws IllegalArgumentException
* if the given object is not a {@link Transforming} instance
* @see #isTransforming(Object)
*/
public static Function, ?> getTransformerFunction(final Object transforming)
{
if (!isTransforming(transforming))
{
throw new IllegalArgumentException("Object is not transforming!");
}
return ((Transforming, ?>) transforming).getTransformerFunction();
}
/**
* Checks if a given object is transforming (if it is an instance of
* {@link Transforming}).
*
* @param o
* the object to check
* @return if the object is {@link Transforming}
*/
public static boolean isTransforming(final Object o)
{
return o instanceof Transforming, ?>;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy