Package com.day.util
Class OrderedSet
- java.lang.Object
-
- com.day.util.OrderedSet
-
- All Implemented Interfaces:
Iterable
,Collection
,Set
public class OrderedSet extends Object implements Set
Helper class that implements a set, but preserves the order of inserting the elements when accessing an iterator.- Since:
- coati, moved to com.day.util for iguana Audience core
-
-
Constructor Summary
Constructors Constructor Description OrderedSet()
Constructs a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75).OrderedSet(int initialCapacity)
Constructs a new, empty set; the backing Set instance has the specified initial capacity and default load factor, which is 0.75.OrderedSet(int initialCapacity, float loadFactor)
Constructs a new, empty set; the backing Set instance has the specified initial capacity and the specified load factor.OrderedSet(Collection c)
Constructs a new set containing the elements in the specified collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(Object o)
boolean
addAll(Collection c)
void
clear()
boolean
contains(Object o)
boolean
containsAll(Collection c)
boolean
isEmpty()
Iterator
iterator()
boolean
remove(Object o)
boolean
removeAll(Collection c)
boolean
retainAll(Collection c)
int
size()
Object[]
toArray()
Object[]
toArray(Object[] a)
-
Methods inherited from class java.lang.Object
equals, 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
-
-
-
-
Constructor Detail
-
OrderedSet
public OrderedSet()
Constructs a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75).
-
OrderedSet
public OrderedSet(Collection c)
Constructs a new set containing the elements in the specified collection. The Set is created with default load factor (0.75) and an initial capacity sufficient to contain the elements in the specified collection.- Parameters:
c
- the collection whose elements are to be placed into this set.- Throws:
NullPointerException
- if the specified collection is null.
-
OrderedSet
public OrderedSet(int initialCapacity, float loadFactor)
Constructs a new, empty set; the backing Set instance has the specified initial capacity and the specified load factor.- Parameters:
initialCapacity
- the initial capacity of the hash map.loadFactor
- the load factor of the hash map.- Throws:
IllegalArgumentException
- if the initial capacity is less than zero, or if the load factor is nonpositive.
-
OrderedSet
public OrderedSet(int initialCapacity)
Constructs a new, empty set; the backing Set instance has the specified initial capacity and default load factor, which is 0.75.- Parameters:
initialCapacity
- the initial capacity of the hash table.- Throws:
IllegalArgumentException
- if the initial capacity is less than zero.
-
-
Method Detail
-
size
public int size()
- Specified by:
size
in interfaceCollection
- Specified by:
size
in interfaceSet
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection
- Specified by:
isEmpty
in interfaceSet
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection
- Specified by:
contains
in interfaceSet
-
iterator
public Iterator iterator()
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection
- Specified by:
toArray
in interfaceSet
-
toArray
public Object[] toArray(Object[] a)
- Specified by:
toArray
in interfaceCollection
- Specified by:
toArray
in interfaceSet
-
add
public boolean add(Object o)
- Specified by:
add
in interfaceCollection
- Specified by:
add
in interfaceSet
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceCollection
- Specified by:
remove
in interfaceSet
-
containsAll
public boolean containsAll(Collection c)
- Specified by:
containsAll
in interfaceCollection
- Specified by:
containsAll
in interfaceSet
-
addAll
public boolean addAll(Collection c)
- Specified by:
addAll
in interfaceCollection
- Specified by:
addAll
in interfaceSet
-
retainAll
public boolean retainAll(Collection c)
- Specified by:
retainAll
in interfaceCollection
- Specified by:
retainAll
in interfaceSet
-
removeAll
public boolean removeAll(Collection c)
- Specified by:
removeAll
in interfaceCollection
- Specified by:
removeAll
in interfaceSet
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection
- Specified by:
clear
in interfaceSet
-
-