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 booleanadd(E e)booleanaddAll(Collection<? extends E> c)voidclear()booleanconditionalRemove(E entry, Predicate<E> entryTest)Removes the entry if the supplied predicate evaluates to true.booleancontains(Object o)booleancontainsAll(Collection<?> c)Eget(Object o)Returns set element that is equal to the specified object.booleaninsertOrReplace(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.booleanisEmpty()Iterator<E>iterator()booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)intsize()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:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceSet<E>
-
addAll
public boolean addAll(Collection<? extends E> c)
-
retainAll
public boolean retainAll(Collection<?> c)
-
removeAll
public boolean removeAll(Collection<?> c)
-
-