]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.browsing.ui.graph.impl;\r
13 \r
14 import org.simantics.browsing.ui.NodeContext;\r
15 import org.simantics.db.request.Read;\r
16 \r
17 /**\r
18  * A database query which identifies itself by two fields: an abstract\r
19  * idenfitier and an INodeContext.\r
20  * \r
21  * @author Antti Villberg\r
22  * \r
23  * @param <T>\r
24  */\r
25 public abstract class ResourceQuery<T> implements Read<T> {\r
26 \r
27     protected final Object       queryIdentifier;\r
28     protected final NodeContext context;\r
29     protected int                hash;\r
30 \r
31     public ResourceQuery(Object queryIdentifier, NodeContext context) {\r
32         assert queryIdentifier != null;\r
33         assert context != null;\r
34         this.queryIdentifier = queryIdentifier;\r
35         this.context = context;\r
36         this.hash = makeHash();\r
37     }\r
38 \r
39     @Override\r
40     public boolean equals(Object object) {\r
41 \r
42         if (this == object)\r
43             return true;\r
44         else if (object == null)\r
45             return false;\r
46         else if (!(object instanceof ResourceQuery<?>))\r
47             return false;\r
48 \r
49         ResourceQuery<?> query = (ResourceQuery<?>) object;\r
50         return getClass() == query.getClass() && queryIdentifier.equals(query.queryIdentifier) && context.equals(query.context);\r
51 \r
52     }\r
53 \r
54     protected int makeHash() {\r
55         return getClass().hashCode() * 31 + context.hashCode() * 41 + queryIdentifier.hashCode();\r
56     }\r
57 \r
58     @Override\r
59     final public int hashCode() {\r
60         return hash;\r
61     }\r
62 \r
63 }\r