Class TypePredicates


  • public class TypePredicates
    extends java.lang.Object
    Common predicates to identify types. Usually used in combination to define a collection of types. For example:
         Predicate<Class<?>> predicate = inPackage("java.util").or(inPackage("com.sun"));
    
    Author:
    Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
    • Constructor Summary

      Constructors 
      Constructor Description
      TypePredicates()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.function.Predicate<java.lang.Class<?>> hasModifiers​(java.lang.Integer modifiers)
      Create a predicate to check that a type has a given set of modifiers.
      static java.util.function.Predicate<java.lang.Class<?>> inPackage​(java.lang.String packageNamePrefix)
      Create a predicate to check that a type is defined in a given package.
      static java.util.function.Predicate<java.lang.Class<?>> isAbstract()
      Create a predicate to check if a class is abstract.
      static java.util.function.Predicate<java.lang.Class<?>> isAnnotatedWith​(java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
      Create a predicate to check that a type is annotated with one of the given annotations.
      static java.util.function.Predicate<java.lang.Class<?>> isArray()
      Create a predicate to check if a type is an array.
      static java.util.function.Predicate<java.lang.Class<?>> isAssignableFrom​(java.lang.Class<?> type)
      Create a predicate to check if a type is assignable from another type.
      static java.util.function.Predicate<java.lang.Class<?>> isEnum()
      Create a predicate to check if a type is an enumeration.
      static java.util.function.Predicate<java.lang.Class<?>> isInterface()
      Create a predicate to check if a type is an interface.
      static java.util.function.Predicate<java.lang.Class<?>> isPrimitive()
      Create a predicate to check if a type is primitive.
      static java.util.function.Predicate<java.lang.Class<?>> named​(java.lang.String name)
      Create a predicate to check that a type has a given name.
      static java.util.function.Predicate<java.lang.Class<?>> ofType​(java.lang.Class<?> type)
      Create a predicate to check that a class has a certain type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TypePredicates

        public TypePredicates()
    • Method Detail

      • named

        public static java.util.function.Predicate<java.lang.Class<?>> named​(java.lang.String name)
        Create a predicate to check that a type has a given name.
        Parameters:
        name - name on the type
        Returns:
        Predicate to check that a type has a given name.
      • ofType

        public static java.util.function.Predicate<java.lang.Class<?>> ofType​(java.lang.Class<?> type)
        Create a predicate to check that a class has a certain type.
        Parameters:
        type - of the class to check
        Returns:
        Predicate to check that a class has a certain type
      • inPackage

        public static java.util.function.Predicate<java.lang.Class<?>> inPackage​(java.lang.String packageNamePrefix)
        Create a predicate to check that a type is defined in a given package.
        Parameters:
        packageNamePrefix - prefix of the package name
        Returns:
        Predicate to check that a type is defined in a given package.
      • isAnnotatedWith

        public static java.util.function.Predicate<java.lang.Class<?>> isAnnotatedWith​(java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
        Create a predicate to check that a type is annotated with one of the given annotations.
        Parameters:
        annotations - present on the type
        Returns:
        Predicate to check that a type is annotated with one of the given annotations.
      • isInterface

        public static java.util.function.Predicate<java.lang.Class<?>> isInterface()
        Create a predicate to check if a type is an interface.
        Returns:
        a predicate to check if a type is an interface
      • isPrimitive

        public static java.util.function.Predicate<java.lang.Class<?>> isPrimitive()
        Create a predicate to check if a type is primitive.
        Returns:
        a predicate to check if a type is primitive
      • isAbstract

        public static java.util.function.Predicate<java.lang.Class<?>> isAbstract()
        Create a predicate to check if a class is abstract.
        Returns:
        a predicate to check if a class is abstract
      • hasModifiers

        public static java.util.function.Predicate<java.lang.Class<?>> hasModifiers​(java.lang.Integer modifiers)
        Create a predicate to check that a type has a given set of modifiers.
        Parameters:
        modifiers - of the type to check
        Returns:
        Predicate to check that a type has a given set of modifiers
      • isEnum

        public static java.util.function.Predicate<java.lang.Class<?>> isEnum()
        Create a predicate to check if a type is an enumeration.
        Returns:
        a predicate to check if a type is an enumeration
      • isArray

        public static java.util.function.Predicate<java.lang.Class<?>> isArray()
        Create a predicate to check if a type is an array.
        Returns:
        a predicate to check if a type is an array
      • isAssignableFrom

        public static java.util.function.Predicate<java.lang.Class<?>> isAssignableFrom​(java.lang.Class<?> type)
        Create a predicate to check if a type is assignable from another type.
        Parameters:
        type - to check
        Returns:
        a predicate to check if a type is assignable from another type.