java.lang.Object
com.invirgance.convirgance.transform.filter.LikeFilter
All Implemented Interfaces:
Filter, Transformer, Predicate<JSONObject>

@Wiring public class LikeFilter extends Object implements Filter
Filter out JSONObjects by using a SQL-esque Like operator.

This class is useful for scenarios where large datasets are being processed, and we need to filter records based on like patterns. For example, finding all records where an industry field contains "Government" as part of its pattern.

Example use case:

    String key = "industry";
    String pattern = "_o__rnment%io_";
   
    ArrayList<JSONObject> wanted = new ArrayList<JSONObject>();
   
    FileSource source = new FileSource("src/test/resources/generic/generic_data_sorted_id.json");
    Iterator<JSONObject> records = new JSONInput().read(source).iterator();
    LikeFilter filter = new LikeFilter(key, pattern);
    Iterator<JSONObject> filtered = filter.transform(records);
 
Author:
tadghh
  • Constructor Details

    • LikeFilter

      public LikeFilter()
      Creates a new LikeFilter.
    • LikeFilter

      public LikeFilter(String key, String pattern)
      Creates a new LikeFilter with the specified key and pattern to pattern match with.
      Parameters:
      key - The key to evaluate in the JSONObject.
      pattern - The pattern to match key values with.
  • Method Details

    • getKey

      public String getKey()
      Gets the comparison key in use.
      Returns:
      The key.
    • setKey

      public void setKey(String key)
      Set the comparison key.
      Parameters:
      key - The key.
    • setPattern

      public void setPattern(String value)
      Sets the value that will be used as a pattern to match with. You can use an alternative wildcard if needed. Supports wildcards '%' (can be overridden) and '_'
      Parameters:
      value - The pattern to match values with.
    • getPattern

      public String getPattern()
      Retrieves the pattern used for comparison.
      Returns:
      The pattern pattern.
    • setWildcard

      public void setWildcard(char value)
      Sets the character that will be the 'wildcard' in the pattern.
      Parameters:
      value - Any character
    • getWildcard

      public char getWildcard()
      Gets the current character used as the pattern wildcard.
      Returns:
      The wildcard character
    • test

      public boolean test(JSONObject record)
      Description copied from interface: Filter
      Tests if the given record meets the filter condition.
      Specified by:
      test in interface Filter
      Specified by:
      test in interface Predicate<JSONObject>
      Parameters:
      record - The JSONObject to test.
      Returns:
      If the record passed or failed.