Skip to content

Instantly share code, notes, and snippets.

@pif
Created March 1, 2012 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pif/1948296 to your computer and use it in GitHub Desktop.
Save pif/1948296 to your computer and use it in GitHub Desktop.
Node class
package ua.edu.lnu.pif.ucs;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Map;
import java.util.TreeMap;
/**
*
* @author pif
*/
public class Node {
private Map<Integer, Node> children = new TreeMap<Integer, Node>();
private String label;
public void addEdge(Node node, int dist) {
if (node == null) {
throw new NullPointerException("edge");
}
children.put(dist, node);
}
public Node(String label) {
if (label == null) {
throw new NullPointerException("null label");
}
this.label = label;
}
public Map<Integer, Node> getChildren() {
return children;
}
@Override
public String toString() {
return label;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Node other = (Node) obj;
return this.label.equals(other.label);
}
@Override
public int hashCode() {
return label.hashCode();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment