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>,SequencedCollection<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
ConstructorsConstructorDescriptionConstruct an empty hashed-list.HashedList(int initialCapacity) Construct an empty hashed-list.HashedList(Collection<? extends E> coll) Construct an empty hashed-list from a source collection.HashedList(Collection<? extends E> coll, boolean ignoreBadEntries) Construct an empty hashed-list from a source collection. -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanFast presence check, in O(log N) instead of O(N), the expected time complexity for search in a list.booleancontainsAll(Collection<?> c) Fast presence check, in O(log N) instead of O(N).static <E> HashedList<E> createUnsafe(Collection<? extends E> coll) Fast construction of a HashedList: the source collection is not checked for null or duplicate entries.get(int index) remove(int index) intsize()Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subListMethods inherited from class java.util.AbstractCollection
addAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, addFirst, addLast, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Constructor Details
-
HashedList
public HashedList()Construct an empty hashed-list. -
HashedList
public HashedList(int initialCapacity) Construct an empty hashed-list.- Parameters:
initialCapacity- initial capacity
-
HashedList
Construct an empty hashed-list from a source collection. The constructor will raise if null or duplicate entries are detected.- Parameters:
coll- source collection, which should not contain duplicates or null entries
-
HashedList
Construct an empty hashed-list from a source collection.- Parameters:
coll- source collection, which should not contain duplicates or null entriesignoreBadEntries- skip insertion of a null or a duplicate element
-
-
Method Details
-
createUnsafe
Fast construction of a HashedList: the source collection is not checked for null or duplicate entries. Usage is not recommended.- Type Parameters:
E- element type- Parameters:
coll- source collection, which should not contain duplicates or null entries- Returns:
- created hashed list
-
get
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein 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:
containsin interfaceCollection<E>- Specified by:
containsin interfaceList<E>- Overrides:
containsin classAbstractCollection<E>
-
containsAll
Fast presence check, in O(log N) instead of O(N).- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceList<E>- Overrides:
containsAllin classAbstractCollection<E>
-