Class HashSet<T>
java.lang.Object
org.javimmutable.collections.common.AbstractSet<T>
org.javimmutable.collections.hash.HashSet<T>
- All Implemented Interfaces:
Serializable
,Iterable<T>
,ArrayAssignMapper<T,
,T, ArraySetNode<T>> ArrayContainsMapper<T,
,ArraySetNode<T>> ArrayDeleteMapper<T,
,ArraySetNode<T>> ArrayIterationMapper<T,
,T, ArraySetNode<T>> ArraySizeMapper<ArraySetNode<T>>
,ICollection<T>
,InvariantCheckable
,ISet<T>
,IStreamable<T>
,Mapped<T,
,T> SplitableIterable<T>
@Immutable
public class HashSet<T>
extends AbstractSet<T>
implements ArrayAssignMapper<T,T,ArraySetNode<T>>, ArrayContainsMapper<T,ArraySetNode<T>>, ArrayIterationMapper<T,T,ArraySetNode<T>>, ArrayDeleteMapper<T,ArraySetNode<T>>, Serializable
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ISetBuilder
<T> builder()
void
Checks invariants of implementing class.boolean
Determines if the Set contains the specified value.Removes the value from the Set.Removes all values of other from the Set.Implemented by derived classes to create a new empty Setvoid
<E extends Exception>
voidforEachThrows
(Proc1Throws<T, E> proc) Processes every value using the provided function.int
Adds the single value to the Set.intersection
(Iterator<? extends T> values) Removes all values from the Set that are not contained in the other collection.intersection
(Set<? extends T> otherSet) Removes all values from the Set that are not contained in the other collection.boolean
isEmpty()
iterator()
Overridden here to require implementations to return a SplitableIterator rather than a basic Iterator.mappedAssign
(ArraySetNode<T> current, T key, T ignored) Called during assign operation to replace an existing mapping for the given key and value.mappedAssign
(T key, T ignored) Called during assign operation to create a new mapping for the given key and value.boolean
mappedContains
(ArraySetNode<T> mapping, T key) mappedDelete
(ArraySetNode<T> current, T key) Called during delete operation to delete a key from a mapping.mappedEntries
(ArraySetNode<T> mapping) mappedKeys
(ArraySetNode<T> mapping) int
mappedSize
(ArraySetNode<T> mapping) Called to obtain number of keys in a given mapping.mappedValues
(ArraySetNode<T> mapping) static <T> ISet
<T> of()
int
size()
Adds all values from other to the Set.Methods inherited from class org.javimmutable.collections.common.AbstractSet
containsAll, containsAll, containsAny, containsAny, deleteAll, equals, getSet, hashCode, insertAll, insertAll, intersection, intersection, toString, union
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.javimmutable.collections.ICollection
isNonEmpty
Methods inherited from interface org.javimmutable.collections.ISet
find, get, getValueOr, reject, select, setCollector
Methods inherited from interface org.javimmutable.collections.IStreamable
parallelStream, spliterator, stream
Methods inherited from interface org.javimmutable.collections.SplitableIterable
indexedForEach, indexedForEachThrows, reduce, reduceThrows
-
Method Details
-
of
-
builder
-
deleteAll
-
emptyMutableSet
Description copied from class:AbstractSet
Implemented by derived classes to create a new empty Set- Specified by:
emptyMutableSet
in classAbstractSet<T>
-
insert
Description copied from interface:ISet
Adds the single value to the Set. -
contains
Description copied from interface:ISet
Determines if the Set contains the specified value. -
delete
Description copied from interface:ISet
Removes the value from the Set. Has no effect if the value is not in the Set. -
deleteAll
Description copied from interface:ISet
Removes all values of other from the Set. Has no effect if none of the values are in the Set -
union
Description copied from interface:ISet
Adds all values from other to the Set. -
intersection
Description copied from interface:ISet
Removes all values from the Set that are not contained in the other collection.- Specified by:
intersection
in interfaceISet<T>
- Returns:
- instance of set with unmatched values removed
-
intersection
Description copied from interface:ISet
Removes all values from the Set that are not contained in the other collection.- Specified by:
intersection
in interfaceISet<T>
- Returns:
- instance of set with unmatched values removed
-
size
public int size()- Specified by:
size
in interfaceICollection<T>
- Returns:
- number of values in the collection
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceICollection<T>
- Returns:
- true only if collection contains no values
-
checkInvariants
public void checkInvariants()Description copied from interface:InvariantCheckable
Checks invariants of implementing class.- Specified by:
checkInvariants
in interfaceInvariantCheckable
-
forEach
-
forEachThrows
Description copied from interface:SplitableIterable
Processes every value using the provided function.- Specified by:
forEachThrows
in interfaceSplitableIterable<T>
- Throws:
E
-
iterator
Description copied from interface:IStreamable
Overridden here to require implementations to return a SplitableIterator rather than a basic Iterator. This is necessary to allow composition of new objects from methods like keys() and values().- Specified by:
iterator
in interfaceIStreamable<T>
- Specified by:
iterator
in interfaceIterable<T>
- Specified by:
iterator
in interfaceSplitableIterable<T>
-
getSpliteratorCharacteristics
public int getSpliteratorCharacteristics()- Specified by:
getSpliteratorCharacteristics
in interfaceIStreamable<T>
- Returns:
- characteristics value used when creating Spliterators
-
mappedContains
- Specified by:
mappedContains
in interfaceArrayContainsMapper<T,
ArraySetNode<T>>
-
mappedAssign
Description copied from interface:ArrayAssignMapper
Called during assign operation to create a new mapping for the given key and value.- Specified by:
mappedAssign
in interfaceArrayAssignMapper<T,
T, ArraySetNode<T>> - Parameters:
key
- key being assigned toignored
- value being assigned- Returns:
- non-null mapping
-
mappedAssign
@Nonnull public ArraySetNode<T> mappedAssign(@Nonnull ArraySetNode<T> current, @Nonnull T key, T ignored) Description copied from interface:ArrayAssignMapper
Called during assign operation to replace an existing mapping for the given key and value.- Specified by:
mappedAssign
in interfaceArrayAssignMapper<T,
T, ArraySetNode<T>> - Parameters:
current
- mapping to be replacedkey
- key being assigned toignored
- value being assigned- Returns:
- same to keep mapping or non-null to replace mapping
-
mappedDelete
Description copied from interface:ArrayDeleteMapper
Called during delete operation to delete a key from a mapping.- Specified by:
mappedDelete
in interfaceArrayDeleteMapper<T,
ArraySetNode<T>> - Parameters:
current
- mapping to be replacedkey
- key being deleted- Returns:
- null to remove mapping, same to keep mapping, or non-null to replace mapping
-
mappedSize
Description copied from interface:ArraySizeMapper
Called to obtain number of keys in a given mapping.- Specified by:
mappedSize
in interfaceArraySizeMapper<T>
- Parameters:
mapping
- mapping to be sized- Returns:
- number of keys in the mapping
-
mappedKeys
- Specified by:
mappedKeys
in interfaceArrayIterationMapper<T,
T, ArraySetNode<T>>
-
mappedValues
- Specified by:
mappedValues
in interfaceArrayIterationMapper<T,
T, ArraySetNode<T>>
-
mappedEntries
@Nonnull public GenericIterator.Iterable<IMapEntry<T,T>> mappedEntries(@Nonnull ArraySetNode<T> mapping) - Specified by:
mappedEntries
in interfaceArrayIterationMapper<T,
T, ArraySetNode<T>>
-