]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/content/OrderedPair.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / content / OrderedPair.java
diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/content/OrderedPair.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/content/OrderedPair.java
new file mode 100644 (file)
index 0000000..3f506ca
--- /dev/null
@@ -0,0 +1,65 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.diagram.content;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ *\r
+ * @param <T> a comparable type\r
+ */\r
+public class OrderedPair<T extends Comparable<T>> {\r
+\r
+    private final T first;\r
+    private final T second;\r
+\r
+    public OrderedPair(T first, T second) {\r
+        assert first != null;\r
+        assert second != null;\r
+\r
+        int comp = first.compareTo(second);\r
+        if (comp < 0) {\r
+            this.first = first;\r
+            this.second = second;\r
+        } else {\r
+            this.first = second;\r
+            this.second = first;\r
+        }\r
+    }\r
+\r
+    public T first() {\r
+        return first;\r
+    }\r
+\r
+    public T second() {\r
+        return second;\r
+    }\r
+\r
+    @Override\r
+    public int hashCode() {\r
+        return (first.hashCode() * 31) + second.hashCode();\r
+    }\r
+\r
+    @Override\r
+    public boolean equals(Object obj) {\r
+        if (this == obj)\r
+            return true;\r
+        if (!(obj instanceof OrderedPair<?>))\r
+            return false;\r
+        OrderedPair<?> other = (OrderedPair<?>) obj;\r
+        return first.equals(other.first) && second.equals(other.second);\r
+    }\r
+\r
+    public static <T extends Comparable<T>> OrderedPair<T> make(T ra, T rb) {\r
+        return new OrderedPair<T>(ra, rb);\r
+    }\r
+\r
+}
\ No newline at end of file