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
ThisSetrelies 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 booleanadd(E e)voidclear()Objectclone()booleancontains(Object o)booleanequals(Object obj)inthashCode()booleanisEmpty()Iterator<E>iterator()booleanremove(Object o)intsize()-
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:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>- See Also:
AbstractCollection.add(java.lang.Object)
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>- See Also:
AbstractCollection.clear()
-
clone
public Object clone()
- See Also:
Object.clone()
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>- See Also:
AbstractCollection.contains(java.lang.Object)
-
equals
public boolean equals(Object obj)
- Specified by:
equalsin interfaceCollection<E>- Specified by:
equalsin interfaceSet<E>- Overrides:
equalsin classAbstractSet<E>- See Also:
AbstractSet.equals(java.lang.Object)
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceCollection<E>- Specified by:
hashCodein interfaceSet<E>- Overrides:
hashCodein classAbstractSet<E>- See Also:
AbstractSet.hashCode()
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Overrides:
isEmptyin classAbstractCollection<E>- See Also:
AbstractCollection.isEmpty()
-
iterator
public Iterator<E> iterator()
- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin interfaceSet<E>- Specified by:
iteratorin classAbstractCollection<E>- See Also:
AbstractCollection.iterator()
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>- See Also:
AbstractCollection.remove(java.lang.Object)
-
size
public int size()
- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>- See Also:
AbstractCollection.size()
-
-