1 package org.apache.commons.graph.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static java.lang.String.format;
23
24 import org.apache.commons.graph.LabeledEdge;
25
26 public class BaseLabeledEdge
27 implements LabeledEdge<BaseLabeledVertex>
28 {
29
30 private final String label;
31
32 private final BaseLabeledVertex head;
33
34 private final BaseLabeledVertex tail;
35
36 public BaseLabeledEdge( String label, BaseLabeledVertex head, BaseLabeledVertex tail )
37 {
38 this.label = label;
39 this.head = head;
40 this.tail = tail;
41 }
42
43
44
45
46 public String getLabel()
47 {
48 return label;
49 }
50
51
52
53
54 public BaseLabeledVertex getHead()
55 {
56 return head;
57 }
58
59
60
61
62 public BaseLabeledVertex getTail()
63 {
64 return tail;
65 }
66
67
68
69
70 @Override
71 public int hashCode()
72 {
73 final int prime = 31;
74 int result = 1;
75 result = prime * result + ( ( head == null ) ? 0 : head.hashCode() );
76 result = prime * result + ( ( label == null ) ? 0 : label.hashCode() );
77 result = prime * result + ( ( tail == null ) ? 0 : tail.hashCode() );
78 return result;
79 }
80
81
82
83
84 @Override
85 public boolean equals( Object obj )
86 {
87 if ( this == obj )
88 {
89 return true;
90 }
91
92 if ( obj == null )
93 {
94 return false;
95 }
96
97 if ( getClass() != obj.getClass() )
98 {
99 return false;
100 }
101
102 BaseLabeledEdge other = (BaseLabeledEdge) obj;
103
104 if ( head == null )
105 {
106 if ( other.getHead() != null )
107 {
108 return false;
109 }
110 }
111 else if ( !head.equals( other.getHead() ) )
112 {
113 return false;
114 }
115
116 if ( tail == null )
117 {
118 if ( other.getTail() != null )
119 {
120 return false;
121 }
122 }
123 else if ( !tail.equals( other.getTail() ) )
124 {
125 return false;
126 }
127
128 if ( label == null )
129 {
130 if ( other.getLabel() != null )
131 {
132 return false;
133 }
134 }
135 else if ( !label.equals( other.label ) )
136 {
137 return false;
138 }
139
140 return true;
141 }
142
143
144
145
146 @Override
147 public String toString()
148 {
149 return format( "%s( %s ==> %s )", label, head, tail );
150 }
151
152 }