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:
Iterable<T>, Collection<T>, Set<T>

public final class IdentitySet<T>
extends AbstractSet<T>
implements 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(Set<IdentitySet.IdentityReference<T>> delegateSet)
          Create a new set using the passed set as the store.
 
Method Summary
 boolean add(T t)
           
 boolean addAll(Collection<? extends T> c)
           
 void clear()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
 boolean isEmpty()
           
 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(Object o)
           
 boolean removeAll(Collection<?> c)
           
 boolean retainAll(Collection<?> c)
           
 int size()
           
 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(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 Collection<T>
Specified by:
clear in interface Set<T>
Overrides:
clear in class AbstractCollection<T>

iterator

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

add

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

remove

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

containsAll

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

addAll

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

retainAll

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

removeAll

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

size

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

isEmpty

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

contains

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

toString

public String toString()
Overrides:
toString in class AbstractCollection<T>


Copyright © 2002-2009 Atlassian. All Rights Reserved.