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.g2d.element.handler.impl;
\r
14 import org.simantics.g2d.element.ElementClass;
\r
15 import org.simantics.g2d.element.handler.Adapter;
\r
16 import org.simantics.utils.ObjectUtils;
\r
19 * A generic single object adapter handler for use with {@link ElementClass}.
\r
21 * @author Tuukka Lehtonen
\r
23 public class StaticObjectAdapter implements Adapter {
\r
25 private static final long serialVersionUID = -8713272704786672656L;
\r
27 private final Object object;
\r
29 public StaticObjectAdapter(Object object) {
\r
31 throw new IllegalArgumentException("null object");
\r
32 this.object = object;
\r
35 @SuppressWarnings("unchecked")
\r
37 public <T> T adapt(Class<T> toClass) {
\r
38 if (toClass == null)
\r
39 throw new IllegalArgumentException("null class");
\r
40 if (toClass.isInstance(object))
\r
46 public int hashCode() {
\r
47 return ObjectUtils.hashCode(object);
\r
51 public boolean equals(Object obj) {
\r
56 if (getClass() != obj.getClass())
\r
58 StaticObjectAdapter other = (StaticObjectAdapter) obj;
\r
59 return ObjectUtils.objectEquals(object, other.object);
\r