blob: aabe7a49f2ecbddb709ce309c41b2215efcb6500 [file] [log] [blame]
Jian Lifc5ca932015-12-10 12:11:57 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Jian Lifc5ca932015-12-10 12:11:57 -08003 *
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 Vachuska4f0252c2020-09-28 11:15:45 -07008 * hcodep://www.apache.org/licenses/LICENSE-2.0
Jian Lifc5ca932015-12-10 12:11:57 -08009 *
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.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 */
27public 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 Vachuska4f0252c2020-09-28 11:15:45 -070032 * <code>e</code> to this set if the set contains no element <code>e2</code>
Jian Lifc5ca932015-12-10 12:11:57 -080033 * such that
Thomas Vachuska4f0252c2020-09-28 11:15:45 -070034 * <code>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</code>.
Jian Lifc5ca932015-12-10 12:11:57 -080035 * If this set already contains the element, the call leaves the set
Thomas Vachuska4f0252c2020-09-28 11:15:45 -070036 * unchanged and returns <code>false</code>. In combination with the
Jian Lifc5ca932015-12-10 12:11:57 -080037 * restriction on constructors, this ensures that sets never contain
38 * duplicate elements.
39 *
40 * @param e element to be added to this set
Thomas Vachuska4f0252c2020-09-28 11:15:45 -070041 * @return <code>true</code> if this set did not already contain the specified
Jian Lifc5ca932015-12-10 12:11:57 -080042 * element
43 */
44 boolean add(E e);
45
46 /**
47 * Removes the specified element from this set if it is present
Thomas Vachuska4f0252c2020-09-28 11:15:45 -070048 * (optional operation). More formally, removes an element <code>e</code>
Jian Lifc5ca932015-12-10 12:11:57 -080049 * such that
Thomas Vachuska4f0252c2020-09-28 11:15:45 -070050 * <code>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</code>, if
51 * this set contains such an element. Returns <code>true</code> if this set
Jian Lifc5ca932015-12-10 12:11:57 -080052 * 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 Vachuska4f0252c2020-09-28 11:15:45 -070057 * @return <code>true</code> if this set contained the specified element
Jian Lifc5ca932015-12-10 12:11:57 -080058 */
59 boolean remove(E e);
60
61 /**
Thomas Vachuska4f0252c2020-09-28 11:15:45 -070062 * 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&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</code>.
Jian Lifc5ca932015-12-10 12:11:57 -080066 *
67 * @param e element whose presence in this set is to be tested
Thomas Vachuska4f0252c2020-09-28 11:15:45 -070068 * @return <code>true</code> if this set contains the specified element
Jian Lifc5ca932015-12-10 12:11:57 -080069 * @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}