-/*******************************************************************************\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.Collections;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.utils.datastructures.MapList;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class DiagramContents {\r
-\r
- /**\r
- * Z-ordered list of ALL direct diagram elements.\r
- */\r
- public List<Resource> elements = Collections.emptyList();\r
-\r
- /**\r
- * The set of normal elements in the diagram contents list.\r
- */\r
- public Set<Resource> nodeSet = Collections.emptySet();\r
-\r
- public Set<Resource> connectionSet = Collections.emptySet();\r
- public Set<EdgeResource> connectionSegments = Collections.emptySet();\r
- public Set<Resource> branchPoints = Collections.emptySet();\r
-\r
- public Set<Resource> routeGraphConnectionSet = Collections.emptySet();\r
- public Set<EdgeResource> routeLinks = Collections.emptySet();\r
- public Set<Resource> routeLines = Collections.emptySet();\r
- public Set<Resource> routePoints = Collections.emptySet();\r
-\r
- public Map<Object, Resource> partToConnection = Collections.emptyMap();\r
- public MapList<Resource, Object> connectionToParts = new MapList<Resource, Object>();\r
-\r
- private <T> void calculateChanges(Set<T> from, Set<T> to, Map<T, Change> result) {\r
- for (T e : to)\r
- if (!from.contains(e))\r
- result.put(e, Change.ADDED);\r
-// else\r
-// result.put(e, Change.POSSIBLY_MODIFIED);\r
- for (T e : from)\r
- if (!to.contains(e))\r
- result.put(e, Change.REMOVED);\r
- }\r
-\r
- private <T> void addAll(Set<T> to, Map<T, Change> result) {\r
- for (T e : to)\r
- result.put(e, Change.ADDED);\r
- }\r
-\r
- public DiagramContentChanges differenceFrom(DiagramContents from) {\r
- DiagramContentChanges result = new DiagramContentChanges();\r
- if (this == from)\r
- return result;\r
- if (from == null) {\r
- // Both nodes and connections are considered elements of the diagram.\r
- addAll(nodeSet, result.elements);\r
- addAll(connectionSet, result.elements);\r
- addAll(routeGraphConnectionSet, result.elements);\r
- addAll(nodeSet, result.nodes);\r
- addAll(connectionSet, result.connections);\r
- addAll(connectionSegments, result.connectionSegments);\r
- addAll(branchPoints, result.branchPoints);\r
- addAll(routeGraphConnectionSet, result.routeGraphConnections);\r
- addAll(routeLinks, result.routeLinks);\r
- addAll(routeLines, result.routeLines);\r
- addAll(routePoints, result.routePoints);\r
- } else {\r
- // Both nodes and connections are considered elements of the diagram.\r
- calculateChanges(from.nodeSet, nodeSet, result.elements);\r
- calculateChanges(from.connectionSet, connectionSet, result.elements);\r
- calculateChanges(from.routeGraphConnectionSet, routeGraphConnectionSet, result.elements);\r
- calculateChanges(from.nodeSet, nodeSet, result.nodes);\r
- calculateChanges(from.connectionSet, connectionSet, result.connections);\r
- calculateChanges(from.connectionSegments, connectionSegments, result.connectionSegments);\r
- calculateChanges(from.branchPoints, branchPoints, result.branchPoints);\r
- calculateChanges(from.routeGraphConnectionSet, routeGraphConnectionSet, result.routeGraphConnections);\r
- calculateChanges(from.routeLinks, routeLinks, result.routeLinks);\r
- calculateChanges(from.routeLines, routeLines, result.routeLines);\r
- calculateChanges(from.routePoints, routePoints, result.routePoints);\r
-\r
- if (!from.elements.equals(elements))\r
- result.markElementOrderChanged();\r
- }\r
- return result;\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result + ((routeGraphConnectionSet == null) ? 0 : routeGraphConnectionSet.hashCode());\r
- result = prime * result + ((connectionSet == null) ? 0 : connectionSet.hashCode());\r
- result = prime * result + ((elements == null) ? 0 : elements.hashCode());\r
- return result;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (obj == null)\r
- return false;\r
- if (getClass() != obj.getClass())\r
- return false;\r
- DiagramContents other = (DiagramContents) obj;\r
- if (!elements.equals(other.elements))\r
- return false;\r
- if (!connectionSegments.equals(other.connectionSegments))\r
- return false;\r
- if (!branchPoints.equals(other.branchPoints))\r
- return false;\r
- if (!routeLinks.equals(other.routeLinks))\r
- return false;\r
- if (!routeLines.equals(other.routeLines))\r
- return false;\r
- if (!routePoints.equals(other.routePoints))\r
- return false;\r
- return true;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return getClass().getSimpleName() + "[elements=" + elements.size()\r
- + ", nodes=" + nodeSet.size()\r
- + ", connections=" + connectionSet.size()\r
- + ", branch points=" + branchPoints.size()\r
- + ", connection segments=" + connectionSegments.size()\r
- + ", routegraph connections=" + routeGraphConnectionSet.size()\r
- + ", routegraph links=" + routeLinks.size()\r
- + ", route lines=" + routeLines.size()\r
- + ", route points=" + routePoints.size()\r
- + "]";\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.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.simantics.db.Resource;
+import org.simantics.utils.datastructures.MapList;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class DiagramContents {
+
+ /**
+ * Z-ordered list of ALL direct diagram elements.
+ */
+ public List<Resource> elements = Collections.emptyList();
+
+ /**
+ * The set of normal elements in the diagram contents list.
+ */
+ public Set<Resource> nodeSet = Collections.emptySet();
+
+ public Set<Resource> connectionSet = Collections.emptySet();
+ public Set<EdgeResource> connectionSegments = Collections.emptySet();
+ public Set<Resource> branchPoints = Collections.emptySet();
+
+ public Set<Resource> routeGraphConnectionSet = Collections.emptySet();
+ public Set<EdgeResource> routeLinks = Collections.emptySet();
+ public Set<Resource> routeLines = Collections.emptySet();
+ public Set<Resource> routePoints = Collections.emptySet();
+
+ public Map<Object, Resource> partToConnection = Collections.emptyMap();
+ public MapList<Resource, Object> connectionToParts = new MapList<Resource, Object>();
+
+ private <T> void calculateChanges(Set<T> from, Set<T> to, Map<T, Change> result) {
+ for (T e : to)
+ if (!from.contains(e))
+ result.put(e, Change.ADDED);
+// else
+// result.put(e, Change.POSSIBLY_MODIFIED);
+ for (T e : from)
+ if (!to.contains(e))
+ result.put(e, Change.REMOVED);
+ }
+
+ private <T> void addAll(Set<T> to, Map<T, Change> result) {
+ for (T e : to)
+ result.put(e, Change.ADDED);
+ }
+
+ public DiagramContentChanges differenceFrom(DiagramContents from) {
+ DiagramContentChanges result = new DiagramContentChanges();
+ if (this == from)
+ return result;
+ if (from == null) {
+ // Both nodes and connections are considered elements of the diagram.
+ addAll(nodeSet, result.elements);
+ addAll(connectionSet, result.elements);
+ addAll(routeGraphConnectionSet, result.elements);
+ addAll(nodeSet, result.nodes);
+ addAll(connectionSet, result.connections);
+ addAll(connectionSegments, result.connectionSegments);
+ addAll(branchPoints, result.branchPoints);
+ addAll(routeGraphConnectionSet, result.routeGraphConnections);
+ addAll(routeLinks, result.routeLinks);
+ addAll(routeLines, result.routeLines);
+ addAll(routePoints, result.routePoints);
+ } else {
+ // Both nodes and connections are considered elements of the diagram.
+ calculateChanges(from.nodeSet, nodeSet, result.elements);
+ calculateChanges(from.connectionSet, connectionSet, result.elements);
+ calculateChanges(from.routeGraphConnectionSet, routeGraphConnectionSet, result.elements);
+ calculateChanges(from.nodeSet, nodeSet, result.nodes);
+ calculateChanges(from.connectionSet, connectionSet, result.connections);
+ calculateChanges(from.connectionSegments, connectionSegments, result.connectionSegments);
+ calculateChanges(from.branchPoints, branchPoints, result.branchPoints);
+ calculateChanges(from.routeGraphConnectionSet, routeGraphConnectionSet, result.routeGraphConnections);
+ calculateChanges(from.routeLinks, routeLinks, result.routeLinks);
+ calculateChanges(from.routeLines, routeLines, result.routeLines);
+ calculateChanges(from.routePoints, routePoints, result.routePoints);
+
+ if (!from.elements.equals(elements))
+ result.markElementOrderChanged();
+ }
+ return result;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((routeGraphConnectionSet == null) ? 0 : routeGraphConnectionSet.hashCode());
+ result = prime * result + ((connectionSet == null) ? 0 : connectionSet.hashCode());
+ result = prime * result + ((elements == null) ? 0 : elements.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;
+ DiagramContents other = (DiagramContents) obj;
+ if (!elements.equals(other.elements))
+ return false;
+ if (!connectionSegments.equals(other.connectionSegments))
+ return false;
+ if (!branchPoints.equals(other.branchPoints))
+ return false;
+ if (!routeLinks.equals(other.routeLinks))
+ return false;
+ if (!routeLines.equals(other.routeLines))
+ return false;
+ if (!routePoints.equals(other.routePoints))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "[elements=" + elements.size()
+ + ", nodes=" + nodeSet.size()
+ + ", connections=" + connectionSet.size()
+ + ", branch points=" + branchPoints.size()
+ + ", connection segments=" + connectionSegments.size()
+ + ", routegraph connections=" + routeGraphConnectionSet.size()
+ + ", routegraph links=" + routeLinks.size()
+ + ", route lines=" + routeLines.size()
+ + ", route points=" + routePoints.size()
+ + "]";
+ }
+
}
\ No newline at end of file