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