package org.simantics.interop.mapping.data; import java.util.ArrayList; import java.util.Collection; public class ObjectIdentifiable implements Identifiable { private Object obj; public ObjectIdentifiable(Object obj) { this.obj = obj; } public Object getObject() { return obj; } @SuppressWarnings("unchecked") @Override public T getAdapter(Class clazz) { if (clazz == String.class) return (T)obj.toString(); return null; } @Override public int hashCode() { return obj.hashCode(); } @Override public boolean equals(Object arg0) { if (arg0 == null) return false; if (this.getClass() != arg0.getClass()) return false; ObjectIdentifiable other = (ObjectIdentifiable)arg0; return obj.equals(other.obj); } @Override public Identifiable merge(Identifiable other) { if (other instanceof ObjectIdentifiable) { ObjectSetIdentifiable i = new ObjectSetIdentifiable(this.obj,((ObjectIdentifiable)other).obj); return i; } else if (other instanceof ObjectSetIdentifiable) { Collection coll = new ArrayList(); coll.add(this.obj); coll.addAll(((ObjectSetIdentifiable)other).getObjects()); ObjectSetIdentifiable i = new ObjectSetIdentifiable(coll); return i; } return null; } }