@Override public List<T> find(Collection<T> collection) throws QueryException { // new arraylist for result List<T> result = new ArrayList<T>(); for (T item : collection) { if (match(item, rootType)) { result.add(item); } } return result; }
@Override public <T> Query<T> createQuery(String queryString, Class<T> type) throws QueryException { if (queryString == null || queryString.trim().length() == 0) { return null; } try { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Processing query: {}", queryString); } // FiqlParser is a parser generated by javacc Expression expression = FiqlParser.parse(queryString); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Query expression: {}", expression); } // create Query and return; return new QueryImpl<T>(type, expression); } catch (Exception ex) { if (LOGGER.isDebugEnabled()) { LOGGER.error("Query processing failed = {}", queryString, ex); } throw new QueryException("Unable to parse query.", ex); } } }
@Override public int filter(Collection<T> collection) throws QueryException { // find items List<T> matched = new ArrayList<T>(); for (T item : collection) { if (match(item, rootType)) { matched.add(item); } } collection.clear(); collection.addAll(matched); return matched.size(); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public int filter(T rootObject, Class<?> childClass) throws QueryException { // retrieve underlying collection TypeInfo childType = rootType.getCollectionChild(childClass); if (childType == null || !(childType instanceof IteratableTypeInfo)) { return 0; } Collection collection = (Collection) childType.getAccessor().getValue(rootObject); // get the child type of the collection type TypeInfo ti = childType.getCollectionChild(childClass); List matched = new ArrayList(); for (Object item : collection) { if (match(item, ti)) { matched.add(item); } } collection.clear(); collection.addAll(matched); return matched.size(); }