Class ObjectSearcher
- All Implemented Interfaces:
ObjectTool<SearchArgs>
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[]
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:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectSearcher
create
(MatcherFactory... factories) Static creator.<R> List<R>
Convenience method for executing the searcher.run
(BeanSession session, Object input, SearchArgs args) Converts the specified input to some other output.
-
Field Details
-
DEFAULT
Default reusable searcher.
-
-
Constructor Details
-
ObjectSearcher
Constructor.- Parameters:
factories
- The matcher factories to use.
If not specified, uses the following:
-
-
Method Details
-
create
Static creator.- Parameters:
factories
- The matcher factories to use.
If not specified, uses the following:- Returns:
- A new
ObjectSearcher
object.
-
run
Convenience method for executing the searcher.- Type Parameters:
R
- The return type.- Parameters:
input
- The input.searchArgs
- The search arguments. SeeSearchArgs
for format.- Returns:
- A list of maps/beans matching the
-
run
Description copied from interface:ObjectTool
Converts the specified input to some other output.- Specified by:
run
in interfaceObjectTool<SearchArgs>
- Parameters:
session
- The current bean session.input
- The input POJO.args
- The arguments.- Returns:
- The output POJO.
-