org.carrot2.core
Class ClusterWithParent

java.lang.Object
  extended by org.carrot2.core.ClusterWithParent

public final class ClusterWithParent
extends Object

Wraps a Cluster to add information about the cluster's parent cluster, if any. A reference to the parent cluster is not kept directly in the Cluster class because some algorithms may attach a single cluster to many parent clusters.

Instances of this class override hashCode() and equals(Object) by forwarding them to cluster.


Field Summary
 Cluster cluster
          The cluster wrapped by this class
 ClusterWithParent parent
          The parent cluster of cluster, may be null in case of top-level clusters.
 List<ClusterWithParent> subclusters
          Subclusters of cluster wrapped to add their parent cluster.
 
Method Summary
 boolean equals(Object obj)
           
static ClusterWithParent find(int id, Collection<ClusterWithParent> wrappers)
          Locate the first cluster that has id equal to id.
 int hashCode()
           
static ClusterWithParent wrap(Cluster root)
          Wraps a cluster hierarchy starting with the root into ClusterWithParent objects.
static List<ClusterWithParent> wrap(List<Cluster> clusters)
          Wraps a list of top level clusters.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cluster

public final Cluster cluster
The cluster wrapped by this class


parent

public final ClusterWithParent parent
The parent cluster of cluster, may be null in case of top-level clusters.


subclusters

public final List<ClusterWithParent> subclusters
Subclusters of cluster wrapped to add their parent cluster. The list is unmodifiable.

Method Detail

wrap

public static ClusterWithParent wrap(Cluster root)
Wraps a cluster hierarchy starting with the root into ClusterWithParent objects. All children of the root cluster will have the parent field set to the wrapper corresponding to their parent clusters, while for the root cluster, parent will be null. Note that for efficiency reasons, reference cycles are not detected.

Parameters:
root - the cluster to be wrapped
Returns:
wrapped cluster with parent

wrap

public static List<ClusterWithParent> wrap(List<Cluster> clusters)
Wraps a list of top level clusters. Each cluster in the list will be assumed to have a null parent cluster. Note that for efficiency reasons, reference cycles are not detected.

Parameters:
clusters - the list of top-level clusters to be wrapped
Returns:
the wrapped clusters with parents

find

public static ClusterWithParent find(int id,
                                     Collection<ClusterWithParent> wrappers)
Locate the first cluster that has id equal to id. The search includes all the clusters in the input and their sub-clusters. The first cluster with matching identifier is returned or null if no such cluster could be found.


hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright (c) Dawid Weiss, Stanislaw Osinski