blob: 377a14871db3c3e3ed41246072de63e025bafcf1 [file] [log] [blame]
Sithara Punnasseryff114552017-01-10 11:40:55 -08001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.config;
17
18
19import org.onosproject.config.model.ResourceIdentifier;
20
21import java.util.Set;
22
23/**
24 * Abstraction for Filters that can be used while traversing the dynamic config store.
25 * This abstraction allows to select entries of interest based on various criteria
26 * defined by this interface.
27 * NOTE: Only criteria based on {@code ResourceIdentifier} are supported currently.
28 * This is a placeholder for a filter; Set of ResourceIdentifier becomes inefficient when
29 * using a large number of filtering criteria;
30 */
31public interface Filter {
32 enum TraversalMode {
33 /**
34 * Traversal types.
35 */
36 SUB_TREE(-1),
37 NODE_ONLY(0),
38 GIVEN_DEPTH;
39
40 /**
41 * variable indicating the depth of traversal.
42 * depth = -1 => if the node is pointing to a subtree, the entire subtree will be traversed;
43 * if the node points to a leaf, just the leaf will be retrieved.
44 * depth = 0 => tree will not be traversed; will retrieve just the specific node,
45 * irrespective of it being a subtree root or a leaf node
46 * depth = any other integer => that many levels of the subtree will be traversed;
47 * if depth > the number of levels of children, the entire subtree will
48 * be traversed and end the traversal, without throwing any errors.
49 */
50 int depth;
51
52 TraversalMode() {
53
54 }
55
56 TraversalMode(int depth) {
57 this.depth = depth;
58 }
59
60 int depth() {
61 return depth;
62 }
63 }
64
65 /**
66 * Adds the traversal depth to the Filter object.
67 * Various interpretations of depth are as mentioned.
68 * Default traversal mode is to read just the given node(NODE_ONLY).
69 *
70 * @param depth new criteria
71 */
72 void addDepth(TraversalMode depth);
73
74 /**
75 * Adds new ResourceIdentifier filtering criteria to a Filter object.
76 * If the same ResourceIdentifier is already part of the criteria
77 * for the object, it will not be added again, but will not throw any exceptions.
78 * This will not check for the validity of the ResourceIdentifier.
79 *
80 * @param add new criteria
81 */
82 void addCriteria(Set<ResourceIdentifier> add);
83
84 /**
85 * Removes the given ResourceIdentifier filtering criteria from a Filter object.
86 * If the ResourceIdentifier was NOT already part of the criteria for
87 * the object, it will not be removed, but will not throw any exceptions.
88 * This will not check for the validity of the ResourceIdentifier.
89 *
90 * @param remove criteria to be removed
91 */
92 void removeCriteria(Set<ResourceIdentifier> remove);
93
94 /**
95 * Method to list all the ResourceIdentifier criteria that are in place for a Filter.
96 *
97 * @return Set of ResourceIdentifier criteria for this entity
98 */
99 Set<ResourceIdentifier> getCriteria();
100
101 /**
102 * Method to create a filter that include all entries rejected by the criteria.
103 *
104 * @param original filter object with a criteria set
105 * @return Filter object with negated criteria set
106 * @throws InvalidFilterException if the received Filter object
107 * was null or if it had an empty criteria set
108 */
109 Filter negateFilter(Filter original);
110
111 /**
112 * Method to check if the Filter has an empty criteria set.
113 *
114 * @return {@code true} if criteria set is empty, {@code true} otherwise.
115 */
116 boolean isEmptyFilter();
117}