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