blob: 46a334be71f628cbbb0123430165922829d0c487 [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
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070019import java.util.Iterator;
20
Madan Jampani5bdebd52016-09-07 16:18:12 -070021import org.onosproject.store.primitives.DocumentTreeNode;
22
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070023/**
Madan Jampani5bdebd52016-09-07 16:18:12 -070024 * A hierarchical <a href="https://en.wikipedia.org/wiki/Document_Object_Model">document tree</a> data structure.
25 *
26 * @param V document tree value type
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070027 */
28public interface DocumentTree<V> {
29
30 /**
Madan Jampani5bdebd52016-09-07 16:18:12 -070031 * Returns the {@link DocumentPath path} to root of the tree.
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070032 *
Madan Jampani5bdebd52016-09-07 16:18:12 -070033 * @return path to root of the tree
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070034 */
35 DocumentPath root();
36
37 /**
Madan Jampani5bdebd52016-09-07 16:18:12 -070038 * Returns an iterator for all the first order descendants of a node.
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070039 *
Madan Jampani5bdebd52016-09-07 16:18:12 -070040 * @param path path to the node
41 * @return an iterator for the child nodes of the specified node path
42 * @throws NoSuchDocumentPathException if the path does not point to a valid node
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070043 */
Madan Jampani5bdebd52016-09-07 16:18:12 -070044 Iterator<DocumentTreeNode<V>> getChildren(DocumentPath path);
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070045
46 /**
Madan Jampani5bdebd52016-09-07 16:18:12 -070047 * Returns a document tree node.
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070048 *
Madan Jampani5bdebd52016-09-07 16:18:12 -070049 * @param path path to node
50 * @return node value or {@code null} if path does not point to a valid node
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070051 */
Madan Jampani5bdebd52016-09-07 16:18:12 -070052 DocumentTreeNode<V> getNode(DocumentPath path);
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070053
54 /**
Madan Jampani5bdebd52016-09-07 16:18:12 -070055 * Creates or updates a document tree node.
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070056 *
Madan Jampani5bdebd52016-09-07 16:18:12 -070057 * @param path path for the node to create or update
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070058 * @param value the non-null value to be associated with the key
Madan Jampani5bdebd52016-09-07 16:18:12 -070059 * @return the previous mapping or {@code null} if there was no previous mapping
60 * @throws NoSuchDocumentPathException if the parent node (for the node to create/update) does not exist
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070061 */
Madan Jampani5bdebd52016-09-07 16:18:12 -070062 V putNode(DocumentPath path, V value);
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070063
64 /**
Madan Jampani5bdebd52016-09-07 16:18:12 -070065 * Creates a document tree node if one does not exist already.
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070066 *
Madan Jampani5bdebd52016-09-07 16:18:12 -070067 * @param path path for the node to create
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070068 * @param value the non-null value to be associated with the key
Madan Jampani5bdebd52016-09-07 16:18:12 -070069 * @return returns {@code true} if the mapping could be added successfully, {@code false} otherwise
70 * @throws NoSuchDocumentPathException if the parent node (for the node to create) does not exist
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070071 */
Madan Jampani5bdebd52016-09-07 16:18:12 -070072 boolean createNode(DocumentPath path, V value);
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070073
74 /**
Madan Jampani5bdebd52016-09-07 16:18:12 -070075 * Removes the node with the specified path.
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070076 *
Madan Jampani5bdebd52016-09-07 16:18:12 -070077 * is not a leaf node i.e has one or more children
Thomas Vachuskaf5e6be42016-09-07 20:58:22 -070078 * @param key path for the node to remove
Madan Jampani5bdebd52016-09-07 16:18:12 -070079 * @return the previous value of the node or {@code null} if it did not exist
80 * @throws IllegalDocumentModificationException if the remove to be removed
Aaron Kruglikovb789b5f2016-08-31 14:47:05 -070081 */
82 V removeNode(DocumentPath key);
83}