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