Created
March 1, 2012 08:23
-
-
Save pif/1948296 to your computer and use it in GitHub Desktop.
Node class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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