1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.dbunit.util.search;
22
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26
27
28
29
30
31
32
33
34 public class Edge implements IEdge {
35
36
37
38
39 private static final Logger logger = LoggerFactory.getLogger(Edge.class);
40
41 private final Comparable<String> nodeFrom;
42 private final Comparable<String> nodeTo;
43
44
45
46
47
48 public Edge(final Comparable<String> nodeFrom, final Comparable<String> nodeTo) {
49 if (nodeFrom == null) {
50 throw new IllegalArgumentException("node from cannot be null");
51 }
52 if (nodeTo == null) {
53 throw new IllegalArgumentException("node to cannot be null");
54 }
55 this.nodeFrom = nodeFrom;
56 this.nodeTo = nodeTo;
57 }
58
59 @Override
60 public Object getFrom() {
61 return this.nodeFrom;
62 }
63
64 @Override
65 public Object getTo() {
66 return this.nodeTo;
67 }
68
69 @Override
70 public String toString() {
71 return this.nodeFrom + "->" + this.nodeTo;
72 }
73
74
75
76
77
78
79
80
81 @Override
82 public int compareTo(final Object o) {
83 logger.debug("compareTo(o={}) - start", o);
84
85 final Edge otherEdge = (Edge) o;
86 int result = this.nodeFrom.compareTo((String) otherEdge.getFrom());
87 if ( result == 0 ) {
88 result = this.nodeTo.compareTo((String) otherEdge.getTo());
89 }
90 return result;
91 }
92
93 @Override
94 public int hashCode() {
95 final int prime = 31;
96 int result = 1;
97 result = prime * result
98 + ((nodeFrom == null) ? 0 : nodeFrom.hashCode());
99 result = prime * result + ((nodeTo == null) ? 0 : nodeTo.hashCode());
100 return result;
101 }
102
103 @Override
104 public boolean equals(final Object obj) {
105 if (this == obj)
106 return true;
107 if (obj == null)
108 return false;
109 if (getClass() != obj.getClass())
110 return false;
111 final Edge other = (Edge) obj;
112 if (nodeFrom == null) {
113 if (other.nodeFrom != null)
114 return false;
115 } else if (!nodeFrom.equals(other.nodeFrom))
116 return false;
117 if (nodeTo == null) {
118 if (other.nodeTo != null)
119 return false;
120 } else if (!nodeTo.equals(other.nodeTo))
121 return false;
122 return true;
123 }
124
125 }