java.lang.Object
nl.jqno.equalsverifier.internal.reflection.FieldCache

public class FieldCache extends Object
Contains a cache for values connected to specific fields, for SubjectCreator.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    (package private) static final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Map<FieldCache.Key,Tuple<?>>
    We store Strings instead of Fields, to make it easier to interact with when we don't actually have a reference to a Field.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(String fieldName, TypeTag fieldType)
    Returns whether values are available for the given field.
    <T> Tuple<T>
    get(String fieldName, TypeTag fieldType)
    Retrieves the values from the cache for the given field.
    Returns the fields preset in the cache.
    <T> void
    put(String fieldName, TypeTag fieldType, Tuple<T> tuple)
    Adds the given factory to the cache and associates it with the given type.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • cache

      private final Map<FieldCache.Key,Tuple<?>> cache
      We store Strings instead of Fields, to make it easier to interact with when we don't actually have a reference to a Field.
  • Constructor Details

    • FieldCache

      public FieldCache()
  • Method Details

    • put

      public <T> void put(String fieldName, TypeTag fieldType, Tuple<T> tuple)
      Adds the given factory to the cache and associates it with the given type.
      Type Parameters:
      T - The type of the values.
      Parameters:
      fieldName - The name of the field to associate with the values.
      fieldType - The type of the field to associate with the values.
      tuple - The tuple that contains the values.
    • get

      public <T> Tuple<T> get(String fieldName, TypeTag fieldType)
      Retrieves the values from the cache for the given field.

      What happens when there are no values, is undefined. Always call contains(String, TypeTag) first.

      Type Parameters:
      T - The returned values will have this as generic type.
      Parameters:
      fieldName - The name of the field for which values are needed.
      fieldType - The type of the field for which values are needed.
      Returns:
      A tuple of values for the given type, or null if none is available.
    • contains

      public boolean contains(String fieldName, TypeTag fieldType)
      Returns whether values are available for the given field.
      Parameters:
      fieldName - The name of the field for which values are needed.
      fieldType - The type of the field for which values are needed.
      Returns:
      Whether values are available for the given field.
    • getFieldNames

      public Set<String> getFieldNames()
      Returns the fields preset in the cache.
      Returns:
      The fields preset in the cache.