Class ObjectSearcher

java.lang.Object
org.apache.juneau.objecttools.ObjectSearcher
All Implemented Interfaces:
ObjectTool<SearchArgs>

public final class ObjectSearcher extends Object implements ObjectTool<SearchArgs>
POJO model searcher.

This class is designed to provide searches across arrays and collections of maps or beans. It allows you to quickly filter beans and maps using simple yet sophisticated search arguments.

Example:

MyBean[] arrayOfBeans = ...; ObjectSearcher searcher = ObjectSearcher.create(); // Returns a list of beans whose 'foo' property is 'X' and 'bar' property is 'Y'. List<MyBean> result = searcher.run(arrayOfBeans, "foo=X,bar=Y");

The tool can be used against the following data types:

  • Arrays/collections of maps or beans.

The default searcher is configured with the following matcher factories that provides the capabilities of matching against various data types. This list is extensible:

The StringMatcherFactory class provides searching based on the following patterns:

  • "property=foo" - Simple full word match
  • "property=fo*", "property=?ar" - Meta-character matching
  • "property=foo bar"(implicit), "property=^foo ^bar"(explicit) - Multiple OR'ed patterns
  • "property=+fo* +*ar" - Multiple AND'ed patterns
  • "property=fo* -bar" - Negative patterns
  • "property='foo bar'" - Patterns with whitespace
  • "property=foo\\'bar" - Patterns with single-quotes
  • "property=/foo\\s+bar" - Regular expression match

The NumberMatcherFactory class provides searching based on the following patterns:

  • "property=1" - A single number
  • "property=1 2" - Multiple OR'ed numbers
  • "property=-1 -2" - Multiple OR'ed negative numbers
  • "property=1-2","property=-2--1" - A range of numbers (whitespace ignored)
  • "property=1-2 4-5" - Multiple OR'ed ranges
  • "property=<1","property=<=1","property=>1","property=>=1" - Open-ended ranges
  • "property=!1","property=!1-2" - Negation

The TimeMatcherFactory class provides searching based on the following patterns:

  • "property=2011" - A single year
  • "property=2011 2013 2015" - Multiple years
  • "property=2011-01" - A single month
  • "property=2011-01-01" - A single day
  • "property=2011-01-01T12" - A single hour
  • "property=2011-01-01T12:30" - A single minute
  • "property=2011-01-01T12:30:45" - A single second
  • "property=>2011","property=>=2011","property=<2011","property=<=2011" - Open-ended ranges
  • "property=>2011","property=>=2011","property=<2011","property=<=2011" - Open-ended ranges
  • "property=2011 - 2013-06-30" - Closed ranges
See Also: