public final class ClusterWithParent extends Object
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.
| Modifier and Type | Field and Description |
|---|---|
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. |
| Modifier and Type | Method and Description |
|---|---|
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.
|
public final Cluster cluster
public final ClusterWithParent parent
cluster, may be null in case of
top-level clusters.public final List<ClusterWithParent> subclusters
cluster wrapped to add their parent cluster. The list is
unmodifiable.public static ClusterWithParent wrap(Cluster root)
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.root - the cluster to be wrappedpublic static List<ClusterWithParent> wrap(List<Cluster> clusters)
null parent cluster. Note that for efficiency reasons,
reference cycles are not detected.clusters - the list of top-level clusters to be wrappedpublic static ClusterWithParent find(int id, Collection<ClusterWithParent> wrappers)
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.