Class WrappingUtils

java.lang.Object
org.polyfrost.oneconfig.utils.v1.WrappingUtils

public final class WrappingUtils extends Object
Various utilities for wrapping and unboxing of arrays, lists, etc. see ArrayCastUtils for some more info.
  • Constructor Details

    • WrappingUtils

      public WrappingUtils()
  • Method Details

    • getWrapped

      public static Class<?> getWrapped(Class<?> cls)
      Return the wrapped class for the given primitive class. If this class is not a primitive, it will return the same class.
    • getUnwrapped

      public static Class<?> getUnwrapped(Class<?> cls)
      Return the primitive class for the given wrapped class. If this class is not a wrapper, it will return the same class.
    • richCast

      public static <T> T richCast(Object in, Class<T> target)
      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 a List<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

      public static boolean isSimpleObject(Object o)
      returns true if:
      - the object is a primitive wrapper
      - the object is a CharSequence
    • isSimpleClass

      public static boolean isSimpleClass(Class<?> c)
    • isPrimitiveWrapper

      public static boolean isPrimitiveWrapper(Object o)
      returns true if the object is a primitive wrapper