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.WeightedEdge;
25
26
27
28
29 public class BaseLabeledWeightedEdge
30 extends BaseLabeledEdge
31 implements WeightedEdge<BaseLabeledVertex>
32 {
33
34 private final Double weight;
35
36 public BaseLabeledWeightedEdge( String label, BaseLabeledVertex head, BaseLabeledVertex tail, Double weight )
37 {
38 super( label, head, tail );
39 this.weight = weight;
40 }
41
42
43
44
45 public int compareTo( WeightedEdge<BaseLabeledVertex> other )
46 {
47 return weight.compareTo( other.getWeight() );
48 }
49
50
51
52
53 public Double getWeight()
54 {
55 return weight;
56 }
57
58
59
60
61 @Override
62 public int hashCode()
63 {
64 final int prime = 31;
65 int result = super.hashCode();
66 result = prime * result + ( ( weight == null ) ? 0 : weight.hashCode() );
67 return result;
68 }
69
70
71
72
73 @Override
74 public boolean equals( Object obj )
75 {
76 if ( this == obj )
77 {
78 return true;
79 }
80
81 if ( !super.equals( obj ) )
82 {
83 return false;
84 }
85
86 if ( getClass() != obj.getClass() )
87 {
88 return false;
89 }
90
91 BaseLabeledWeightedEdge other = (BaseLabeledWeightedEdge) obj;
92 if ( weight == null )
93 {
94 if ( other.getWeight() != null )
95 {
96 return false;
97 }
98 }
99 else if ( !weight.equals( other.getWeight() ) )
100 {
101 return false;
102 }
103
104 return true;
105 }
106
107
108
109
110 @Override
111 public String toString()
112 {
113 return format( "%s( %s =%s=> %s )", getLabel(), getHead(), weight, getTail() );
114 }
115
116 }