]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/PossibleAdapter.java
61a47ecb12a96443620f5c546b29bc2fda50813d
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / primitiverequest / PossibleAdapter.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.db.common.primitiverequest;
13
14 import org.simantics.db.AsyncReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.procedure.AsyncProcedure;
17 import org.simantics.db.request.AsyncRead;
18
19 final public class PossibleAdapter<T> implements AsyncRead<T> {
20
21         final private Resource resource;
22     final private Class<T> clazz;
23     
24     @Override
25     public int hashCode() {
26         return resource.hashCode() + 31 * clazz.hashCode();
27     }
28     
29     @Override
30     public boolean equals(Object object) {
31         if (this == object)
32             return true;
33         else if (object == null)
34             return false;
35         else if (getClass() != object.getClass())
36             return false;
37         PossibleAdapter<?> r = (PossibleAdapter<?>)object;
38         return resource.equals(r.resource) && clazz.equals(r.clazz);
39     }
40
41     @Override
42     public int threadHash() {
43         return hashCode();
44     }
45
46     @Override
47     public int getFlags() {
48         return 0;
49     }
50     
51     public PossibleAdapter(Resource resource, Class<T> clazz) {
52         this.resource = resource;
53         this.clazz = clazz;
54     }
55
56     @Override
57     public void perform(AsyncReadGraph graph, AsyncProcedure<T> procedure) {
58         
59         graph.forPossibleAdapted(resource, clazz, procedure);
60         
61     }
62
63 }