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