blob: 5156c068519e13712f6cc24a19466f42b7804f7e [file] [log] [blame]
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -07001/*
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 */
16
17package org.onosproject.store.service;
18
19import org.onosproject.store.primitives.DocumentTreeNode;
20
21import java.util.Iterator;
22
23/**
24 * Interface for a tree with structure wherein keys hold information
25 * about the hierarchical structure of the tree (name of parent,
26 * grandparent etc.).
27 */
28public interface DocumentTree<V> {
29
30 /**
31 * Returns the root of the tree. This will be the first part of any fully
32 * qualified path and will enable discovery of the entire tree.
33 *
34 * @return a string that is the name of the root of the tree.
35 */
36 DocumentPath root();
37
38 /**
39 * Returns a sorted list containing all key value pairs that are direct
40 * descendants of the supplied parent. The returned list will be immutable.
41 * If the specified parent does not exist this method will fail with an
42 * exception.
43 *
44 * @throws NoSuchDocumentPathException if the parent does not exist
45 * @param parentPath the path to the parent of the desired nodes
46 * @return an iterator of the children of the specified parent
47 */
48 Iterator<DocumentTreeNode<V>> getChildren(DocumentPath parentPath);
49
50 /**
51 * Returns the value associated with the supplied key or null if no such
52 * node exists.
53 *
54 * @param key the key to query
55 * @return a value or null
56 */
57 DocumentTreeNode<V> getNode(DocumentPath key);
58
59 /**
60 * Takes a string that specifies the complete path to the mapping to be
61 * added or updated and creates the key value mapping or updates the value.
62 * If the specified parent cannot be found the operation fails with an
63 * error.
64 *
65 * @throws NoSuchDocumentPathException if the specified parent does not
66 * exist.
67 * @param key the fully qualified key of the entry to be added or updated
68 * @param value the non-null value to be associated with the key
69 * @return the previous mapping or null if there was no previous mapping
70 */
71 V putNode(DocumentPath key, V value);
72
73 /**
74 * Takes the fully qualified name of the node to be added along with
75 * the value to be added. If the specified key already exists it doesnot
76 * update anything & returns false. If the parent does not exist the
77 * operation fails with an exception.
78 *
79 * @throws NoSuchDocumentPathException if the specified parent does not
80 * exist.
81 * @param key the fully qualified key of the entry to be added or updated
82 * @param value the non-null value to be associated with the key
83 * @return returns true if the mapping could be added successfully
84 */
85 boolean createNode(DocumentPath key, V value);
86
87 /**
88 * Removes the node with the specified fully qualified key. Returns null if
89 * the node did not exist. This method will throw an exception if called on
90 * a non-leaf node.
91 *
92 * @throws IllegalDocumentModificationException if the node had children.
93 * @param key the fully qualified key of the node to be removed
94 * @return the previous value of the node or null if it did not exist
95 */
96 V removeNode(DocumentPath key);
97}