Class FieldComparators

java.lang.Object
org.assertj.core.api.recursive.comparison.FieldComparators

public class FieldComparators extends Object
An internal holder of the comparators for fields described by their path without element index.

Examples: name.first or names.first but not names[1].first or names.[1].first

  • Field Details

    • comparatorByPatterns

      protected final LinkedList<org.assertj.core.api.recursive.comparison.ComparatorForPatterns> comparatorByPatterns
    • fieldHolder

      protected final Map<String,Comparator<?>> fieldHolder
  • Constructor Details

    • FieldComparators

      public FieldComparators()
  • Method Details

    • registerComparator

      public void registerComparator(String fieldLocation, Comparator<?> comparator)
      Registers the comparator for the given fieldLocation.
      Parameters:
      fieldLocation - the location where to apply the comparator
      comparator - the comparator itself
    • registerComparatorForFieldsMatchingRegexes

      public void registerComparatorForFieldsMatchingRegexes(String[] regexes, Comparator<?> comparator)
      Registers the comparator for the given regexes field location.
      Parameters:
      regexes - the regexes field location where to apply the comparator
      comparator - the comparator to use for the regexes
    • hasComparatorForField

      public boolean hasComparatorForField(String fieldLocation)
      Checks, whether an any comparator is associated with the giving field location.
      Parameters:
      fieldLocation - the field location which association need to check
      Returns:
      is field location contain a custom comparator
    • getComparatorForField

      public Comparator<?> getComparatorForField(String fieldLocation)
      Retrieves a custom comparator, which is associated with the giving field location. If this location does not associate with any custom comparators - this method returns null.
      Parameters:
      fieldLocation - the field location that has to be associated with a comparator
      Returns:
      a custom comparator or null
    • comparatorByFields

      public Stream<Map.Entry<String,Comparator<?>>> comparatorByFields()
      Returns a sequence of associated field-comparator pairs.
      Returns:
      sequence of field-comparator pairs
    • comparatorByRegexFields

      public Stream<Map.Entry<List<Pattern>,Comparator<?>>> comparatorByRegexFields()
    • isEmpty

      public boolean isEmpty()
      Returns:
      true is there are registered entities, false otherwise
    • hasFieldComparators

      public boolean hasFieldComparators()
    • hasRegexFieldComparators

      public boolean hasRegexFieldComparators()
    • put

      public void put(String fieldLocation, Comparator<?> entity)
      Pairs the giving entity with the fieldLocation.
      Parameters:
      fieldLocation - the field location where to apply the giving entity
      entity - the entity to pair
    • get

      public Comparator<?> get(String fieldLocation)
      Retrieves a specific entity which is associated with the giving filedLocation from the field holder, if it presents. Otherwise, this method returns null.
      Parameters:
      fieldLocation - the field location which has to be associated with an entity
      Returns:
      entity or null
    • hasEntity

      public boolean hasEntity(String fieldLocation)
      Checks, whether an any entity associated with the giving field location.
      Parameters:
      fieldLocation - the field location which association need to check
      Returns:
      is entity associated with field location
    • entryByField

      public Stream<Map.Entry<String,Comparator<?>>> entryByField()
      Returns a sequence of all field-entry pairs which the current holder supplies.
      Returns:
      sequence of field-entry pairs
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object