Class FieldFilter

java.lang.Object
com.northconcepts.datapipeline.filter.Filter
com.northconcepts.datapipeline.filter.FieldFilter

public class FieldFilter extends Filter
See FieldPath for supported field name expressions.
  • Constructor Details

    • FieldFilter

      public FieldFilter(String... names)
      Creates a filter whose rules each of the given fields must pass; at least one name is required.
    • FieldFilter

      public FieldFilter(String name)
    • FieldFilter

      public FieldFilter(String name, FieldFilterRule... rules)
      Creates a filter that keeps records whose named field passes all of the given rules.
  • Method Details

    • getCurrentRule

      public FieldFilterRule getCurrentRule()
      Returns the rule most recently applied by allow(Record) (the failing one when a rule rejects the record) or null if none was.
    • getCurrentField

      public Field getCurrentField()
      Returns the field most recently checked by allow(Record) or null if none was.
    • getName

      public String getName()
      Returns the field name when this filter checks exactly one field, otherwise null.
    • isThrowExceptionOnMissingField

      public boolean isThrowExceptionOnMissingField()
      Indicates if a record missing a checked field causes an exception (the default) instead of being discarded.
    • setThrowExceptionOnMissingField

      public FieldFilter setThrowExceptionOnMissingField(boolean throwExceptionOnMissingField)
      Indicates if a record missing a checked field causes an exception (the default) instead of being discarded.
    • addRule

      public FieldFilter addRule(FieldFilterRule... rules)
      Adds rules that every checked field must pass for the record to be kept.
    • addNotRule

      public FieldFilter addNotRule(FieldFilterRule rule)
      Adds a rule requiring the given rule to fail.
    • or

      public FieldFilter or(FieldFilterRule... rule)
      Adds a rule requiring at least one of the given rules to pass.
    • valueMatches

      public <T> FieldFilter valueMatches(T... array)
      Adds a rule requiring the field's value to equal one of the given values (compared with equals, so types must match).
    • valueNotMatches

      public <T> FieldFilter valueNotMatches(T... array)
      Adds a rule requiring the field's value to equal none of the given values (compared with equals).
    • patternMatches

      public FieldFilter patternMatches(String... regex)
      Adds a rule requiring the field's whole value to match one of the given regular expressions; null values fail.
    • patternNotMatches

      public FieldFilter patternNotMatches(String... regex)
      Adds a rule requiring the field's value to be null or not wholly match any of the given regular expressions.
    • contains

      public FieldFilter contains(String value, boolean caseSensitive)
      Adds a rule requiring the field's value, as a string, to contain the given text; null values fail.
    • notContains

      public FieldFilter notContains(String value, boolean caseSensitive)
      Adds a rule requiring the field's value to be null or, as a string, not contain the given text.
    • isFieldType

      public FieldFilter isFieldType(FieldType type)
      Adds a rule requiring the field to be of the given FieldType.
    • isNotFieldType

      public FieldFilter isNotFieldType(FieldType type)
      Adds a rule requiring the field not to be of the given FieldType.
    • isInstanceOfJavaType

      public FieldFilter isInstanceOfJavaType(Class<?> type)
      Adds a rule requiring the field's value to be an instance of the given type or a subtype; null values fail.
    • isNotInstanceOfJavaType

      public FieldFilter isNotInstanceOfJavaType(Class<?> type)
      Adds a rule requiring the field's value to be null or not an instance of the given type.
    • isJavaType

      public FieldFilter isJavaType(Class<?> type)
      Adds a rule requiring the field's value to be null or exactly of the given class (subclasses fail).
    • isNotJavaType

      public FieldFilter isNotJavaType(Class<?> type)
      Adds a rule requiring the field's value to be non-null and not exactly of the given class.
    • IsNotNull

      public FieldFilter IsNotNull()
      Adds a rule requiring the field's value to be non-null.
    • isNull

      public FieldFilter isNull()
      Adds a rule requiring the field's value to be null.
    • isEmpty

      public FieldFilter isEmpty()
      Adds an IsEmpty rule to this filter. The field will match if it is null, an empty array, or an empty/whitespace-only string.
      Returns:
      this FieldFilter instance for method chaining
      See Also:
    • isNotEmpty

      public FieldFilter isNotEmpty()
      Adds an IsNotEmpty rule to this filter. The field will match if it is not null, not an empty array, and not an empty/whitespace-only string.
      Returns:
      this FieldFilter instance for method chaining
      See Also:
    • dateIsBefore

      public FieldFilter dateIsBefore(Date date)
      Adds a rule requiring the field's date-time value to be null or before the given date.
    • dateIsBefore

      public FieldFilter dateIsBefore(String date)
      Adds a rule requiring the field's date-time value to be null or before the given yyyy-MM-dd or yyyy-MM-dd HH:mm[:ss[.SSS]] date.
    • dateIsAfter

      public FieldFilter dateIsAfter(Date date)
      Adds a rule requiring the field's date-time value to be after the given date; null values fail.
    • dateIsAfter

      public FieldFilter dateIsAfter(String date)
      Adds a rule requiring the field's date-time value to be after the given yyyy-MM-dd or yyyy-MM-dd HH:mm[:ss[.SSS]] date; null values fail.
    • dateIs

      public FieldFilter dateIs(Date date)
      Adds a rule requiring the field's date-time value to equal the given date to the millisecond.
    • dateIs

      public FieldFilter dateIs(String date)
      Adds a rule requiring the field's date-time value to equal the given yyyy-MM-dd or yyyy-MM-dd HH:mm[:ss[.SSS]] date to the millisecond.
    • getRuleCount

      public int getRuleCount()
    • getRule

      public FieldFilterRule getRule(int index)
    • allow

      public boolean allow(Record record)
      Description copied from class: Filter
      Tests whether a record passes this filter.

      Contract for subclasses (see also docs/authoring/Filter.md):

      • Return true to keep the record.
      • Return false to discard the record (routed to a discard writer if the host FilteringReader is configured with one).
      • Must be a pure decision — do not mutate the record here.
      • Throw DataException only for unrecoverable filter failures; for ordinary "data fails predicate" cases, return false.
      Specified by:
      allow in class Filter
    • getNames

      public FieldPath[] getNames()
    • toString

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

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Filter
      Adds this filter's settings to the given exception and returns it; subclasses override it to add their own.
      Overrides:
      addExceptionProperties in class Filter
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object