]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ResourceQuery.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / ResourceQuery.java
diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ResourceQuery.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ResourceQuery.java
new file mode 100644 (file)
index 0000000..b76d16e
--- /dev/null
@@ -0,0 +1,63 @@
+/*******************************************************************************\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.browsing.ui.graph.impl;\r
+\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.db.request.Read;\r
+\r
+/**\r
+ * A database query which identifies itself by two fields: an abstract\r
+ * idenfitier and an INodeContext.\r
+ * \r
+ * @author Antti Villberg\r
+ * \r
+ * @param <T>\r
+ */\r
+public abstract class ResourceQuery<T> implements Read<T> {\r
+\r
+    protected final Object       queryIdentifier;\r
+    protected final NodeContext context;\r
+    protected int                hash;\r
+\r
+    public ResourceQuery(Object queryIdentifier, NodeContext context) {\r
+        assert queryIdentifier != null;\r
+        assert context != null;\r
+        this.queryIdentifier = queryIdentifier;\r
+        this.context = context;\r
+        this.hash = makeHash();\r
+    }\r
+\r
+    @Override\r
+    public boolean equals(Object object) {\r
+\r
+        if (this == object)\r
+            return true;\r
+        else if (object == null)\r
+            return false;\r
+        else if (!(object instanceof ResourceQuery<?>))\r
+            return false;\r
+\r
+        ResourceQuery<?> query = (ResourceQuery<?>) object;\r
+        return getClass() == query.getClass() && queryIdentifier.equals(query.queryIdentifier) && context.equals(query.context);\r
+\r
+    }\r
+\r
+    protected int makeHash() {\r
+        return getClass().hashCode() * 31 + context.hashCode() * 41 + queryIdentifier.hashCode();\r
+    }\r
+\r
+    @Override\r
+    final public int hashCode() {\r
+        return hash;\r
+    }\r
+\r
+}\r