summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/graph/Edge.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-04-03 19:22:48 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-04-03 19:22:48 -0400
commit1c8bc7132d980c1ff2dbd6b9af579c3b2fd8c63e (patch)
treea29777f07ebd81fbef61b5ae02f13f1a9d8f65a2 /BJC-Utils2/src/main/java/bjc/utils/graph/Edge.java
parenta023de85aa08c8f2b8b2441c6b14064eabee2775 (diff)
General code refactoring and maintenance
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/graph/Edge.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/graph/Edge.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/graph/Edge.java b/BJC-Utils2/src/main/java/bjc/utils/graph/Edge.java
index 44aa8e7..58a233a 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/graph/Edge.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/graph/Edge.java
@@ -30,6 +30,14 @@ public class Edge<T> {
* The distance between initial and terminal edge
*/
public Edge(T initialNode, T terminalNode, int distance) {
+ if (initialNode == null) {
+ throw new NullPointerException(
+ "Initial node must not be null");
+ } else if (terminalNode == null) {
+ throw new NullPointerException(
+ "Terminal node must not be null");
+ }
+
this.source = initialNode;
this.target = terminalNode;
this.distance = distance;
@@ -68,4 +76,58 @@ public class Edge<T> {
return " first vertex " + source + " to vertex " + target
+ " with distance: " + distance;
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + distance;
+ result = prime * result
+ + ((source == null) ? 0 : source.hashCode());
+ result = prime * result
+ + ((target == null) ? 0 : target.hashCode());
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ } else if (obj == null) {
+ return false;
+ } else if (getClass() != obj.getClass()) {
+ return false;
+ } else {
+
+ Edge<?> other = (Edge<?>) obj;
+
+ if (distance != other.distance) {
+ return false;
+ } else if (source == null) {
+ if (other.source != null) {
+ return false;
+ }
+ } else if (!source.equals(other.source)) {
+ return false;
+ } else if (target == null) {
+ if (other.target != null) {
+ return false;
+ }
+ } else if (!target.equals(other.target)) {
+ return false;
+ }
+
+ return true;
+ }
+ }
}