com.mantledillusion.essentials.graph.NodeId Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of graph-essentials Show documentation
Show all versions of graph-essentials Show documentation
Graph Essentials contain utility classes useful for graph visualization purposes.
The newest version!
package com.mantledillusion.essentials.graph;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
/**
* Cumulative ID of one or multiple @{@link Node}'s IDs.
*
* @param The node's identifier type
*/
public class NodeId {
private final Set ids;
/**
* Default constructor.
*
* @param id A {@link Node}'s ID; might not be null.
*/
public NodeId(IdType id) {
this(Collections.singleton(id));
}
private NodeId(Set ids) {
this.ids = ids;
}
/**
* Returns the IDs contained by the cluster this @{@link NodeId} identifies.
*
* @return The IDs, never null
*/
public Set getIds() {
return this.ids;
}
/**
* Returns the size of the cluster this {@link NodeId} identifies.
*
* @return The size
*/
public int getClusterSize() {
return this.ids.size();
}
/**
* Clusters this {@link NodeId} with the given one.
*
* @param other The {@link NodeId} to form cumulative {@link NodeId} with; might not be null.
* @return A new {@link NodeId} with combined IDs, never null
*/
public NodeId clusterWith(NodeId other) {
return new NodeId<>(NodeEssentials.union(this.ids, other.ids));
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof NodeId)) return false;
return Objects.equals(this.ids, ((NodeId>) o).ids);
}
@Override
public int hashCode() {
return Objects.hash(this.ids);
}
@Override
public String toString() {
return this.ids.toString();
}
}