]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/BaseRequest.java
Logger fixes after merge commit:fdbe8762
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / adapter / BaseRequest.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.diagram.adapter;\r
13 \r
14 import org.simantics.db.request.Read;\r
15 import org.simantics.g2d.canvas.ICanvasContext;\r
16 \r
17 /**\r
18  * A base for synchronous requests performed by\r
19  * {@link GraphToDiagramSynchronizer}.\r
20  * \r
21  * <p>\r
22  * Takes care of making this request unique for this\r
23  * {@link GraphToDiagramSynchronizer} instances by making the active\r
24  * {@link ICanvasContext} a part of the requests identity.\r
25  * </p>\r
26  * \r
27  * @param <T> type of stored data element\r
28  * @param <Result> query result type\r
29  */\r
30 abstract class BaseRequest<T, Result> implements Read<Result> {\r
31 \r
32     final protected T    data;\r
33 \r
34     final int            hash;\r
35 \r
36     final ICanvasContext canvas;\r
37 \r
38     public BaseRequest(ICanvasContext canvas, T data) {\r
39         this.canvas = canvas;\r
40         assert canvas != null;\r
41         assert data != null;\r
42         this.data = data;\r
43         this.hash = data.hashCode() + 31 * canvas.hashCode();\r
44     }\r
45 \r
46     @Override\r
47     public int hashCode() {\r
48         return hash;\r
49     }\r
50 \r
51     @Override\r
52     public boolean equals(Object other) {\r
53         if (this == other)\r
54             return true;\r
55         if (other == null || getClass() != other.getClass())\r
56             return false;\r
57         BaseRequest<?, ?> o = (BaseRequest<?, ?>) other;\r
58         return data.equals(o.data) && canvas.equals(o.canvas);\r
59     }\r
60 \r
61     @Override\r
62     public String toString() {\r
63         return getClass().getSimpleName() + "[" + data + " - " + canvas.hashCode() + "]";\r
64     }\r
65 \r
66 }