Class TypeTokens

java.lang.Object
io.permazen.util.TypeTokens

public final class TypeTokens extends Object
Various utility routines relating to TypeTokens.
  • Method Details

    • findLowestCommonAncestorOfClasses

      public static TypeToken<?> findLowestCommonAncestorOfClasses(Stream<Class<?>> types)
      Find the narrowest type that is a supertype of all of the given types.

      This method delegates to findLowestCommonAncestor() after converting the Class instances to TypeTokens.

      Parameters:
      types - sub-types
      Returns:
      narrowest common super-type
      Throws:
      IllegalArgumentException - if types or any type in types is null
      See Also:
    • findLowestCommonAncestorsOfClasses

      public static Set<TypeToken<?>> findLowestCommonAncestorsOfClasses(Stream<Class<?>> types)
      Find the narrowest type(s) each of which is a supertype of all of the given types.

      This method delegates to findLowestCommonAncestors() after converting the Class instances to TypeTokens.

      Parameters:
      types - sub-types
      Returns:
      maximally narrow common supertype(s)
      Throws:
      IllegalArgumentException - if any type in types is null
      See Also:
    • findLowestCommonAncestor

      public static TypeToken<?> findLowestCommonAncestor(Stream<TypeToken<?>> types)
      Find the narrowest type that is a supertype of all of the given types.

      Note that there may be more than one such type. The returned type will always be as narrow as possible, but it's possible there for there to be multiple such types for which none is a sub-type of any other.

      Parameters:
      types - sub-types
      Returns:
      narrowest common super-type
    • findLowestCommonAncestors

      public static Set<TypeToken<?>> findLowestCommonAncestors(Stream<TypeToken<?>> types)
      Find the narrowest type(s) each of which is a supertype of all of the given types.
      Parameters:
      types - sub-types
      Returns:
      maximally narrow common supertype(s)
    • getWildcardedType

      public static <T> TypeToken<? extends T> getWildcardedType(Class<T> type)
      Parameterize the raw type with wildcards.
      Type Parameters:
      T - raw type
      Parameters:
      type - raw type
      Returns:
      type genericized with wildcards
    • newParameterizedType

      public static <T> TypeToken<? extends T> newParameterizedType(Class<T> target, Type[] params)
      Convert a raw class back into its generic type using caller-supplied type parameters.
      Type Parameters:
      T - raw class type
      Parameters:
      target - raw class
      params - type parameters
      Returns:
      generic TypeToken for target
      See Also: