Designed to provide search/view/sort/paging filtering on tabular in-memory POJO models.
It can also perform just view filtering on beans/maps.
Examples of tabular POJO models:
- Collection
- Collection
- Map[]
- Bean[]
Tabular POJO models can be thought of as tables of data. For example, a list of the following beans...
public MyBean {
public int myInt;
public String myString;
public Date myDate;
}
... can be thought of a table containing the following columns...
myInt | myString | myDate |
123 | 'foobar' | yyyy/MM/dd HH:mm:ss |
... |
From this table, you can perform the following functions:
-
Search - Return only rows where a search pattern matches.
-
View - Return only the specified subset of columns in the specified order.
-
Sort - Sort the table by one or more columns.
-
Position/limit - Only return a subset of rows.
Search
The search capabilities allow you to filter based on query patterns against strings, dates, and numbers.
Queries take the form of a Map with column names as keys, and search patterns as values.
Multiple search patterns are ANDed (i.e. all patterns must match for the row to be returned).
Example:
-
{myInt:'123'} - Return only rows where the myInt column is 123.
-
{myString:'foobar'} - Return only rows where the myString column is 'foobar'.
-
{myDate:'2001'} - Return only rows where the myDate column have dates in the year 2001.
String Patterns
Any objects can be queried against using string patterns.
If the objects being searched are not strings, then the patterns are matched against whatever is return by the
Object#toString() method.
Example string query patterns:
- foo - The string 'foo'
- foo bar - The string 'foo' or the string 'bar'
- 'foo bar' - The phrase 'foo bar'
- "foo bar" - The phrase 'foo bar'
- foo* - * matches zero-or-more characters.
- foo? - ? matches exactly one character
Notes:
-
Whitespace is ignored around search patterns.
-
Prepend + to tokens that must match. (e.g. +foo* +*bar)
-
Prepend - to tokens that must not match. (e.g. +foo* -*bar)
Numeric Patterns
Any object of type
Number (or numeric primitives) can be searched using numeric patterns.
Example numeric query patterns:
- 123 - The single number 123
- 1 2 3 - 1, 2, or 3
- 1-100 - Between 1 and 100
- 1 - 100 - Between 1 and 100
- 1 - 100 200-300 - Between 1 and 100 or between 200 and 300
- > 100 - Greater than 100
- >= 100 - Greater than or equal to 100
- !123 - Not 123
Notes:
-
Whitespace is ignored in search patterns.
-
Negative numbers are supported.
Date Patterns
Any object of type
Date or
Calendar can be searched using date patterns.
The default valid input timestamp formats (which can be overridden via the
#setValidTimestampFormats(String...)method are...
- yyyy.MM.dd.HH.mm.ss
- yyyy.MM.dd.HH.mm
- yyyy.MM.dd.HH
- yyyy.MM.dd
- yyyy.MM
- yyyy
Example date query patterns:
- 2001 - A specific year.
- 2001.01.01.10.50 - A specific time.
- >2001 - After a specific year.
- >=2001 - During or after a specific year.
- 2001 - 2003.06.30 - A date range.
- 2001 2003 2005 - Multiple date patterns are ORed.
Notes:
-
Whitespace is ignored in search patterns.
View
The view capability allows you to return only the specified subset of columns in the specified order.
The view parameter is a list of either Strings or Maps.
Example view parameters:
- column1 - Return only column 'column1'.
- column2, column1 - Return only columns 'column2' and 'column1' in that order.
Sort
The sort capability allows you to sort values by the specified rows.
The sort parameter is a list of strings with an optional '+' or '-' suffix representing
ascending and descending order accordingly.
Example sort parameters:
- column1 - Sort rows by column 'column1' ascending.
- column1+ - Sort rows by column 'column1' ascending.
- column1- - Sort rows by column 'column1' descending.
- column1, column2- - Sort rows by column 'column1' ascending, then 'column2' descending.
Paging
Use the position and limit parameters to specify a subset of rows to return.