-/*******************************************************************************\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
-import java.util.Iterator;\r
-import java.util.NoSuchElementException;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public final class EdgeResource /*extends OrderedPair<Resource>*/ implements Iterable<Resource>, Comparable<EdgeResource> {\r
-\r
- private final Resource first;\r
- private final Resource second;\r
-\r
- public EdgeResource(Resource first, Resource second) {\r
- this.first = first;\r
- this.second = second;\r
- }\r
-\r
- public String toString(ReadGraph g) throws DatabaseException {\r
- return "(" + NameUtils.getSafeName(g, first()) + ", " + NameUtils.getSafeName(g, second()) + ")";\r
- }\r
-\r
- public Resource first() {\r
- return first;\r
- }\r
-\r
- public Resource second() {\r
- return second;\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- return first.hashCode() + second.hashCode();\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (!(obj instanceof EdgeResource))\r
- return false;\r
- EdgeResource other = (EdgeResource) obj;\r
- return (first.equals(other.first) && second.equals(other.second)) || (first.equals(other.second) && second.equals(other.first));\r
- }\r
-\r
-\r
- @Override\r
- public String toString() {\r
- //return "(" + first() + ", " + second() + ")";\r
- StringBuilder sb = new StringBuilder(32);\r
- sb.append('(');\r
- sb.append(first.getResourceId());\r
- sb.append(',');\r
- sb.append(second.getResourceId());\r
- sb.append(')');\r
- return sb.toString();\r
- }\r
-\r
- @Override\r
- public Iterator<Resource> iterator() {\r
- return new Iterator<Resource>() {\r
- int i = 0;\r
-\r
- @Override\r
- public boolean hasNext() {\r
- return i == 0;\r
- }\r
-\r
- @Override\r
- public Resource next() {\r
- ++i;\r
- switch (i) {\r
- case 1: return first();\r
- case 2: return second();\r
- default:\r
- throw new NoSuchElementException("element " + i + "is out of bounds, only two elements exist.");\r
- }\r
- }\r
-\r
- @Override\r
- public void remove() {\r
- throw new UnsupportedOperationException();\r
- }\r
- };\r
- }\r
-\r
- final private long id() {\r
- return first.getResourceId() + second.getResourceId();\r
- }\r
-\r
- @Override\r
- public int compareTo(EdgeResource arg0) {\r
- long i = id();\r
- long i2 = arg0.id();\r
- if(i == i2) return 0;\r
- if(i < i2) return -1;\r
- else return 1;\r
- }\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.diagram.content;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public final class EdgeResource /*extends OrderedPair<Resource>*/ implements Iterable<Resource>, Comparable<EdgeResource> {
+
+ private final Resource first;
+ private final Resource second;
+
+ public EdgeResource(Resource first, Resource second) {
+ this.first = first;
+ this.second = second;
+ }
+
+ public String toString(ReadGraph g) throws DatabaseException {
+ return "(" + NameUtils.getSafeName(g, first()) + ", " + NameUtils.getSafeName(g, second()) + ")";
+ }
+
+ public Resource first() {
+ return first;
+ }
+
+ public Resource second() {
+ return second;
+ }
+
+ @Override
+ public int hashCode() {
+ return first.hashCode() + second.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!(obj instanceof EdgeResource))
+ return false;
+ EdgeResource other = (EdgeResource) obj;
+ return (first.equals(other.first) && second.equals(other.second)) || (first.equals(other.second) && second.equals(other.first));
+ }
+
+
+ @Override
+ public String toString() {
+ //return "(" + first() + ", " + second() + ")";
+ StringBuilder sb = new StringBuilder(32);
+ sb.append('(');
+ sb.append(first.getResourceId());
+ sb.append(',');
+ sb.append(second.getResourceId());
+ sb.append(')');
+ return sb.toString();
+ }
+
+ @Override
+ public Iterator<Resource> iterator() {
+ return new Iterator<Resource>() {
+ int i = 0;
+
+ @Override
+ public boolean hasNext() {
+ return i == 0;
+ }
+
+ @Override
+ public Resource next() {
+ ++i;
+ switch (i) {
+ case 1: return first();
+ case 2: return second();
+ default:
+ throw new NoSuchElementException("element " + i + "is out of bounds, only two elements exist.");
+ }
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ final private long id() {
+ return first.getResourceId() + second.getResourceId();
+ }
+
+ @Override
+ public int compareTo(EdgeResource arg0) {
+ long i = id();
+ long i2 = arg0.id();
+ if(i == i2) return 0;
+ if(i < i2) return -1;
+ else return 1;
+ }
+
}
\ No newline at end of file