edu.uci.ics.jung.visualization.util.Context Maven / Gradle / Ivy
package edu.uci.ics.jung.visualization.util;
/**
* A class that is used to link together a graph element and a specific graph. Provides appropriate
* implementations of hashCode
and equals
.
*/
public class Context {
/** The graph element which defines this context. */
public final G graph;
/** The edge element which defines this context. */
public final E element;
private Context(G graph, E element) {
this.graph = graph;
this.element = element;
}
/**
* Returns an instance of this type for the specified graph and element.
*
* @param the graph type
* @param the element type
*/
@SuppressWarnings("unchecked")
public static Context getInstance(G graph, E element) {
return new Context(graph, element);
}
@Override
public int hashCode() {
return graph.hashCode() ^ element.hashCode();
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object o) {
if (!(o instanceof Context)) return false;
Context context = (Context) o;
return context.graph.equals(graph) && context.element.equals(element);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy