X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FCollectionSupportImpl.java;fp=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FCollectionSupportImpl.java;h=8b4df608f2eda9755f9636be2d5d79903d3d4ec1;hp=c8560bad89ae1257c2f0987a722f4e0fa962b7d5;hb=0d9b90834ce56b292c00b1a39850ed842c3e4d42;hpb=e5db6157fd8722c946613d4e46d7aaf6bfa92609 diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/CollectionSupportImpl.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/CollectionSupportImpl.java index c8560bad8..8b4df608f 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/CollectionSupportImpl.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/CollectionSupportImpl.java @@ -28,11 +28,8 @@ import gnu.trove.iterator.TIntIterator; import gnu.trove.list.array.TIntArrayList; import gnu.trove.map.hash.TIntIntHashMap; import gnu.trove.map.hash.TIntObjectHashMap; -import gnu.trove.map.hash.TObjectIntHashMap; import gnu.trove.procedure.TIntObjectProcedure; import gnu.trove.procedure.TIntProcedure; -import gnu.trove.procedure.TObjectIntProcedure; -import gnu.trove.procedure.TObjectProcedure; import gnu.trove.set.hash.TIntHashSet; public class CollectionSupportImpl implements CollectionSupport { @@ -117,196 +114,6 @@ public class CollectionSupportImpl implements CollectionSupport { return new IntResourceMap(session); } - static final class ObjectResourceMap implements Map { - - final private SessionImplSocket session; - final private TObjectIntHashMap backend; - - ObjectResourceMap(SessionImplSocket session) { - this.session = session; - backend = new TObjectIntHashMap(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, 0); - } - - ObjectResourceMap(SessionImplSocket session, int capacity) { - this.session = session; - backend = new TObjectIntHashMap(capacity, Constants.DEFAULT_LOAD_FACTOR, 0); - } - - @Override - public int size() { - return backend.size(); - } - @Override - public boolean isEmpty() { - return backend.isEmpty(); - } - - @Override - public boolean containsKey(Object key) { - return backend.contains(key); - } - - @Override - public boolean containsValue(Object value) { - ResourceImpl impl = (ResourceImpl) value; - return backend.containsValue(impl.id); - } - - @Override - public Resource get(Object key) { - try { - int result = backend.get(key); - if (result == 0) - return null; - return session.getResourceByKey(result); - } catch (ResourceNotFoundException e) { - e.printStackTrace(); - } - return null; - } - - @Override - public Resource put(T key, Resource value) { - ResourceImpl impl = (ResourceImpl) value; - int i = backend.put(key, impl.id); - if (i == 0) - return null; - else - try { - return session.getResourceByKey(i); - } catch (ResourceNotFoundException e) { - e.printStackTrace(); - } - return null; - } - - @Override - public Resource remove(Object key) { - throw new UnsupportedOperationException("remove not supported, structure is immutable"); - } - - @Override - public void putAll(Map map) { - @SuppressWarnings("unchecked") - ObjectResourceMap other = (ObjectResourceMap) map; - other.backend.forEachEntry(new TObjectIntProcedure() { - - @Override - public boolean execute(T a, int b) { - backend.put(a, b); - return true; - } - }); - } - - @Override - public void clear() { - throw new UnsupportedOperationException("clear not supported, structure is immutable"); - } - - @Override - public Set keySet() { - final Set result = new HashSet(); - backend.forEach(new TObjectProcedure() { - - @Override - public boolean execute(T object) { - result.add(object); - return true; - } - }); - return result; - } - - @Override - public Collection values() { - ArrayList result = new ArrayList(); - for (int key : backend.values()) { - try { - result.add(session.getResourceByKey(key)); - } catch (ResourceNotFoundException e) { - e.printStackTrace(); - } - } - return result; - } - - @Override - public Set> entrySet() { - final HashSet> result = new HashSet>(); - backend.forEachEntry(new TObjectIntProcedure() { - - @Override - public boolean execute(final T a, final int b) { - return result.add(new Map.Entry() { - - @Override - public T getKey() { - return a; - } - - @Override - public Resource getValue() { - return new ResourceImpl(session.resourceSupport, b); - } - - @Override - public Resource setValue(Resource value) { - throw new UnsupportedOperationException("Map.Entry.setValue not supported, structure is immutable"); - } - - }); - } - }); - return result; - } - - @Override - public int hashCode() { - return backend.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) { - if (obj instanceof Map) { - // Nonoptimal fallback for comparing against generic Map - Map m = (Map) obj; - if (m.size() != size()) - return false; - try { - Iterator> i = entrySet().iterator(); - while (i.hasNext()) { - Entry e = i.next(); - T key = e.getKey(); - Resource value = e.getValue(); - if (value == null) { - if (!(m.get(key)==null && m.containsKey(key))) - return false; - } else { - if (!value.equals(m.get(key))) - return false; - } - } - return true; - } catch (ClassCastException unused) { - return false; - } catch (NullPointerException unused) { - return false; - } - } - return false; - } - ObjectResourceMap other = (ObjectResourceMap) obj; - return session == other.session && backend.equals(other.backend); - } - - } - @SuppressWarnings("unchecked") @Override public T createObjectResourceMap(Class clazz) {