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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.diagram.adapter;
\r
14 import org.simantics.db.request.Read;
\r
15 import org.simantics.g2d.canvas.ICanvasContext;
\r
18 * A base for synchronous requests performed by
\r
19 * {@link GraphToDiagramSynchronizer}.
\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
27 * @param <T> type of stored data element
\r
28 * @param <Result> query result type
\r
30 abstract class BaseRequest<T, Result> implements Read<Result> {
\r
32 final protected T data;
\r
36 final ICanvasContext canvas;
\r
38 public BaseRequest(ICanvasContext canvas, T data) {
\r
39 this.canvas = canvas;
\r
40 assert canvas != null;
\r
41 assert data != null;
\r
43 this.hash = data.hashCode() + 31 * canvas.hashCode();
\r
47 public int hashCode() {
\r
52 public boolean equals(Object other) {
\r
55 if (other == null || getClass() != other.getClass())
\r
57 BaseRequest<?, ?> o = (BaseRequest<?, ?>) other;
\r
58 return data.equals(o.data) && canvas.equals(o.canvas);
\r
62 public String toString() {
\r
63 return getClass().getSimpleName() + "[" + data + " - " + canvas.hashCode() + "]";
\r