Class FieldPredicates


  • public class FieldPredicates
    extends java.lang.Object
    Common predicates to identify fields. Usually used in combination to define a field in an object graph. For example:
         Predicate<Field> predicate = named("name").and(ofType(String.class)).and(inClass(Person.class));
    
    Author:
    Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
    • Constructor Summary

      Constructors 
      Constructor Description
      FieldPredicates()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.function.Predicate<java.lang.reflect.Field> hasModifiers​(java.lang.Integer modifiers)
      Create a predicate to check that a field has a given set of modifiers.
      static java.util.function.Predicate<java.lang.reflect.Field> inClass​(java.lang.Class<?> clazz)
      Create a predicate to check that a field is defined in a given class.
      static java.util.function.Predicate<java.lang.reflect.Field> isAnnotatedWith​(java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
      Create a predicate to check that a field is annotated with one of the given annotations.
      static java.util.function.Predicate<java.lang.reflect.Field> named​(java.lang.String name)
      Create a predicate to check that a field has a certain name pattern.
      static java.util.function.Predicate<java.lang.reflect.Field> ofType​(java.lang.Class<?> type)
      Create a predicate to check that a field has a certain type.
      • Methods inherited from class java.lang.Object

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

      • FieldPredicates

        public FieldPredicates()
    • Method Detail

      • named

        public static java.util.function.Predicate<java.lang.reflect.Field> named​(java.lang.String name)
        Create a predicate to check that a field has a certain name pattern.
        Parameters:
        name - pattern of the field name to check
        Returns:
        Predicate to check that a field has a certain name pattern
      • ofType

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

        public static java.util.function.Predicate<java.lang.reflect.Field> inClass​(java.lang.Class<?> clazz)
        Create a predicate to check that a field is defined in a given class.
        Parameters:
        clazz - enclosing type of the field to check
        Returns:
        Predicate to check that a field is defined in a given class.
      • isAnnotatedWith

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

        public static java.util.function.Predicate<java.lang.reflect.Field> hasModifiers​(java.lang.Integer modifiers)
        Create a predicate to check that a field has a given set of modifiers.
        Parameters:
        modifiers - of the field to check
        Returns:
        Predicate to check that a field has a given set of modifiers