]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.route/src/org/simantics/district/route/internal/WaypointImpl.java
Improved Routes view functionality
[simantics/district.git] / org.simantics.district.route / src / org / simantics / district / route / internal / WaypointImpl.java
1 package org.simantics.district.route.internal;
2
3 import java.util.Objects;
4
5 import org.simantics.db.Resource;
6 import org.simantics.district.route.Waypoint;
7
8 /**
9  * @author Tuukka Lehtonen
10  * @since 6.09
11  */
12 public class WaypointImpl implements Waypoint {
13
14     private final Resource element;
15     private String label;
16
17     public WaypointImpl(Resource element, String label) {
18         Objects.requireNonNull(element, "Non-null element required");
19         this.element = element;
20         this.label = label;
21     }
22
23     @SuppressWarnings("unchecked")
24     @Override
25     public <T> T getObject() {
26         return (T) element;
27     }
28
29     @Override
30     public String getLabel() {
31         return label;
32     }
33
34     public void setLabel(String label) {
35         this.label = label;
36     }
37
38     @Override
39     public String toString() {
40         return label;
41     }
42
43     public Waypoint withLabel(String label) {
44         return new WaypointImpl(element, label);
45     }
46
47     @Override
48     public int hashCode() {
49         final int prime = 31;
50         int result = 1;
51         result = prime * result + element.hashCode();
52         return result;
53     }
54
55     @Override
56     public boolean equals(Object obj) {
57         if (this == obj)
58             return true;
59         if (obj == null)
60             return false;
61         if (getClass() != obj.getClass())
62             return false;
63         WaypointImpl other = (WaypointImpl) obj;
64         return element.equals(other.element);
65     }
66
67 }