Package com.comphenix.protocol.wrappers
Class Converters
java.lang.Object
com.comphenix.protocol.wrappers.Converters
Utility class for converters
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> EquivalentConverter<T[]> array(Class<?> nmsClass, EquivalentConverter<T> converter) Creates a generic array converter.static <T,C extends Collection<T>>
EquivalentConverter<C> collection(EquivalentConverter<T> elementConverter, Function<Collection<Object>, C> genericToSpecificCollectionFactory, Function<C, Collection<?>> specificToGenericCollectionFactory) static <T> EquivalentConverter<T> Creates a simple converter for wrappers withgetHandle()andfromHandle(...)methods.static <T> EquivalentConverter<T> holder(EquivalentConverter<T> converter, WrappedRegistry registry) static <T> EquivalentConverter<T> ignoreNull(EquivalentConverter<T> converter) Returns a converter that ignores null elements, so that the underlying converter doesn't have to worry about them.static <T> EquivalentConverter<Iterable<T>> iterable(EquivalentConverter<T> elementConverter, Supplier<List<T>> specificCollectionFactory, Supplier<List<?>> genericCollectionFactory) static <T> EquivalentConverter<Optional<T>> optional(EquivalentConverter<T> converter) static <T> EquivalentConverter<T> passthrough(Class<T> clazz) Returns a converter that passes generic and specific values through without converting.static <T> List<T>
-
Constructor Details
-
Converters
public Converters()
-
-
Method Details
-
ignoreNull
Returns a converter that ignores null elements, so that the underlying converter doesn't have to worry about them.- Type Parameters:
T- Element type- Parameters:
converter- Underlying converter- Returns:
- An ignore null converter
-
passthrough
Returns a converter that passes generic and specific values through without converting.- Type Parameters:
T- Element type- Parameters:
clazz- Element class- Returns:
- A passthrough converter
-
handle
public static <T> EquivalentConverter<T> handle(Function<T, Object> toHandle, Function<Object, T> fromHandle, Class<T> specificType) Creates a simple converter for wrappers withgetHandle()andfromHandle(...)methods. With Java 8, converters can be reduced to a single line (seeBukkitConverters.getWrappedGameProfileConverter()).- Type Parameters:
T- Wrapper type- Parameters:
toHandle- Function from wrapper to handle (i.e.getHandle())fromHandle- Function from handle to wrapper (i.e.fromHandle(Object))- Returns:
- A handle converter
-
array
public static <T> EquivalentConverter<T[]> array(Class<?> nmsClass, EquivalentConverter<T> converter) Creates a generic array converter. Converts a NMS object array to and from a wrapper array by converting each element individually.- Type Parameters:
T- Generic type- Parameters:
nmsClass- NMS classconverter- Underlying converter- Returns:
- An array converter
-
optional
-
collection
public static <T,C extends Collection<T>> EquivalentConverter<C> collection(EquivalentConverter<T> elementConverter, Function<Collection<Object>, C> genericToSpecificCollectionFactory, Function<C, Collection<?>> specificToGenericCollectionFactory) -
iterable
public static <T> EquivalentConverter<Iterable<T>> iterable(EquivalentConverter<T> elementConverter, Supplier<List<T>> specificCollectionFactory, Supplier<List<?>> genericCollectionFactory) -
holder
public static <T> EquivalentConverter<T> holder(EquivalentConverter<T> converter, WrappedRegistry registry) -
toList
-