com.atlassian.jira.util.collect
Class IdentitySet<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<T>
          extended by com.atlassian.jira.util.collect.IdentitySet<T>
All Implemented Interfaces:
java.lang.Iterable<T>, java.util.Collection<T>, java.util.Set<T>

public final class IdentitySet<T>
extends java.util.AbstractSet<T>
implements java.util.Set<T>

A Set implementation that considers objects equal if an only if they are the same instance. The Object.equals(Object) and Object.hashCode() methods of the stored objects are ignored.

This implementation uses another Set to store IdentitySet.IdentityReference objects for each object in the set.


Nested Class Summary
static class IdentitySet.IdentityReference<T>
          Stores a reference to any Object.
 
Constructor Summary
IdentitySet(java.util.Set<IdentitySet.IdentityReference<T>> delegateSet)
          Create a new set using the passed set as the store.
 
Method Summary
 boolean add(T t)
           
 boolean addAll(java.util.Collection<? extends T> c)
           
 void clear()
           
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection<?> c)
           
 boolean isEmpty()
           
 java.util.Iterator<T> iterator()
           
static
<T> IdentitySet<T>
newListOrderedSet()
          Create a new identity set.
static
<T> IdentitySet<T>
newSet()
          Create a new identity set.
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection<?> c)
           
 boolean retainAll(java.util.Collection<?> c)
           
 int size()
           
 java.lang.String toString()
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode
 
Methods inherited from class java.util.AbstractCollection
toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
equals, hashCode, toArray, toArray
 

Constructor Detail

IdentitySet

public IdentitySet(java.util.Set<IdentitySet.IdentityReference<T>> delegateSet)
Create a new set using the passed set as the store. The passed set should not be used by the caller while the new IdentitySet is in use.

Parameters:
delegateSet - the set actually store the objects.
Method Detail

newSet

public static <T> IdentitySet<T> newSet()
Create a new identity set.

Type Parameters:
T - the objects to be stored in the identity set.
Returns:
the new set.

newListOrderedSet

public static <T> IdentitySet<T> newListOrderedSet()
Create a new identity set. The elements in the returned set will be stored in addition order.

Type Parameters:
T - the objects to be stored in the identity set.
Returns:
the new set.

clear

public void clear()
Specified by:
clear in interface java.util.Collection<T>
Specified by:
clear in interface java.util.Set<T>
Overrides:
clear in class java.util.AbstractCollection<T>

iterator

public java.util.Iterator<T> iterator()
Specified by:
iterator in interface java.lang.Iterable<T>
Specified by:
iterator in interface java.util.Collection<T>
Specified by:
iterator in interface java.util.Set<T>
Specified by:
iterator in class java.util.AbstractCollection<T>

add

public boolean add(T t)
Specified by:
add in interface java.util.Collection<T>
Specified by:
add in interface java.util.Set<T>
Overrides:
add in class java.util.AbstractCollection<T>

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection<T>
Specified by:
remove in interface java.util.Set<T>
Overrides:
remove in class java.util.AbstractCollection<T>

containsAll

public boolean containsAll(java.util.Collection<?> c)
Specified by:
containsAll in interface java.util.Collection<T>
Specified by:
containsAll in interface java.util.Set<T>
Overrides:
containsAll in class java.util.AbstractCollection<T>

addAll

public boolean addAll(java.util.Collection<? extends T> c)
Specified by:
addAll in interface java.util.Collection<T>
Specified by:
addAll in interface java.util.Set<T>
Overrides:
addAll in class java.util.AbstractCollection<T>

retainAll

public boolean retainAll(java.util.Collection<?> c)
Specified by:
retainAll in interface java.util.Collection<T>
Specified by:
retainAll in interface java.util.Set<T>
Overrides:
retainAll in class java.util.AbstractCollection<T>

removeAll

public boolean removeAll(java.util.Collection<?> c)
Specified by:
removeAll in interface java.util.Collection<T>
Specified by:
removeAll in interface java.util.Set<T>
Overrides:
removeAll in class java.util.AbstractSet<T>

size

public int size()
Specified by:
size in interface java.util.Collection<T>
Specified by:
size in interface java.util.Set<T>
Specified by:
size in class java.util.AbstractCollection<T>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<T>
Specified by:
isEmpty in interface java.util.Set<T>
Overrides:
isEmpty in class java.util.AbstractCollection<T>

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection<T>
Specified by:
contains in interface java.util.Set<T>
Overrides:
contains in class java.util.AbstractCollection<T>

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractCollection<T>


Copyright © 2002-2011 Atlassian. All Rights Reserved.