Package org.polyfrost.oneconfig.utils.v1
Class WrappingUtils
java.lang.Object
org.polyfrost.oneconfig.utils.v1.WrappingUtils
Various utilities for wrapping and unboxing of arrays, lists, etc.
see
ArrayCastUtils for some more info.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?> getUnwrapped(Class<?> cls) Return the primitive class for the given wrapped class.static Class<?> getWrapped(Class<?> cls) Return the wrapped class for the given primitive class.static booleanreturns true if the object is a primitive wrapperstatic booleanisSimpleClass(Class<?> c) static booleanreturns true if:
- the object is a primitive wrapper
- the object is a CharSequencestatic <T> TMethod that will attempt to get around the 'quirks' of casting involving primitives in java.
-
Constructor Details
-
WrappingUtils
public WrappingUtils()
-
-
Method Details
-
getWrapped
Return the wrapped class for the given primitive class. If this class is not a primitive, it will return the same class. -
getUnwrapped
Return the primitive class for the given wrapped class. If this class is not a wrapper, it will return the same class. -
richCast
Method that will attempt to get around the 'quirks' of casting involving primitives in java.
This method will do the following (note that these actions are effectively chained where applicable, so aList<Integer>can become a long[] if needed):- Convert Number classes to the target type (e.g. Float into Double)
- Turn Object[] arrays into their actual types, by inspecting the type of the first element
- Turn
Collection<?>into their array counterparts - unbox boxed arrays (e.g. Integer[] into int[])
- cast array content to the given type if possible
- convert between common primitve array types, e.g. int[] into long[]
-
isSimpleObject
returns true if:
- the object is a primitive wrapper
- the object is a CharSequence -
isSimpleClass
-
isPrimitiveWrapper
returns true if the object is a primitive wrapper
-