edu.illinois.cs.cogcomp.lbj.coref.util.collections
Class Partition<T>

java.lang.Object
  extended by edu.illinois.cs.cogcomp.lbj.coref.util.collections.Partition<T>

public class Partition<T>
extends java.lang.Object


Field Summary
private  java.util.Map<T,java.util.Set<T>> m_subsets
           
 
Constructor Summary
Partition()
           
Partition(java.util.Collection<java.util.Collection<T>> subsets)
          Creates a partition from Collections.
Partition(Partition<T> p)
           
 
Method Summary
 boolean add(T obj)
          Adds obj to the partition as a new subset.
 boolean add(T obj, T toSubsetContaining)
          Add the object to subsetContaining.
 boolean addAll(Partition<T> other)
          Adds all subsets from other to this.
 boolean addSubset(java.util.Collection<T> subset)
          Adds a subset to the Partition.
 boolean areTogether(T a, T b)
           
 boolean contains(T obj)
           
static
<T> Partition<T>
createSingletonsPartition(java.util.Collection<T> singletons)
          Constructs a partition in which each item from singletons forms its own subset.
 java.util.Set<T> getAllMembers()
          Backed externally.
 java.util.Set<T> getContainerFor(T obj)
           
 java.util.List<java.util.Set<T>> getSubsets()
           
 void join(T partitionContainingA, T partitionContainingB)
           
 java.util.Collection<java.util.Collection<T>> toCollections()
          Returns a copy of this partition as a Collection of Collections.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_subsets

private java.util.Map<T,java.util.Set<T>> m_subsets
Constructor Detail

Partition

public Partition()

Partition

public Partition(java.util.Collection<java.util.Collection<T>> subsets)
Creates a partition from Collections.

Throws:
java.lang.Exception - if any element occurs in multiple subsets.

Partition

public Partition(Partition<T> p)
Method Detail

createSingletonsPartition

public static <T> Partition<T> createSingletonsPartition(java.util.Collection<T> singletons)
Constructs a partition in which each item from singletons forms its own subset. Currently, duplicates will be dropped.


add

public boolean add(T obj)
Adds obj to the partition as a new subset.

Returns:
true if successful; false if obj already present.

add

public boolean add(T obj,
                   T toSubsetContaining)
Add the object to subsetContaining. The obj must not be in the Partition.

Returns:
whether operation succeeded.

addSubset

public boolean addSubset(java.util.Collection<T> subset)
Adds a subset to the Partition. The subset must not contain any elements already in the partition. subset will be backed internally.

Returns:
whether operation succeeded.

addAll

public boolean addAll(Partition<T> other)
Adds all subsets from other to this. In case adding any subset from other fails, returns false but still adds all addable subsets.

Parameters:
other - Another Partition (disjoint from this one).
Returns:
true if successful; false if some subset(s) could not be added.

join

public void join(T partitionContainingA,
                 T partitionContainingB)

areTogether

public boolean areTogether(T a,
                           T b)

contains

public boolean contains(T obj)

getAllMembers

public java.util.Set<T> getAllMembers()
Backed externally.


getSubsets

public java.util.List<java.util.Set<T>> getSubsets()

getContainerFor

public java.util.Set<T> getContainerFor(T obj)
Returns:
an unmodifiable view of the Set containing obj, or null if obj not found.

toCollections

public java.util.Collection<java.util.Collection<T>> toCollections()
Returns a copy of this partition as a Collection of Collections. Subsets will be copies, but items will not be cloned.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object