public class EquivalentHashSet<E> extends AbstractSet<E>
Equivalence
function implementations for values,
as opposed to relying on their own equals/hashCode/toString implementations.
This is handy when using key/values whose mentioned methods cannot be
overriden, i.e. arrays, and in situations where users want to avoid using
wrapper objects.Constructor and Description |
---|
EquivalentHashSet(Equivalence<? super E> entryEq)
Deprecated.
Constructs a new, empty set, with a given equivalence function
|
EquivalentHashSet(int initialCapacity,
Equivalence<? super E> entryEq)
Deprecated.
Constructs a new, empty set, with a given initial capacity and a
particular equivalence function to compare entries.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E o)
Deprecated.
Adds the specified element to this set if it is not already present.
|
void |
clear()
Deprecated.
Removes all of the elements from this set.
|
boolean |
contains(Object o)
Deprecated.
Returns
true if this set contains the specified element. |
int |
hashCode()
Deprecated.
Returns the hash code value for this set using the
Equivalence
function associated with it. |
boolean |
isEmpty()
Deprecated.
Returns
true if this set contains no elements. |
Iterator<E> |
iterator()
Deprecated.
Returns an iterator over the elements in this set.
|
boolean |
remove(Object o)
Deprecated.
Removes the specified element from this set if it is present.
|
int |
size()
Deprecated.
Returns the number of elements in this set.
|
equals, removeAll
addAll, containsAll, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, containsAll, retainAll, spliterator, toArray, toArray
parallelStream, removeIf, stream
public EquivalentHashSet(Equivalence<? super E> entryEq)
entryEq
- the Equivalence function to be used to compare entries
in this set.public EquivalentHashSet(int initialCapacity, Equivalence<? super E> entryEq)
initialCapacity
- this set's initial capacityentryEq
- the Equivalence function to be used to compare entries
in this set.public Iterator<E> iterator()
public int size()
Integer.MAX_VALUE
elements, it
returns Integer.MAX_VALUE
.size
in interface Collection<E>
size
in interface Set<E>
size
in class AbstractCollection<E>
public boolean isEmpty()
true
if this set contains no elements.isEmpty
in interface Collection<E>
isEmpty
in interface Set<E>
isEmpty
in class AbstractCollection<E>
true
if this set contains no elementspublic boolean contains(Object o)
true
if this set contains the specified element.contains
in interface Collection<E>
contains
in interface Set<E>
contains
in class AbstractCollection<E>
o
- the object to be checked for containment in this settrue
if this set contains the specified elementpublic boolean add(E o)
add
in interface Collection<E>
add
in interface Set<E>
add
in class AbstractCollection<E>
o
- element to be added to this settrue
if the set did not already contain the specified
elementpublic boolean remove(Object o)
remove
in interface Collection<E>
remove
in interface Set<E>
remove
in class AbstractCollection<E>
o
- object to be removed from this set, if presenttrue
if the set contained the specified elementpublic void clear()
clear
in interface Collection<E>
clear
in interface Set<E>
clear
in class AbstractCollection<E>
public int hashCode()
Equivalence
function associated with it. The hash code of a set is defined to be
the sum of the hash codes of the elements in the set, where the hash
code of a null element is defined to be zero. This ensures that
Equivalence.equals(Object s1, Object s2)
implies that
Equivalence.hashCode(Object s1)
==Equivalence.hashCode(Object s2)
for any two sets s1 and s2, as required by the general
contract of Object.hashCode()
.
This implementation iterates over the set, calling the hashCode method on each element in the set, and adding up the results.
hashCode
in interface Collection<E>
hashCode
in interface Set<E>
hashCode
in class AbstractSet<E>
Copyright © 2017 JBoss, a division of Red Hat. All rights reserved.