]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.route/src/org/simantics/district/route/internal/WaypointImpl.java
Initial version of the district network Routes view.
[simantics/district.git] / org.simantics.district.route / src / org / simantics / district / route / internal / WaypointImpl.java
diff --git a/org.simantics.district.route/src/org/simantics/district/route/internal/WaypointImpl.java b/org.simantics.district.route/src/org/simantics/district/route/internal/WaypointImpl.java
new file mode 100644 (file)
index 0000000..d78f0c3
--- /dev/null
@@ -0,0 +1,67 @@
+package org.simantics.district.route.internal;
+
+import java.util.Objects;
+
+import org.simantics.db.Resource;
+import org.simantics.district.route.Waypoint;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 6.09
+ */
+public class WaypointImpl implements Waypoint {
+
+    private final Resource element;
+    private String label;
+
+    public WaypointImpl(Resource element, String label) {
+        Objects.requireNonNull(element, "Non-null element required");
+        this.element = element;
+        this.label = label;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T> T getObject() {
+        return (T) element;
+    }
+
+    @Override
+    public String getLabel() {
+        return label;
+    }
+
+    public void setLabel(String label) {
+        this.label = label;
+    }
+
+    @Override
+    public String toString() {
+        return label;
+    }
+
+    public Waypoint withLabel(String label) {
+        return new WaypointImpl(element, label);
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + element.hashCode();
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        WaypointImpl other = (WaypointImpl) obj;
+        return element.equals(other.element);
+    }
+
+}