Package org.onlab.util
Class ExtendedSet<E>
- java.lang.Object
-
- org.onlab.util.ExtendedSet<E>
-
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Set<E>
public class ExtendedSet<E> extends Object implements Set<E>
A Set providing additional get, insertOrReplace and conditionalRemove methods.
-
-
Constructor Summary
Constructors Constructor Description ExtendedSet(Map<E,E> map)
Constructs a new instance by backing it with the supplied Map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E e)
boolean
addAll(Collection<? extends E> c)
void
clear()
boolean
conditionalRemove(E entry, Predicate<E> entryTest)
Removes the entry if the supplied predicate evaluates to true.boolean
contains(Object o)
boolean
containsAll(Collection<?> c)
E
get(Object o)
Returns set element that is equal to the specified object.boolean
insertOrReplace(E entry, Predicate<E> entryTest)
Inserts the entry if it is not already in the set otherwise replaces the existing entry if the supplied predicate evaluates to true.boolean
isEmpty()
Iterator<E>
iterator()
boolean
remove(Object o)
boolean
removeAll(Collection<?> c)
boolean
retainAll(Collection<?> c)
int
size()
Object[]
toArray()
<T> T[]
toArray(T[] a)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
equals, hashCode, spliterator
-
-
-
-
Method Detail
-
get
public E get(Object o)
Returns set element that is equal to the specified object.- Parameters:
o
- object- Returns:
- set element that is equal to the input argument or null if no such set element exists
-
insertOrReplace
public boolean insertOrReplace(E entry, Predicate<E> entryTest)
Inserts the entry if it is not already in the set otherwise replaces the existing entry if the supplied predicate evaluates to true.- Parameters:
entry
- entry to addentryTest
- predicate that is used to evaluate if the existing entry should be replaced- Returns:
- true if the set is updated; false otherwise
-
conditionalRemove
public boolean conditionalRemove(E entry, Predicate<E> entryTest)
Removes the entry if the supplied predicate evaluates to true.- Parameters:
entry
- entry to removeentryTest
- predicate that is used to evaluated aginst the existing entry. Return value of true implies value should be removed.- Returns:
- true if the set is updated; false otherwise
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
contains
public boolean contains(Object o)
-
toArray
public Object[] toArray()
-
toArray
public <T> T[] toArray(T[] a)
-
add
public boolean add(E e)
-
remove
public boolean remove(Object o)
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceSet<E>
-
addAll
public boolean addAll(Collection<? extends E> c)
-
retainAll
public boolean retainAll(Collection<?> c)
-
removeAll
public boolean removeAll(Collection<?> c)
-
-