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.symbolcontribution;
14 import org.eclipse.core.runtime.IAdaptable;
17 * @author Tuukka Lehtonen
19 public abstract class IdentifiedObject implements IAdaptable, IIdentifiedObject {
20 Object identification;
22 public IdentifiedObject(Object identification) {
23 if (identification == null)
24 throw new NullPointerException("null identification");
25 this.identification = identification;
29 public Object getId() {
30 return identification;
34 public int hashCode() {
35 return identification.hashCode();
39 public boolean equals(Object obj) {
44 if (!(obj instanceof IdentifiedObject))
46 IdentifiedObject other = (IdentifiedObject) obj;
47 return identification.equals(other.identification);
50 @SuppressWarnings("unchecked")
51 protected <T> T adapt(Class<T> clazz) {
52 if (clazz.isInstance(identification))
53 return (T) identification;
54 if (identification instanceof IAdaptable)
55 return (T) ((IAdaptable) identification).getAdapter(clazz);
59 @SuppressWarnings("rawtypes")
61 public Object getAdapter(Class adapter) {
62 if (adapter.isInstance(identification))
63 return identification;
64 if (identification instanceof IAdaptable)
65 return ((IAdaptable) identification).getAdapter(adapter);
70 public String toString() {
71 return getClass().getSimpleName() + "[id=" + identification + "]";