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