Package com.pnfsoftware.jeb.util.collect
Class HashedList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
com.pnfsoftware.jeb.util.collect.HashedList<E>
- Type Parameters:
E
- list's object type
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,List<E>
A List type suitable for long lists of unique items for which
presence
checks
are often required. For typical list implementations, contains(Object)
is in
O(N) and therefore slow for long lists.
Limitations: Neither duplicate (per equals
) nor null entries are allowed. Methods throw
NullPointerException
on attempts to insert null entries, and
IllegalArgumentException
on attempts to insert duplicates.
This class is not thread-safe. This class is serializable.
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
Fast presence check, in O(log N) instead of O(N), the expected time complexity for search in a list.boolean
containsAll
(Collection<?> c) Fast presence check, in O(log N) instead of O(N).get
(int index) remove
(int index) int
size()
Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
Methods inherited from class java.util.AbstractCollection
addAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Constructor Details
-
HashedList
public HashedList() -
HashedList
public HashedList(int initialCapacity) -
HashedList
- Parameters:
c
- source collection, which should not contain duplicates or null entries
-
-
Method Details
-
get
-
size
public int size()- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceList<E>
- Specified by:
size
in classAbstractCollection<E>
-
set
-
add
-
remove
-
contains
Fast presence check, in O(log N) instead of O(N), the expected time complexity for search in a list.- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceList<E>
- Overrides:
contains
in classAbstractCollection<E>
-
containsAll
Fast presence check, in O(log N) instead of O(N).- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceList<E>
- Overrides:
containsAll
in classAbstractCollection<E>
-