]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/IntArray.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / IntArray.java
index 8770b4d49d27a196da2e63fd456623d9c4c7f46a..6ee30ad70fd1d341930f11c35eabe2ecdf69af87 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.impl.query;\r
-\r
-import java.util.Arrays;\r
-\r
-\r
-final public class IntArray {\r
-\r
-       public static IntArray EMPTY = new IntArray();\r
-       \r
-    public int[] data;\r
-\r
-    /** the index after the last entry in the list */\r
-    public int sizeOrData;\r
-\r
-    /** the default capacity for new lists */\r
-    protected static final int DEFAULT_CAPACITY = 3;\r
-\r
-    protected static final int NO_DATA = -1;\r
-\r
-    public IntArray() {\r
-        data = null;\r
-        sizeOrData = NO_DATA;\r
-    }\r
-\r
-    /**\r
-     * Returns the number of values in the list.\r
-     *\r
-     * @return the number of values in the list.\r
-     */\r
-    public int size() {\r
-        return data != null ? sizeOrData : (sizeOrData != NO_DATA ? 1 : 0);\r
-    }\r
-\r
-    /**\r
-     * Tests whether this list contains any values.\r
-     *\r
-     * @return true if the list is empty.\r
-     */\r
-    public boolean isEmpty() {\r
-        return sizeOrData == NO_DATA;\r
-    }\r
-\r
-//    /**\r
-//     * Sheds any excess capacity above and beyond the current size of\r
-//     * the list.\r
-//     */\r
-//    public void trimToSize() {\r
-//        if (_data.length > size()) {\r
-//            int[] tmp = new int[size()];\r
-//            toNativeArray(tmp, 0, tmp.length);\r
-//            _data = tmp;\r
-//        }\r
-//    }\r
-\r
-    // modifying\r
-\r
-    public void trim() {\r
-       if(data != null) {\r
-               int[] newData = new int[sizeOrData];\r
-               System.arraycopy(data, 0, newData, 0, sizeOrData);\r
-               data = newData;\r
-       }\r
-    }\r
-    \r
-    /**\r
-     * Adds <tt>val</tt> to the end of the list, growing as needed.\r
-     *\r
-     * @param val an <code>int</code> value\r
-     */\r
-    public void add(int val) {\r
-        if(data == null) {\r
-            if(sizeOrData == NO_DATA) {\r
-                sizeOrData = val;\r
-            } else {\r
-                data = new int[DEFAULT_CAPACITY];\r
-                data[0] = sizeOrData;\r
-                data[1] = val;\r
-                sizeOrData = 2;\r
-            }\r
-        } else {\r
-            if(data.length == sizeOrData) {\r
-                int newCap = data.length << 1;\r
-                int[] tmp = new int[newCap];\r
-                System.arraycopy(data, 0, tmp, 0, data.length);\r
-                data = tmp;\r
-                data[sizeOrData++] = val;\r
-            } else {\r
-                data[sizeOrData++] = val;\r
-            }\r
-        }\r
-    }\r
-    \r
-    int[] toArray() {\r
-       int size = size();\r
-       int[] result = new int[size];\r
-       if(size == 1) {\r
-               result[0] = sizeOrData; \r
-       } else {\r
-            System.arraycopy(data, 0, result, 0, size);\r
-       }\r
-       return result;\r
-    }\r
-    \r
-    @Override\r
-    public boolean equals(Object object) {\r
-        if (this == object)\r
-            return true;\r
-        else if (object == null)\r
-            return false;\r
-        else if (IntArray.class != object.getClass())\r
-            return false;\r
-        IntArray r = (IntArray)object;\r
-//        System.out.println("equals " + this + " vs. " + r);\r
-        return sizeOrData == r.sizeOrData && Arrays.equals(data, r.data);\r
-    }\r
-    \r
-    @Override\r
-    public String toString() {\r
-        return "IntArray " + sizeOrData + " " + Arrays.toString(data);\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.impl.query;
+
+import java.util.Arrays;
+
+
+final public class IntArray {
+
+       public static IntArray EMPTY = new IntArray();
+       
+    public int[] data;
+
+    /** the index after the last entry in the list */
+    public int sizeOrData;
+
+    /** the default capacity for new lists */
+    protected static final int DEFAULT_CAPACITY = 3;
+
+    protected static final int NO_DATA = -1;
+
+    public IntArray() {
+        data = null;
+        sizeOrData = NO_DATA;
+    }
+
+    /**
+     * Returns the number of values in the list.
+     *
+     * @return the number of values in the list.
+     */
+    public int size() {
+        return data != null ? sizeOrData : (sizeOrData != NO_DATA ? 1 : 0);
+    }
+
+    /**
+     * Tests whether this list contains any values.
+     *
+     * @return true if the list is empty.
+     */
+    public boolean isEmpty() {
+        return sizeOrData == NO_DATA;
+    }
+
+//    /**
+//     * Sheds any excess capacity above and beyond the current size of
+//     * the list.
+//     */
+//    public void trimToSize() {
+//        if (_data.length > size()) {
+//            int[] tmp = new int[size()];
+//            toNativeArray(tmp, 0, tmp.length);
+//            _data = tmp;
+//        }
+//    }
+
+    // modifying
+
+    public void trim() {
+       if(data != null) {
+               int[] newData = new int[sizeOrData];
+               System.arraycopy(data, 0, newData, 0, sizeOrData);
+               data = newData;
+       }
+    }
+    
+    /**
+     * Adds <tt>val</tt> to the end of the list, growing as needed.
+     *
+     * @param val an <code>int</code> value
+     */
+    public void add(int val) {
+        if(data == null) {
+            if(sizeOrData == NO_DATA) {
+                sizeOrData = val;
+            } else {
+                data = new int[DEFAULT_CAPACITY];
+                data[0] = sizeOrData;
+                data[1] = val;
+                sizeOrData = 2;
+            }
+        } else {
+            if(data.length == sizeOrData) {
+                int newCap = data.length << 1;
+                int[] tmp = new int[newCap];
+                System.arraycopy(data, 0, tmp, 0, data.length);
+                data = tmp;
+                data[sizeOrData++] = val;
+            } else {
+                data[sizeOrData++] = val;
+            }
+        }
+    }
+    
+    int[] toArray() {
+       int size = size();
+       int[] result = new int[size];
+       if(size == 1) {
+               result[0] = sizeOrData; 
+       } else {
+            System.arraycopy(data, 0, result, 0, size);
+       }
+       return result;
+    }
+    
+    @Override
+    public boolean equals(Object object) {
+        if (this == object)
+            return true;
+        else if (object == null)
+            return false;
+        else if (IntArray.class != object.getClass())
+            return false;
+        IntArray r = (IntArray)object;
+//        System.out.println("equals " + this + " vs. " + r);
+        return sizeOrData == r.sizeOrData && Arrays.equals(data, r.data);
+    }
+    
+    @Override
+    public String toString() {
+        return "IntArray " + sizeOrData + " " + Arrays.toString(data);
+    }
+    
 }
\ No newline at end of file