]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src/org/simantics/databoard/primitives/UnsignedShort.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / primitives / UnsignedShort.java
index 158b57bdf4a32a7e1f34aed7455eeb4e22630b3c..3f40370f16d05189f8ae1995a2217c43676b638b 100644 (file)
-package org.simantics.databoard.primitives;\r
-\r
-\r
-/**\r
- * Unsigned 16-bit integer value. The value is between 0 and 65535.\r
- *\r
- * @author Toni Kalajainen <toni.kalajainen@iki.fi>\r
- */\r
-public abstract class UnsignedShort extends Number implements Comparable<Number> {\r
-\r
-       private static final long serialVersionUID = 1L;\r
-\r
-       public static final UnsignedShort MIN_VALUE, MAX_VALUE, ZERO;\r
-       \r
-       static long MASK = 0xFFFFl;\r
-       public static final long L_MAX_VALUE = 0xFFFFL;\r
-       public static final long L_MIN_VALUE = 0;\r
-\r
-       /** Value container */\r
-       int value;\r
-\r
-    public static UnsignedShort valueOf(long value) {\r
-               if (value>=0 && value<CACHE.length) return CACHE[(int)value];\r
-               return new UnsignedShort.Immutable(value);      \r
-    }\r
-               \r
-    public static UnsignedShort fromBits(int intBits) {\r
-               if (intBits>=0 && intBits<CACHE.length) return CACHE[intBits];\r
-       UnsignedShort result = new UnsignedShort.Immutable();\r
-       result.value = intBits & 0xFFFF;\r
-       return result;\r
-    }          \r
-\r
-       public static class Mutable extends UnsignedShort {\r
-\r
-               private static final long serialVersionUID = 1L;\r
-\r
-               Mutable() {}\r
-               \r
-           public Mutable(int value) throws IllegalArgumentException {\r
-               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");\r
-               this.value = value;\r
-           }\r
-\r
-           public Mutable(long value) throws IllegalArgumentException {\r
-               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");\r
-               this.value = (int) value;\r
-           }\r
-\r
-           public Mutable(String stringValue) throws IllegalArgumentException {\r
-               long value = Long.parseLong(stringValue);\r
-               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");\r
-               this.value = (int) value;\r
-           }   \r
-                   \r
-           public static UnsignedShort fromBits(int intBits) {\r
-               UnsignedShort result = new Mutable();\r
-               result.value = intBits & 0xFFFF;\r
-               return result;\r
-           }               \r
-           \r
-           public void setBits(int intBits) {\r
-               this.value = intBits;\r
-           }\r
-           \r
-           public void setValue(int value) {\r
-               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");\r
-               this.value = value;\r
-           }\r
-           \r
-           public void setValue(long value) {\r
-               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");\r
-               this.value = (int) value;\r
-           }       \r
-               \r
-       }\r
-\r
-       public static class Immutable extends UnsignedShort {\r
-\r
-               private static final long serialVersionUID = 1L;\r
-               \r
-               Immutable() {}\r
-               \r
-           public Immutable(int value) throws IllegalArgumentException {\r
-               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");\r
-               this.value = value;\r
-           }\r
-\r
-           public Immutable(long value) throws IllegalArgumentException {\r
-               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");\r
-               this.value = (int) value;\r
-           }\r
-\r
-           public Immutable(String stringValue) throws IllegalArgumentException {\r
-               long value = Long.parseLong(stringValue);\r
-               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");\r
-               this.value = (int) value;\r
-           }   \r
-                   \r
-           public static UnsignedShort fromBits(int intBits) {\r
-               UnsignedShort result = new Immutable();\r
-               result.value = intBits & 0xFFFF;\r
-               return result;\r
-           }               \r
-               \r
-       }\r
-    \r
-       \r
-    public int toBits() {\r
-       return value;\r
-    }\r
-       \r
-       @Override\r
-       public int intValue() {\r
-               return value;\r
-       }\r
-       \r
-       @Override\r
-       public long longValue() {\r
-               return value & MASK;\r
-       }\r
-       \r
-       @Override\r
-       public float floatValue() {\r
-               return value & MASK;\r
-       }\r
-       @Override\r
-       public double doubleValue() {\r
-               return value & MASK;\r
-       }\r
-       \r
-    @Override\r
-       public boolean equals(Object obj) {\r
-               if (obj == null) return false;\r
-               if (obj == this) return true;\r
-               \r
-               if (obj instanceof UnsignedShort == false) return false;\r
-               UnsignedShort other = (UnsignedShort) obj;\r
-               return value == other.value;\r
-       }\r
-    \r
-    @Override\r
-    public String toString() {\r
-        return Long.toString(value & MASK);\r
-    }\r
-    \r
-       @Override\r
-       public int compareTo(Number obj) {\r
-        return Long.signum( (value & MASK) - obj.longValue() );\r
-       }\r
-       \r
-       @Override\r
-       public int hashCode() {\r
-               return value;\r
-       }\r
-\r
-       // Initialize Cache\r
-       private static int CACHE_SIZE = 16;\r
-       private static UnsignedShort.Immutable[] CACHE;\r
-       static {\r
-               CACHE = new UnsignedShort.Immutable[CACHE_SIZE];\r
-               for (int i=0; i<CACHE_SIZE; i++) CACHE[i] = new UnsignedShort.Immutable(i);\r
-               ZERO = MIN_VALUE = CACHE[0];\r
-               MAX_VALUE = new UnsignedShort.Immutable(L_MAX_VALUE);\r
-       }\r
-\r
-}\r
+package org.simantics.databoard.primitives;
+
+
+/**
+ * Unsigned 16-bit integer value. The value is between 0 and 65535.
+ *
+ * @author Toni Kalajainen <toni.kalajainen@iki.fi>
+ */
+public abstract class UnsignedShort extends Number implements Comparable<Number> {
+
+       private static final long serialVersionUID = 1L;
+
+       public static final UnsignedShort MIN_VALUE, MAX_VALUE, ZERO;
+       
+       static long MASK = 0xFFFFl;
+       public static final long L_MAX_VALUE = 0xFFFFL;
+       public static final long L_MIN_VALUE = 0;
+
+       /** Value container */
+       int value;
+
+    public static UnsignedShort valueOf(long value) {
+               if (value>=0 && value<CACHE.length) return CACHE[(int)value];
+               return new UnsignedShort.Immutable(value);      
+    }
+               
+    public static UnsignedShort fromBits(int intBits) {
+               if (intBits>=0 && intBits<CACHE.length) return CACHE[intBits];
+       UnsignedShort result = new UnsignedShort.Immutable();
+       result.value = intBits & 0xFFFF;
+       return result;
+    }          
+
+       public static class Mutable extends UnsignedShort {
+
+               private static final long serialVersionUID = 1L;
+
+               Mutable() {}
+               
+           public Mutable(int value) throws IllegalArgumentException {
+               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");
+               this.value = value;
+           }
+
+           public Mutable(long value) throws IllegalArgumentException {
+               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");
+               this.value = (int) value;
+           }
+
+           public Mutable(String stringValue) throws IllegalArgumentException {
+               long value = Long.parseLong(stringValue);
+               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");
+               this.value = (int) value;
+           }   
+                   
+           public static UnsignedShort fromBits(int intBits) {
+               UnsignedShort result = new Mutable();
+               result.value = intBits & 0xFFFF;
+               return result;
+           }               
+           
+           public void setBits(int intBits) {
+               this.value = intBits;
+           }
+           
+           public void setValue(int value) {
+               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");
+               this.value = value;
+           }
+           
+           public void setValue(long value) {
+               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");
+               this.value = (int) value;
+           }       
+               
+       }
+
+       public static class Immutable extends UnsignedShort {
+
+               private static final long serialVersionUID = 1L;
+               
+               Immutable() {}
+               
+           public Immutable(int value) throws IllegalArgumentException {
+               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");
+               this.value = value;
+           }
+
+           public Immutable(long value) throws IllegalArgumentException {
+               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");
+               this.value = (int) value;
+           }
+
+           public Immutable(String stringValue) throws IllegalArgumentException {
+               long value = Long.parseLong(stringValue);
+               if ( value<L_MIN_VALUE || value>L_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range");
+               this.value = (int) value;
+           }   
+                   
+           public static UnsignedShort fromBits(int intBits) {
+               UnsignedShort result = new Immutable();
+               result.value = intBits & 0xFFFF;
+               return result;
+           }               
+               
+       }
+    
+       
+    public int toBits() {
+       return value;
+    }
+       
+       @Override
+       public int intValue() {
+               return value;
+       }
+       
+       @Override
+       public long longValue() {
+               return value & MASK;
+       }
+       
+       @Override
+       public float floatValue() {
+               return value & MASK;
+       }
+       @Override
+       public double doubleValue() {
+               return value & MASK;
+       }
+       
+    @Override
+       public boolean equals(Object obj) {
+               if (obj == null) return false;
+               if (obj == this) return true;
+               
+               if (obj instanceof UnsignedShort == false) return false;
+               UnsignedShort other = (UnsignedShort) obj;
+               return value == other.value;
+       }
+    
+    @Override
+    public String toString() {
+        return Long.toString(value & MASK);
+    }
+    
+       @Override
+       public int compareTo(Number obj) {
+        return Long.signum( (value & MASK) - obj.longValue() );
+       }
+       
+       @Override
+       public int hashCode() {
+               return value;
+       }
+
+       // Initialize Cache
+       private static int CACHE_SIZE = 16;
+       private static UnsignedShort.Immutable[] CACHE;
+       static {
+               CACHE = new UnsignedShort.Immutable[CACHE_SIZE];
+               for (int i=0; i<CACHE_SIZE; i++) CACHE[i] = new UnsignedShort.Immutable(i);
+               ZERO = MIN_VALUE = CACHE[0];
+               MAX_VALUE = new UnsignedShort.Immutable(L_MAX_VALUE);
+       }
+
+}