Jian Li | fc5ca93 | 2015-12-10 12:11:57 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Jian Li | fc5ca93 | 2015-12-10 12:11:57 -0800 | [diff] [blame] | 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 | * |
Thomas Vachuska | 4f0252c | 2020-09-28 11:15:45 -0700 | [diff] [blame] | 8 | * hcodep://www.apache.org/licenses/LICENSE-2.0 |
Jian Li | fc5ca93 | 2015-12-10 12:11:57 -0800 | [diff] [blame] | 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 | package org.onosproject.store.service; |
| 17 | |
| 18 | /** |
| 19 | * Transactional Set data structure. |
| 20 | * <p> |
| 21 | * A TransactionalSet is implemented with the help of TransactionalMap data structure. |
| 22 | * All operations performed on this set within a transaction boundary are invisible externally |
| 23 | * until the point when the transaction commits. A commit usually succeeds in the absence of conflicts. |
| 24 | * |
| 25 | * @param <E> type of element. |
| 26 | */ |
| 27 | public interface TransactionalSet<E> { |
| 28 | |
| 29 | /** |
| 30 | * Adds the specified element to this set if it is not already present |
| 31 | * (optional operation). More formally, adds the specified element |
Thomas Vachuska | 4f0252c | 2020-09-28 11:15:45 -0700 | [diff] [blame] | 32 | * <code>e</code> to this set if the set contains no element <code>e2</code> |
Jian Li | fc5ca93 | 2015-12-10 12:11:57 -0800 | [diff] [blame] | 33 | * such that |
Thomas Vachuska | 4f0252c | 2020-09-28 11:15:45 -0700 | [diff] [blame] | 34 | * <code>(e==null ? e2==null : e.equals(e2))</code>. |
Jian Li | fc5ca93 | 2015-12-10 12:11:57 -0800 | [diff] [blame] | 35 | * If this set already contains the element, the call leaves the set |
Thomas Vachuska | 4f0252c | 2020-09-28 11:15:45 -0700 | [diff] [blame] | 36 | * unchanged and returns <code>false</code>. In combination with the |
Jian Li | fc5ca93 | 2015-12-10 12:11:57 -0800 | [diff] [blame] | 37 | * restriction on constructors, this ensures that sets never contain |
| 38 | * duplicate elements. |
| 39 | * |
| 40 | * @param e element to be added to this set |
Thomas Vachuska | 4f0252c | 2020-09-28 11:15:45 -0700 | [diff] [blame] | 41 | * @return <code>true</code> if this set did not already contain the specified |
Jian Li | fc5ca93 | 2015-12-10 12:11:57 -0800 | [diff] [blame] | 42 | * element |
| 43 | */ |
| 44 | boolean add(E e); |
| 45 | |
| 46 | /** |
| 47 | * Removes the specified element from this set if it is present |
Thomas Vachuska | 4f0252c | 2020-09-28 11:15:45 -0700 | [diff] [blame] | 48 | * (optional operation). More formally, removes an element <code>e</code> |
Jian Li | fc5ca93 | 2015-12-10 12:11:57 -0800 | [diff] [blame] | 49 | * such that |
Thomas Vachuska | 4f0252c | 2020-09-28 11:15:45 -0700 | [diff] [blame] | 50 | * <code>(o==null ? e==null : o.equals(e))</code>, if |
| 51 | * this set contains such an element. Returns <code>true</code> if this set |
Jian Li | fc5ca93 | 2015-12-10 12:11:57 -0800 | [diff] [blame] | 52 | * contained the element (or equivalently, if this set changed as a |
| 53 | * result of the call). (This set will not contain the element once the |
| 54 | * call returns.) |
| 55 | * |
| 56 | * @param e element to be removed to this set |
Thomas Vachuska | 4f0252c | 2020-09-28 11:15:45 -0700 | [diff] [blame] | 57 | * @return <code>true</code> if this set contained the specified element |
Jian Li | fc5ca93 | 2015-12-10 12:11:57 -0800 | [diff] [blame] | 58 | */ |
| 59 | boolean remove(E e); |
| 60 | |
| 61 | /** |
Thomas Vachuska | 4f0252c | 2020-09-28 11:15:45 -0700 | [diff] [blame] | 62 | * Returns <code>true</code> if this set contains the specified element. |
| 63 | * More formally, returns <code>true</code> if and only if this set |
| 64 | * contains an element <code>e</code> such that |
| 65 | * <code>(o==null ? e==null : o.equals(e))</code>. |
Jian Li | fc5ca93 | 2015-12-10 12:11:57 -0800 | [diff] [blame] | 66 | * |
| 67 | * @param e element whose presence in this set is to be tested |
Thomas Vachuska | 4f0252c | 2020-09-28 11:15:45 -0700 | [diff] [blame] | 68 | * @return <code>true</code> if this set contains the specified element |
Jian Li | fc5ca93 | 2015-12-10 12:11:57 -0800 | [diff] [blame] | 69 | * @throws ClassCastException if the type of the specified element |
| 70 | * is incompatible with this set |
| 71 | * @throws NullPointerException if the specified element is null and this |
| 72 | * set does not permit null elements |
| 73 | */ |
| 74 | boolean contains(E e); |
| 75 | } |