Class MapPathMatcher

java.lang.Object
net.solarnetwork.util.MapPathMatcher

public class MapPathMatcher extends Object
Match search filter against a nested map using paths for filter keys.

This utility tries to match a SearchFilter against a Map, by treating each search filter key (the left-hand side of each filter comparison) like a URL path that corresponds to an entry in the map. Each path segment represents a map, possibly nested with the root map.

For example, given this JSON representation of a nested map structure:

 {
     "foo": {
         "bar": 1,
         "bim": "bam"
     },
     "pow": 2
 }
 

then the filters (/foo/bar=1) and (/foo/bim=bam) and (/pow=2) and (&(/foo/bar=1)(/pow<5)) would match while (/foo/bar>1) and (/foo/bim=no) and (|(/foo/bar>1)(/pow>2)) would not.

Originally ported from the JavaScript objectPathMatcher class.

Since:
1.67
Version:
1.0
Author:
matt
  • Constructor Details

    • MapPathMatcher

      public MapPathMatcher(Map<String,?> map)
      Constructor.
      Parameters:
      map - the map root
  • Method Details

    • matches

      public static boolean matches(Map<String,?> map, String filterText)
      Test if a filter matches a map.
      Parameters:
      map - the map
      filterText - the filter in text form
      Returns:
      true if the filter matches
      See Also:
    • matches

      public static boolean matches(Map<String,?> map, SearchFilter filter)
      Test if a filter matches the configured map.
      Parameters:
      map - the map
      filter - the filter to test for matches
      Returns:
      true if the filter matches
    • matches

      public boolean matches(String filterText)
      Test if a filter matches the configured map.
      Parameters:
      filterText - the filter in text form
      Returns:
      true if the filter matches
      See Also:
    • matches

      public boolean matches(SearchFilter filter)
      Test if a filter matches the configured map.
      Parameters:
      filter - the filter to test for matches
      Returns:
      true if the filter matches