Tabnine Logo
PojoQuery
Code IndexAdd Tabnine to your IDE (free)

How to use
PojoQuery
in
org.apache.juneau.utils

Best Java code snippets using org.apache.juneau.utils.PojoQuery (Showing top 20 results out of 315)

origin: apache/juneau

  @Override /* RestConverter */
  public Object convert(RestRequest req, Object o) {
    if (o == null)
      return null;
    SearchArgs searchArgs = req.getQuery().getSearchArgs();
    if (searchArgs == null)
      return o;
    return new PojoQuery(o, req.getBeanSession()).filter(searchArgs);
  }
}
origin: apache/juneau

private static void doView(List list, List<String> view) {
  for (ListIterator i = list.listIterator(); i.hasNext();) {
    Object o = i.next();
    Map m = (Map)o;
    doView(m, view);
  }
}
origin: org.apache.juneau/juneau-marshall

/**
 * Parses a timestamp string off the beginning of the string segment 'seg'.
 * Goes through each possible valid timestamp format until it finds a match.
 * The position where the parsing left off is stored in pp.
 *
 * @param seg The string segment being parsed.
 * @param pp Where parsing last left off.
 * @return An object representing a timestamp.
 */
CalendarP parseDate(String seg, ParsePosition pp) {
  CalendarP cal = null;
  for (int i = 0; i < validTimestampFormats.length && cal == null; i++) {
    pp.setIndex(0);
    SimpleDateFormat f = validTimestampFormats[i];
    Date d = f.parse(seg, pp);
    int idx = pp.getIndex();
    if (idx != 0) {
      // it only counts if the next character is '-', 'space', or end-of-string.
      char c = (seg.length() == idx ? 0 : seg.charAt(idx));
      if (c == 0 || c == '-' || Character.isWhitespace(c))
        cal = new CalendarP(d, getPrecisionField(f.toPattern()));
    }
  }
  if (cal == null)
    throw new FormattedRuntimeException("Invalid date encountered:  ''{0}''", seg);
  return cal;
}
origin: apache/juneau

s = replace(s, '*', '\u9997', true);
s = replace(s, '?', '\u9996', true);
s = unEscapeChars(s, new char[]{'*','?'});
s = s.replace('\u9998', '-');
String[] sa = splitQuoted(s, ' ');
List<String> l = new ArrayList<>(sa.length);
int numOrs = 0;
    s2 = unEscapeChars(s2, new char[]{'"','\''});
    s2 = unEscapeChars(s2, new char[]{'\\'});
origin: org.apache.juneau/juneau-marshall

ObjectList l = (ObjectList)replaceWithMutables(input);
    doSort(l, sort);
  if (! view.isEmpty())
    doView(l, view);
origin: org.apache.juneau/juneau-server

  o = cm.getPojoSwap().swap(o, bc);
PojoQuery f = new PojoQuery(o, bc);
  int pos = req.getQueryParameter("p", Integer.class, 0);
  int limit = req.getQueryParameter("l", Integer.class, 0);
  o = f.filterCollection(query, view, sort, pos, limit, ignoreCase);
  o = f.filterMap(view);
origin: org.apache.juneau/juneau-marshall

  @Override /* Comparator */
  public int compare(Map m1, Map m2) {
    Comparable v1 = toComparable(m1.get(c)), v2 = toComparable(m2.get(c));
    if (v1 == null && v2 == null)
      return 0;
    if (v1 == null)
      return (isDesc ? -1 : 1);
    if (v2 == null)
      return (isDesc ? 1 : -1);
    return (isDesc ? v2.compareTo(v1) : v1.compareTo(v2));
  }
};
origin: apache/juneau

ObjectList l = new DelegateList(session.getClassMetaForObject(o));
for (Object o2 : (Collection)o)
  l.add(replaceWithMutables(o2));
return l;
return replaceWithMutables(Arrays.asList((Object[])o));
origin: org.apache.juneau/juneau-marshall

  l.add(new TimestampRange(op, parseDate(seg, pp)));
  state = 1;
} else if (state == 3) {
  startDate = parseDate(seg, pp);
  seg = seg.substring(pp.getIndex()).trim();
  pp.setIndex(0);
  l.add(new TimestampRange(startDate, parseDate(seg, pp)));
  seg = seg.substring(pp.getIndex()).trim();
  pp.setIndex(0);
origin: apache/juneau

ObjectList l = (ObjectList)replaceWithMutables(input);
    doSort(l, sort);
  if (! view.isEmpty())
    doView(l, view);
origin: org.apache.juneau/juneau-marshall

s = replace(s, '*', '\u9997', true);
s = replace(s, '?', '\u9996', true);
s = unEscapeChars(s, new char[]{'*','?'});
s = s.replace('\u9998', '-');
String[] sa = splitQuoted(s, ' ');
List<String> l = new ArrayList<>(sa.length);
int numOrs = 0;
    s2 = unEscapeChars(s2, new char[]{'"','\''});
    s2 = unEscapeChars(s2, new char[]{'\\'});
origin: apache/juneau

  @Override /* Comparator */
  public int compare(Map m1, Map m2) {
    Comparable v1 = toComparable(m1.get(c)), v2 = toComparable(m2.get(c));
    if (v1 == null && v2 == null)
      return 0;
    if (v1 == null)
      return (isDesc ? -1 : 1);
    if (v2 == null)
      return (isDesc ? 1 : -1);
    return (isDesc ? v2.compareTo(v1) : v1.compareTo(v2));
  }
};
origin: org.apache.juneau/juneau-marshall

