]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/slice/ValueRange.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.datastructures / src / org / simantics / utils / datastructures / slice / ValueRange.java
index 5e5d1e71f8ef1bc62ba1860e82ff39a71c7c8be0..aecd35b720777925afa4b866faffa573efdd6209 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.utils.datastructures.slice;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class ValueRange {\r
-\r
-    public static final ValueRange NO_RANGE = new ValueRange(0, Integer.MAX_VALUE);\r
-    public static final ValueRange EMPTY = new ValueRange(0, 0);\r
-    public static final ValueRange ONE   = new ValueRange(0, 1);\r
-    public static final ValueRange TWO   = new ValueRange(0, 2);\r
-\r
-    private final int start;\r
-    private final int size;\r
-\r
-    public static ValueRange make(int size) {\r
-        if (size == 0)\r
-            return EMPTY;\r
-        else if (size == 1)\r
-            return ONE;\r
-        else if (size == 2)\r
-            return TWO;\r
-        return new ValueRange(size);\r
-    }\r
-\r
-    public static ValueRange make(int start, int size) {\r
-        if (start == 0) {\r
-            if (size == 0)\r
-                return EMPTY;\r
-            else if (size == 1)\r
-                return ONE;\r
-            else if (size == 2)\r
-                return TWO;\r
-        }\r
-        return new ValueRange(start, size);\r
-    }\r
-\r
-    private ValueRange(int size) {\r
-        this(0, size);\r
-    }\r
-\r
-    private ValueRange(int start, int size) {\r
-        if (start < 0)\r
-            throw new IllegalArgumentException("negative range start: " + start);\r
-        if (size < 0)\r
-            throw new IllegalArgumentException("negative range size: " + size);\r
-        this.start = start;\r
-        this.size = size;\r
-    }\r
-\r
-    public boolean isEmpty() {\r
-        return size == 0;\r
-    }\r
-\r
-    public boolean isSingle() {\r
-        return size == 1;\r
-    }\r
-\r
-    public int start() {\r
-        return start;\r
-    }\r
-\r
-    public int end() {\r
-        return start + size;\r
-    }\r
-\r
-    public int size() {\r
-        return size;\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        if (isEmpty())\r
-            return "[]";\r
-        if (isSingle())\r
-            return "[" + start + "]";\r
-        return "[" + start + "-" + (start + size - 1) + "]";\r
-    }\r
-\r
-    public String toString(int offset) {\r
-        if (isEmpty())\r
-            return "[]";\r
-        if (isSingle())\r
-            return "[" + (start+offset) + "]";\r
-        return "[" + (start+offset) + "-" + (start + size - 1 + offset) + "]";\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        final int prime = 31;\r
-        int result = 1;\r
-        result = prime * result + size;\r
-        result = prime * result + start;\r
-        return result;\r
-    }\r
-\r
-    @Override\r
-    public boolean equals(Object obj) {\r
-        if (this == obj)\r
-            return true;\r
-        if (obj == null)\r
-            return false;\r
-        if (getClass() != obj.getClass())\r
-            return false;\r
-        ValueRange other = (ValueRange) obj;\r
-        return size == other.size && start == other.start;\r
-    }\r
-\r
-//    public ChildReference toChildReference() {\r
-//        if (isEmpty())\r
-//            throw new UnsupportedOperationException("cannot create a value reference for an empty range");\r
-//        if (isSingle())\r
-//            return new IndexReference(start);\r
-//        //throw new RangeReference(start, start+size-1);\r
-//        throw new UnsupportedOperationException("cannot create a value reference for a range with cardinality > 1");\r
-//    }\r
-\r
-    /**\r
-     * @return a Simantics Databoard child reference string describing this range.\r
-     */\r
-    public String toChildReferenceString() {\r
-        if (isEmpty())\r
-            throw new UnsupportedOperationException("cannot create a value reference for an empty range");\r
-        StringBuilder sb = new StringBuilder();\r
-        if (isSingle())\r
-            return sb.append("i-").append(start).toString();\r
-        // TODO: proposal: http://dev.simantics.org/index.php/Talk:Databoard_Specification\r
-        return sb.append("r-").append(start).append('-').append(start+size-1).toString();\r
-    }\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.utils.datastructures.slice;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class ValueRange {
+
+    public static final ValueRange NO_RANGE = new ValueRange(0, Integer.MAX_VALUE);
+    public static final ValueRange EMPTY = new ValueRange(0, 0);
+    public static final ValueRange ONE   = new ValueRange(0, 1);
+    public static final ValueRange TWO   = new ValueRange(0, 2);
+
+    private final int start;
+    private final int size;
+
+    public static ValueRange make(int size) {
+        if (size == 0)
+            return EMPTY;
+        else if (size == 1)
+            return ONE;
+        else if (size == 2)
+            return TWO;
+        return new ValueRange(size);
+    }
+
+    public static ValueRange make(int start, int size) {
+        if (start == 0) {
+            if (size == 0)
+                return EMPTY;
+            else if (size == 1)
+                return ONE;
+            else if (size == 2)
+                return TWO;
+        }
+        return new ValueRange(start, size);
+    }
+
+    private ValueRange(int size) {
+        this(0, size);
+    }
+
+    private ValueRange(int start, int size) {
+        if (start < 0)
+            throw new IllegalArgumentException("negative range start: " + start);
+        if (size < 0)
+            throw new IllegalArgumentException("negative range size: " + size);
+        this.start = start;
+        this.size = size;
+    }
+
+    public boolean isEmpty() {
+        return size == 0;
+    }
+
+    public boolean isSingle() {
+        return size == 1;
+    }
+
+    public int start() {
+        return start;
+    }
+
+    public int end() {
+        return start + size;
+    }
+
+    public int size() {
+        return size;
+    }
+
+    @Override
+    public String toString() {
+        if (isEmpty())
+            return "[]";
+        if (isSingle())
+            return "[" + start + "]";
+        return "[" + start + "-" + (start + size - 1) + "]";
+    }
+
+    public String toString(int offset) {
+        if (isEmpty())
+            return "[]";
+        if (isSingle())
+            return "[" + (start+offset) + "]";
+        return "[" + (start+offset) + "-" + (start + size - 1 + offset) + "]";
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + size;
+        result = prime * result + start;
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        ValueRange other = (ValueRange) obj;
+        return size == other.size && start == other.start;
+    }
+
+//    public ChildReference toChildReference() {
+//        if (isEmpty())
+//            throw new UnsupportedOperationException("cannot create a value reference for an empty range");
+//        if (isSingle())
+//            return new IndexReference(start);
+//        //throw new RangeReference(start, start+size-1);
+//        throw new UnsupportedOperationException("cannot create a value reference for a range with cardinality > 1");
+//    }
+
+    /**
+     * @return a Simantics Databoard child reference string describing this range.
+     */
+    public String toChildReferenceString() {
+        if (isEmpty())
+            throw new UnsupportedOperationException("cannot create a value reference for an empty range");
+        StringBuilder sb = new StringBuilder();
+        if (isSingle())
+            return sb.append("i-").append(start).toString();
+        // TODO: proposal: http://dev.simantics.org/index.php/Talk:Databoard_Specification
+        return sb.append("r-").append(start).append('-').append(start+size-1).toString();
+    }
+
+}