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