- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- com.aoapps.collections.UnmodifiableArraySet<E>
-
- All Implemented Interfaces:
Externalizable,Serializable,Iterable<E>,Collection<E>,Set<E>
public class UnmodifiableArraySet<E> extends AbstractSet<E> implements Externalizable
An unmodifiable compact
Setimplementation that stores the elements in hashCode order. The emphasis is to use as little heap space as possible - this is not a general-purposeSetimplementation.This set does not support null values.
This set will generally operate at O(log n) due to binary search. In general, it will not be as fast as the O(1) behavior of HashSet. Here we give up speed to save space.
This set is not thread safe.
- Author:
- AO Industries, Inc.
- See Also:
to properly sort objects before adding to the set, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description UnmodifiableArraySet()UnmodifiableArraySet(E... elements)Uses the provided elements, which must already be sorted in hashCode order and unique.UnmodifiableArraySet(Collection<E> elements)Uses the provided elements collection, which must already be sorted in hashCode order and unique.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E e)booleanaddAll(Collection<? extends E> c)voidclear()booleancontains(Object o)booleancontainsAll(Collection<?> c)booleanisEmpty()Iterator<E>iterator()voidreadExternal(ObjectInput in)booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)intsize()Object[]toArray()<T> T[]toArray(T[] a)voidwriteExternal(ObjectOutput out)-
Methods inherited from class java.util.AbstractSet
equals, hashCode
-
Methods inherited from class java.util.AbstractCollection
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
-
Methods inherited from interface java.util.Set
spliterator
-
-
-
-
Constructor Detail
-
UnmodifiableArraySet
@SafeVarargs public UnmodifiableArraySet(E... elements)
Uses the provided elements, which must already be sorted in hashCode order and unique. The sort order and uniqueness is only checked with assertions enabled.
-
UnmodifiableArraySet
public UnmodifiableArraySet(Collection<E> elements)
Uses the provided elements collection, which must already be sorted in hashCode order and unique. A defensive copy is made. The sort order and uniqueness is only checked with assertions enabled.
-
UnmodifiableArraySet
public UnmodifiableArraySet()
-
-
Method Detail
-
size
public int size()
- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Overrides:
toArrayin classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Overrides:
toArrayin classAbstractCollection<E>
-
add
public boolean add(E e)
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceSet<E>- Overrides:
containsAllin classAbstractCollection<E>
-
addAll
public boolean addAll(Collection<? extends E> c)
- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceSet<E>- Overrides:
addAllin classAbstractCollection<E>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceSet<E>- Overrides:
retainAllin classAbstractCollection<E>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceSet<E>- Overrides:
removeAllin classAbstractSet<E>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
-