ObjectList l = new DelegateList(session.getClassMetaForObject(o));
for (Object o2 : (Collection)o)
  l.add(replaceWithMutables(o2));
return l;
return replaceWithMutables(Arrays.asList((Object[])o));
origin: apache/juneau

  l.add(new TimestampRange(op, parseDate(seg, pp)));
  state = 1;
} else if (state == 3) {
  startDate = parseDate(seg, pp);
  seg = seg.substring(pp.getIndex()).trim();
  pp.setIndex(0);
  l.add(new TimestampRange(startDate, parseDate(seg, pp)));
  seg = seg.substring(pp.getIndex()).trim();
  pp.setIndex(0);
origin: org.apache.juneau/juneau-rest-server

  @Override /* RestConverter */
  public Object convert(RestRequest req, Object o) {
    if (o == null)
      return null;
    SearchArgs searchArgs = req.getQuery().getSearchArgs();
    if (searchArgs == null)
      return o;
    return new PojoQuery(o, req.getBeanSession()).filter(searchArgs);
  }
}
origin: apache/juneau

ObjectList l = (ObjectList)replaceWithMutables(input);
    doSort(l, sort);
  if (! view.isEmpty())
    doView(l, view);
origin: apache/juneau

s = replace(s, '*', '\u9997', true);
s = replace(s, '?', '\u9996', true);
s = unEscapeChars(s, new char[]{'*','?'});
s = s.replace('\u9998', '-');
String[] sa = splitQuoted(s, ' ');
List<String> l = new ArrayList<>(sa.length);
int numOrs = 0;
    s2 = unEscapeChars(s2, new char[]{'"','\''});
    s2 = unEscapeChars(s2, new char[]{'\\'});
origin: apache/juneau

private static void doView(List list, List<String> view) {
  for (ListIterator i = list.listIterator(); i.hasNext();) {
    Object o = i.next();
    Map m = (Map)o;
    doView(m, view);
  }
}
origin: apache/juneau

  @Override /* Comparator */
  public int compare(Map m1, Map m2) {
    Comparable v1 = toComparable(m1.get(c)), v2 = toComparable(m2.get(c));
    if (v1 == null && v2 == null)
      return 0;
    if (v1 == null)
      return (isDesc ? -1 : 1);
    if (v2 == null)
      return (isDesc ? 1 : -1);
    return (isDesc ? v2.compareTo(v1) : v1.compareTo(v2));
  }
};
origin: apache/juneau

/**
 * Parses a timestamp string off the beginning of the string segment 'seg'.
 * Goes through each possible valid timestamp format until it finds a match.
 * The position where the parsing left off is stored in pp.
 *
 * @param seg The string segment being parsed.
 * @param pp Where parsing last left off.
 * @return An object representing a timestamp.
 */
CalendarP parseDate(String seg, ParsePosition pp) {
  CalendarP cal = null;
  for (int i = 0; i < validTimestampFormats.length && cal == null; i++) {
    pp.setIndex(0);
    SimpleDateFormat f = validTimestampFormats[i];
    Date d = f.parse(seg, pp);
    int idx = pp.getIndex();
    if (idx != 0) {
      // it only counts if the next character is '-', 'space', or end-of-string.
      char c = (seg.length() == idx ? 0 : seg.charAt(idx));
      if (c == 0 || c == '-' || Character.isWhitespace(c))
        cal = new CalendarP(d, getPrecisionField(f.toPattern()));
    }
  }
  if (cal == null)
    throw new FormattedRuntimeException("Invalid date encountered:  ''{0}''", seg);
  return cal;
}
org.apache.juneau.utilsPojoQuery

Javadoc

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...

myIntmyStringmyDate
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.

Most used methods

  • <init>
    Constructor.
  • filter
    Filters the input object as a collection of maps.
  • doSort
  • doView
  • getPrecisionField
  • parseDate
    Parses a timestamp string off the beginning of the string segment 'seg'. Goes through each possible
  • replace
    Replaces tokens in a string with a different token. replace("A and B and C", "and", "or") -> "A or B
  • replaceWithMutables
  • splitQuoted
  • toComparable
  • unEscapeChars
    Removes escape characters (specified by escapeChar) from the specified characters.
  • filterCollection
  • unEscapeChars,
  • filterCollection,
  • filterMap

Popular in Java

  • Running tasks concurrently on multiple threads
  • onRequestPermissionsResult (Fragment)
  • requestLocationUpdates (LocationManager)
  • getResourceAsStream (ClassLoader)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now