]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ForeignTable.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db.procore / src / org / simantics / db / procore / cluster / ForeignTable.java
index 6fab99615d16b03d37856580cb0c281f8ddd4cec..474e5b8a58502365d6c4f2da166a5960f125908d 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db.procore.cluster;\r
-\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.impl.ClusterI.Procedure;\r
-import org.simantics.db.impl.ClusterSupport;\r
-import org.simantics.db.impl.Modifier;\r
-import org.simantics.db.impl.Table;\r
-import org.simantics.db.impl.TableFactory;\r
-import org.simantics.db.impl.TableSizeListener;\r
-import org.simantics.db.service.ClusterUID;\r
-import org.simantics.db.service.ResourceUID;\r
-\r
-final class ForeignElement {\r
-    private static final int CLUSTER_OFFSET = 0; // resourceUID\r
-    private static final int SIZE_OF = 3;\r
-\r
-    static void constructForeign(long[] table, int index, ResourceUID resourceUID) {\r
-        int i = CLUSTER_OFFSET + index;\r
-        resourceUID.toLong(table, i);\r
-    }\r
-    static void destructForeign(long[] table, int index) {\r
-        int i = CLUSTER_OFFSET + index;\r
-        table[i++] = 0;\r
-        table[i++] = 0;\r
-        table[i++] = 0;\r
-    }\r
-    static int getSizeOf() {\r
-        return SIZE_OF;\r
-    }\r
-    static ResourceUID getResourceUID(long[] table, int index) {\r
-        int i = CLUSTER_OFFSET + index;\r
-        return new ResourceUID(table, i);\r
-    }\r
-    static void fillResourceUID(long[] table, int index, ClusterSmall cluster) {\r
-        int i = CLUSTER_OFFSET + index;\r
-        cluster.clusterUID1 = table[i];\r
-        cluster.clusterUID2 = table[i+1];\r
-        cluster.executeIndex = (short)table[i+2];\r
-    }\r
-}\r
-\r
-public final class ForeignTable extends Table<long[]>\r
-{\r
-    public ForeignTable(TableSizeListener sizeListener, int[] header, int headerBase) {\r
-        super(TableFactory.getLongFactory(), sizeListener, header, headerBase);\r
-    }\r
-    public ForeignTable(TableSizeListener sizeListener, int[] header, int headerBase, long[] longs) {\r
-        super(TableFactory.getLongFactory(), sizeListener, header, headerBase, longs);\r
-    }\r
-    public int getUsedSize() {\r
-        return getTableCount();\r
-    }\r
-    TObjectIntHashMap<ClusterUID> getHashMap()\r
-    throws DatabaseException {\r
-        int ELEMENT_SIZE = ForeignElement.getSizeOf();\r
-        final int TABLE_SIZE = getTableCount();\r
-        final int FOREIGN_COUNT = getForeignCount();\r
-        final int BASE = this.getTableBase();\r
-        final int TOP = BASE + TABLE_SIZE * ELEMENT_SIZE;\r
-        long[] table = this.getTable();\r
-        int count = 0;\r
-        int index = ZERO_SHIFT;\r
-        TObjectIntHashMap<ClusterUID> hm = new TObjectIntHashMap<ClusterUID>(FOREIGN_COUNT);\r
-        for (int i=BASE; i<TOP && count<FOREIGN_COUNT;\r
-        i+=ELEMENT_SIZE, ++index) {\r
-            if (0 == table[i] && 0 == table[i+1] && 0 == table[i+2])\r
-                continue; // element has been deleted\r
-            hm.put(ClusterUID.make(table[i], table[i+1]), index);\r
-            ++count;\r
-        }\r
-        if (FOREIGN_COUNT != hm.size())\r
-            throw new DatabaseException("Foreign table has been corrupted.");\r
-        return hm;\r
-    }\r
-    TObjectIntHashMap<ResourceUID> getResourceHashMap()\r
-    throws DatabaseException {\r
-        int ELEMENT_SIZE = ForeignElement.getSizeOf();\r
-        assert(ELEMENT_SIZE == 3);\r
-        final int TABLE_SIZE = getTableCount();\r
-        final int FOREIGN_COUNT = getForeignCount();\r
-        final int BASE = this.getTableBase();\r
-        final int TOP = BASE + TABLE_SIZE * ELEMENT_SIZE;\r
-        long[] table = this.getTable();\r
-        int count = 0;\r
-        int index = ZERO_SHIFT;\r
-        TObjectIntHashMap<ResourceUID> hm = new TObjectIntHashMap<ResourceUID>(FOREIGN_COUNT);\r
-        for (int i=BASE; i<TOP && count<FOREIGN_COUNT;\r
-        i+=ELEMENT_SIZE, ++index) {\r
-            if (0 == table[i] && 0 == table[i+1] && 0 == table[i+2])\r
-                continue; // element has been deleted\r
-            hm.put(new ResourceUID(table[i], table[i+1], table[i+2]), index);\r
-            ++count;\r
-        }\r
-        if (FOREIGN_COUNT != hm.size())\r
-            throw new DatabaseException("Foreign table has been corrupted. count=" + FOREIGN_COUNT + "size=" + hm.size());\r
-        return hm;\r
-    }\r
-    int createForeign(ResourceUID uid) {\r
-        int index = getTableCount();\r
-        int size = ForeignElement.getSizeOf();\r
-        int foreignIndex = createNewElement(size);\r
-        int realIndex = checkIndexAndGetRealIndex(foreignIndex, size);\r
-        ForeignElement.constructForeign(getTable(), realIndex, uid);\r
-        incForeignCount();\r
-        return index + ZERO_SHIFT;\r
-    }\r
-    void deleteForeign(int foreignIndex) {\r
-        int realIndex = checkIndexAndGetRealIndex(foreignIndex);\r
-        ForeignElement.destructForeign(getTable(), realIndex);\r
-        decForeignCount();\r
-    }\r
-    public final ResourceUID getResourceUID(int foreignIndex) {\r
-        return ForeignElement.getResourceUID(table, checkIndexAndGetRealIndex(foreignIndex)); \r
-    }\r
-    int getForeignCount() {\r
-        return getExtra(FOREIGN_COUNT_INDEX);\r
-    }\r
-    private static final int FOREIGN_COUNT_INDEX = 0;\r
-    private int incForeignCount() {\r
-        int count = getExtra(FOREIGN_COUNT_INDEX) + 1;\r
-        setExtra(FOREIGN_COUNT_INDEX, count);\r
-        return count;\r
-    }\r
-    private int decForeignCount() {\r
-        int count = getExtra(FOREIGN_COUNT_INDEX) - 1;\r
-        setExtra(FOREIGN_COUNT_INDEX, count);\r
-        return count;\r
-    }\r
-    private int checkIndexAndGetRealIndex(int foreignIndex) {\r
-        int index = (foreignIndex - ZERO_SHIFT) * ForeignElement.getSizeOf() + ZERO_SHIFT;\r
-        int realIndex = checkIndexAndGetRealIndex(index, ForeignElement.getSizeOf());\r
-        return realIndex;\r
-    }\r
-    @Override\r
-    public <Context> boolean foreach(int setIndex, Procedure procedure, Context context,\r
-            ClusterSupport support, Modifier modifier) throws DatabaseException {\r
-        throw new UnsupportedOperationException();\r
-    }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.procore.cluster;
+
+import gnu.trove.map.hash.TObjectIntHashMap;
+
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.impl.ClusterI.Procedure;
+import org.simantics.db.impl.ClusterSupport;
+import org.simantics.db.impl.Modifier;
+import org.simantics.db.impl.Table;
+import org.simantics.db.impl.TableFactory;
+import org.simantics.db.impl.TableSizeListener;
+import org.simantics.db.service.ClusterUID;
+import org.simantics.db.service.ResourceUID;
+
+final class ForeignElement {
+    private static final int CLUSTER_OFFSET = 0; // resourceUID
+    private static final int SIZE_OF = 3;
+
+    static void constructForeign(long[] table, int index, ResourceUID resourceUID) {
+        int i = CLUSTER_OFFSET + index;
+        resourceUID.toLong(table, i);
+    }
+    static void destructForeign(long[] table, int index) {
+        int i = CLUSTER_OFFSET + index;
+        table[i++] = 0;
+        table[i++] = 0;
+        table[i++] = 0;
+    }
+    static int getSizeOf() {
+        return SIZE_OF;
+    }
+    static ResourceUID getResourceUID(long[] table, int index) {
+        int i = CLUSTER_OFFSET + index;
+        return new ResourceUID(table, i);
+    }
+    static void fillResourceUID(long[] table, int index, ClusterSmall cluster) {
+        int i = CLUSTER_OFFSET + index;
+        cluster.clusterUID1 = table[i];
+        cluster.clusterUID2 = table[i+1];
+        cluster.executeIndex = (short)table[i+2];
+    }
+}
+
+public final class ForeignTable extends Table<long[]>
+{
+    public ForeignTable(TableSizeListener sizeListener, int[] header, int headerBase) {
+        super(TableFactory.getLongFactory(), sizeListener, header, headerBase);
+    }
+    public ForeignTable(TableSizeListener sizeListener, int[] header, int headerBase, long[] longs) {
+        super(TableFactory.getLongFactory(), sizeListener, header, headerBase, longs);
+    }
+    public int getUsedSize() {
+        return getTableCount();
+    }
+    TObjectIntHashMap<ClusterUID> getHashMap()
+    throws DatabaseException {
+        int ELEMENT_SIZE = ForeignElement.getSizeOf();
+        final int TABLE_SIZE = getTableCount();
+        final int FOREIGN_COUNT = getForeignCount();
+        final int BASE = this.getTableBase();
+        final int TOP = BASE + TABLE_SIZE * ELEMENT_SIZE;
+        long[] table = this.getTable();
+        int count = 0;
+        int index = ZERO_SHIFT;
+        TObjectIntHashMap<ClusterUID> hm = new TObjectIntHashMap<ClusterUID>(FOREIGN_COUNT);
+        for (int i=BASE; i<TOP && count<FOREIGN_COUNT;
+        i+=ELEMENT_SIZE, ++index) {
+            if (0 == table[i] && 0 == table[i+1] && 0 == table[i+2])
+                continue; // element has been deleted
+            hm.put(ClusterUID.make(table[i], table[i+1]), index);
+            ++count;
+        }
+        if (FOREIGN_COUNT != hm.size())
+            throw new DatabaseException("Foreign table has been corrupted.");
+        return hm;
+    }
+    TObjectIntHashMap<ResourceUID> getResourceHashMap()
+    throws DatabaseException {
+        int ELEMENT_SIZE = ForeignElement.getSizeOf();
+        assert(ELEMENT_SIZE == 3);
+        final int TABLE_SIZE = getTableCount();
+        final int FOREIGN_COUNT = getForeignCount();
+        final int BASE = this.getTableBase();
+        final int TOP = BASE + TABLE_SIZE * ELEMENT_SIZE;
+        long[] table = this.getTable();
+        int count = 0;
+        int index = ZERO_SHIFT;
+        TObjectIntHashMap<ResourceUID> hm = new TObjectIntHashMap<ResourceUID>(FOREIGN_COUNT);
+        for (int i=BASE; i<TOP && count<FOREIGN_COUNT;
+        i+=ELEMENT_SIZE, ++index) {
+            if (0 == table[i] && 0 == table[i+1] && 0 == table[i+2])
+                continue; // element has been deleted
+            hm.put(new ResourceUID(table[i], table[i+1], table[i+2]), index);
+            ++count;
+        }
+        if (FOREIGN_COUNT != hm.size())
+            throw new DatabaseException("Foreign table has been corrupted. count=" + FOREIGN_COUNT + "size=" + hm.size());
+        return hm;
+    }
+    int createForeign(ResourceUID uid) {
+        int index = getTableCount();
+        int size = ForeignElement.getSizeOf();
+        int foreignIndex = createNewElement(size);
+        int realIndex = checkIndexAndGetRealIndex(foreignIndex, size);
+        ForeignElement.constructForeign(getTable(), realIndex, uid);
+        incForeignCount();
+        return index + ZERO_SHIFT;
+    }
+    void deleteForeign(int foreignIndex) {
+        int realIndex = checkIndexAndGetRealIndex(foreignIndex);
+        ForeignElement.destructForeign(getTable(), realIndex);
+        decForeignCount();
+    }
+    public final ResourceUID getResourceUID(int foreignIndex) {
+        return ForeignElement.getResourceUID(table, checkIndexAndGetRealIndex(foreignIndex)); 
+    }
+    int getForeignCount() {
+        return getExtra(FOREIGN_COUNT_INDEX);
+    }
+    private static final int FOREIGN_COUNT_INDEX = 0;
+    private int incForeignCount() {
+        int count = getExtra(FOREIGN_COUNT_INDEX) + 1;
+        setExtra(FOREIGN_COUNT_INDEX, count);
+        return count;
+    }
+    private int decForeignCount() {
+        int count = getExtra(FOREIGN_COUNT_INDEX) - 1;
+        setExtra(FOREIGN_COUNT_INDEX, count);
+        return count;
+    }
+    private int checkIndexAndGetRealIndex(int foreignIndex) {
+        int index = (foreignIndex - ZERO_SHIFT) * ForeignElement.getSizeOf() + ZERO_SHIFT;
+        int realIndex = checkIndexAndGetRealIndex(index, ForeignElement.getSizeOf());
+        return realIndex;
+    }
+    @Override
+    public <Context> boolean foreach(int setIndex, Procedure procedure, Context context,
+            ClusterSupport support, Modifier modifier) throws DatabaseException {
+        throw new UnsupportedOperationException();
+    }
+}