Package org.leplus.ristretto.util
Class IdentityHashSet<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- org.leplus.ristretto.util.IdentityHashSet<E>
-
- Type Parameters:
E
- the type of the elements of the set.
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<E>
,Collection<E>
,Set<E>
public class IdentityHashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, Serializable
ThisSet
relies on identity (==) to compare the objects it contains. It does not matter what the objectsObject.equals(java.lang.Object)
methods say.This collection is Cloneable and Serializable. If you clone an instance of an IdentityHashSet, the clone is equal to the original instance (i.e. original.equals(clone) == true and clone.equals(original) == true). However this is not true for serialization, a deserialized instance of IdentityHashSet is not equal to the instance originally serialized (i.e. original.equals(deserialized) == false and deserialized.equals(original) == false).
- Since:
- 1.0.0
- Author:
- Thomas Leplus
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description IdentityHashSet()
Constructs a new, empty identity hash set with a default expected maximum size (21).IdentityHashSet(int expectedMaxSize)
Constructs a new, empty set with the specified expected maximum size.IdentityHashSet(Collection<? extends E> c)
Constructs a new identity hash set containing the objects of the provided collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E e)
void
clear()
Object
clone()
boolean
contains(Object o)
boolean
equals(Object obj)
int
hashCode()
boolean
isEmpty()
Iterator<E>
iterator()
boolean
remove(Object o)
int
size()
-
Methods inherited from class java.util.AbstractSet
removeAll
-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toString
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
addAll, containsAll, removeAll, retainAll, spliterator, toArray, toArray
-
-
-
-
Constructor Detail
-
IdentityHashSet
public IdentityHashSet()
Constructs a new, empty identity hash set with a default expected maximum size (21).
-
IdentityHashSet
public IdentityHashSet(Collection<? extends E> c)
Constructs a new identity hash set containing the objects of the provided collection.- Parameters:
c
- a collection of objects to put in this identity hash set.
-
IdentityHashSet
public IdentityHashSet(int expectedMaxSize)
Constructs a new, empty set with the specified expected maximum size. Putting more than the expected number of objects into the set may cause the internal data structure to grow, which may be somewhat time-consuming.- Parameters:
expectedMaxSize
- the expected maximum size of the set.- Throws:
IllegalArgumentException
- if expectedMaxSize is negative.
-
-
Method Detail
-
add
public boolean add(E e)
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceSet<E>
- Overrides:
add
in classAbstractCollection<E>
- See Also:
AbstractCollection.add(java.lang.Object)
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceSet<E>
- Overrides:
clear
in classAbstractCollection<E>
- See Also:
AbstractCollection.clear()
-
clone
public Object clone()
- See Also:
Object.clone()
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceSet<E>
- Overrides:
contains
in classAbstractCollection<E>
- See Also:
AbstractCollection.contains(java.lang.Object)
-
equals
public boolean equals(Object obj)
- Specified by:
equals
in interfaceCollection<E>
- Specified by:
equals
in interfaceSet<E>
- Overrides:
equals
in classAbstractSet<E>
- See Also:
AbstractSet.equals(java.lang.Object)
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceCollection<E>
- Specified by:
hashCode
in interfaceSet<E>
- Overrides:
hashCode
in classAbstractSet<E>
- See Also:
AbstractSet.hashCode()
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceSet<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
- See Also:
AbstractCollection.isEmpty()
-
iterator
public Iterator<E> iterator()
- Specified by:
iterator
in interfaceCollection<E>
- Specified by:
iterator
in interfaceIterable<E>
- Specified by:
iterator
in interfaceSet<E>
- Specified by:
iterator
in classAbstractCollection<E>
- See Also:
AbstractCollection.iterator()
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceSet<E>
- Overrides:
remove
in classAbstractCollection<E>
- See Also:
AbstractCollection.remove(java.lang.Object)
-
size
public int size()
- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceSet<E>
- Specified by:
size
in classAbstractCollection<E>
- See Also:
AbstractCollection.size()
-
-