/** * Returns the first object in the list that matches the expression. * * @since 3.1 */ public <T> T first(List<T> objects) { for (T o : objects) { if (match(o)) { return o; } } return null; }
/** * Adds objects matching this expression from the source collection to the * target collection. * * @since 1.1 */ public <T> Collection<?> filter(Collection<T> source, Collection<T> target) { for (T o : source) { if (match(o)) { target.add(o); } } return target; }
/** * Adds objects matching this expression from the source collection to the target * collection. * * @since 1.1 */ public Collection filter(Collection source, Collection target) { Iterator it = source.iterator(); while (it.hasNext()) { Object o = it.next(); if (match(o)) { target.add(o); } } return target; }
private void encode(Counter c, List<?> objects, int limit, JsonGenerator out) throws IOException { int length = objects.size(); for (; c.position < length && c.encoded < limit; c.position++) { Object o = objects.get(c.position); if (filter == null || filter.match(o)) { if (elementEncoder.encode(null, objects.get(c.position), out)) { c.encoded++; } } } }
private int visit(Counter c, List<?> objects, int limit, EncoderVisitor visitor) { int length = objects.size(); for (; c.position < length && c.encoded < limit; c.position++) { Object o = objects.get(c.position); if (filter == null || filter.match(o)) { int bitmask = elementEncoder.visitEntities(o, visitor); c.encoded++; if ((bitmask & VISIT_SKIP_ALL) != 0) { return VISIT_SKIP_ALL; } } } return VISIT_CONTINUE; }
private void rewind(Counter c, List<?> objects, int limit) { int length = objects.size(); for (; c.position < length && c.rewound < limit; c.position++) { if (shouldFilter) { Object o = objects.get(c.position); if (filter == null || filter.match(o)) { if (elementEncoder.willEncode(null, o)) { c.rewound++; } } } else { c.rewound++; } } }
if (filter != null && !filter.match(o)) { continue;
/** * Returns the deepest possible entity in the inheritance hierarchy that can be used * to create objects from a given DataRow. */ public ObjEntity entityMatchingRow(DataRow row) { // match depth first if (subentities != null) { for (EntityInheritanceTree child : subentities) { ObjEntity matched = child.entityMatchingRow(row); if (matched != null) { return matched; } } } Expression qualifier = getDbQualifier(); if (qualifier != null) { return qualifier.match(row) ? entity : null; } // no qualifier ... matches all rows return entity; }
/** * Returns the deepest possible entity in the inheritance hierarchy * that can be used to create objects from a given DataRow. */ public ObjEntity entityMatchingRow(DataRow row) { // match depth first if (subentities != null) { Iterator it = subentities.iterator(); while (it.hasNext()) { EntityInheritanceTree child = (EntityInheritanceTree) it.next(); ObjEntity matched = child.entityMatchingRow(row); if (matched != null) { return matched; } } } Expression qualifier = entity.getDeclaredQualifier(); if (qualifier != null) { if (normalizedQualifier == null) { normalizedQualifier = entity.translateToDbPath(qualifier); } return normalizedQualifier.match(row) ? entity : null; } // no qualifier ... matches all rows return entity; }
while (it.hasNext()) { T t = it.next(); if (!filter.match(t)) { it.remove();