Class ValueType<T>

java.lang.Object
cc.carm.lib.configuration.adapter.ValueType<T>

public abstract class ValueType<T> extends Object
ValueType used to get the generic type of the value, It can be used to check if an object is an instance of a specific type, and to cast objects to the correct type.

Java's type system is not capable of retaining generic type information at runtime. This class is used to represent a type with its generic parameters.

  • Field Details Link icon

  • Constructor Details Link icon

    • ValueType Link icon

      protected ValueType()
  • Method Details Link icon

    • of Link icon

      public static <T> ValueType<T> of(@NotNull T value)
    • of Link icon

      public static <T> ValueType<T> of(Type type)
    • of Link icon

      public static <T> ValueType<T> of(@NotNull @NotNull Class<T> clazz)
    • ofList Link icon

      public static <T> ValueType<List<T>> ofList(@NotNull @NotNull Class<T> paramType)
    • ofList Link icon

      public static <T> ValueType<List<T>> ofList(@NotNull @NotNull ValueType<T> paramType)
    • ofMap Link icon

      public static <K, V> ValueType<Map<K,V>> ofMap(@NotNull @NotNull Class<K> keyType, @NotNull @NotNull Class<V> valueType)
    • ofMap Link icon

      public static <K, V> ValueType<Map<K,V>> ofMap(@NotNull @NotNull ValueType<K> keyType, @NotNull @NotNull ValueType<V> valueType)
    • of Link icon

      public static <T> ValueType<T> of(Class<?> rawType, Type... types)
      Get the generic type of the complex type.
      Type Parameters:
      T - The type
      Parameters:
      rawType - The raw type
      types - The type arguments
      Returns:
      The ValueType
    • getType Link icon

      public Type getType()
    • isSubtypeOf Link icon

      public boolean isSubtypeOf(Class<?> target)
      Checks if this ValueType is a subtype of the given Class.
      Parameters:
      target - The target Class to check against
      Returns:
      true if this ValueType is a subtype of the target Class, false otherwise
    • isSubtypeOf Link icon

      public boolean isSubtypeOf(ValueType<?> target)
      Checks if this ValueType is a subtype of the given ValueType.
      Parameters:
      target - The target ValueType to check against
      Returns:
      true if this ValueType is a subtype of the target, false otherwise
    • isInstance Link icon

      public boolean isInstance(Object obj)
      Checks if the given object is an instance of the type represented by this ValueType.
      Parameters:
      obj - The object to check
      Returns:
      true if the object is an instance of the type, false otherwise
    • getRawType Link icon

      public Class<T> getRawType()
      Extracts the raw type from the generic type.
      Returns:
      The raw type of the generic type
      Throws:
      IllegalStateException - if the type is not a Class or ParameterizedType
    • cast Link icon

      public T cast(Object obj)
      Casts the object to the type represented by this ValueType.
      Parameters:
      obj - The object to cast
      Returns:
      The object cast to the type represented by this ValueType
    • toString Link icon

      public String toString()
      Returns a string representation of the type. Like "java.util.List<java.lang.String>" or "java.lang.Integer".
      Overrides:
      toString in class Object
      Returns:
      String representation of the type
    • equals Link icon

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode Link icon

      public int hashCode()
      Overrides:
      hashCode in class Object