Class VisitOnceWorkingSet<E>
- java.lang.Object
-
- it.unive.lisa.util.collections.workset.VisitOnceWorkingSet<E>
-
- Type Parameters:
E- the type of the elements that this working set contains
- All Implemented Interfaces:
WorkingSet<E>
public final class VisitOnceWorkingSet<E> extends java.lang.Object implements WorkingSet<E>
A working set that guarantees that each element will be added to this working set no more than once. It works by wrapping a difference instance ofWorkingSet, and delegating all operations to that instance, except forpush(Object): an element will be pushed only if it has not already added before (even if it is has already been popped out). This implementation is not thread-safe.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)java.util.Collection<E>getSeen()Yields the elements visited (and this no longer able to be added to this working set) by this object.inthashCode()booleanisEmpty()Yieldstrueif and only if this working set is empty.static <E> VisitOnceWorkingSet<E>mk(WorkingSet<E> ws)Yields a new, empty working set.Epeek()Returns the next element to be processed from this working set without removing it.Epop()Removes the next element to be processed from this working set and returns it.voidpush(E e)Pushes a new element into this working set.intsize()Yields the size of this working set, that is, the number of elements contained in it.java.lang.StringtoString()
-
-
-
Method Detail
-
mk
public static <E> VisitOnceWorkingSet<E> mk(WorkingSet<E> ws)
Yields a new, empty working set.- Type Parameters:
E- the type of the elements that the returned working set contains- Parameters:
ws- the underlying working set- Returns:
- the new working set
-
push
public void push(E e)
Description copied from interface:WorkingSetPushes a new element into this working set.- Specified by:
pushin interfaceWorkingSet<E>- Parameters:
e- the element
-
pop
public E pop()
Description copied from interface:WorkingSetRemoves the next element to be processed from this working set and returns it.- Specified by:
popin interfaceWorkingSet<E>- Returns:
- the next element to process
-
peek
public E peek()
Description copied from interface:WorkingSetReturns the next element to be processed from this working set without removing it.- Specified by:
peekin interfaceWorkingSet<E>- Returns:
- the next element to process
-
size
public int size()
Description copied from interface:WorkingSetYields the size of this working set, that is, the number of elements contained in it.- Specified by:
sizein interfaceWorkingSet<E>- Returns:
- the size
-
isEmpty
public boolean isEmpty()
Description copied from interface:WorkingSetYieldstrueif and only if this working set is empty.- Specified by:
isEmptyin interfaceWorkingSet<E>- Returns:
trueif that condition holds
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getSeen
public java.util.Collection<E> getSeen()
Yields the elements visited (and this no longer able to be added to this working set) by this object.- Returns:
- the collection of visited elements
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-