2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.northbound.commons.query;
10 import java.util.Collection;
11 import java.util.List;
15 * Represents a parsed query used in filtering of collections.
17 public interface Query<T> {
20 * Find items in the given collection and return them as a new list. The
21 * original collection is not changed.
23 * @param collection to search in.
24 * @return list of items which match the query.
25 * @throws QueryException
27 public List<T> find(Collection<T> collection) throws QueryException;
30 * Apply the query on the given collection. Note that this method will modify
31 * the given object by removing any items which don't match the query criteria.
32 * If the collection is 'singleton' or unmodifiable, invocation will result in
36 * @return the number matched items
37 * @throws QueryException
39 public int filter(Collection<T> collection) throws QueryException;
42 * Search the given root for a child collection and them apply the query on.
43 * Note that this method will modify the given object by removing any items
44 * which don't match the query criteria.
46 * @param root - top level object to search in
47 * @param childType - the child type which represents the collection.
48 * @return the number of matched items
49 * @throws QueryException
51 public int filter(T root, Class<?> childType) throws QueryException;