]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src/org/simantics/databoard/primitives/UnsignedByte.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / primitives / UnsignedByte.java
index 8283b68d1864437984feb70ce21c0345b9c3fc9b..ff8d82824613d1a48f05480ce54112baf8457a78 100644 (file)
-package org.simantics.databoard.primitives;\r
-\r
-\r
-\r
-/**\r
- * Unsigned 8-bit integer value. The value is between 0 and 255.\r
- *\r
- * @author Toni Kalajainen <toni.kalajainen@iki.fi>\r
- */\r
-public abstract class UnsignedByte extends Number implements Comparable<Number> {\r
-\r
-       private static final long serialVersionUID = 1L;\r
-\r
-       public static final UnsignedByte MIN_VALUE, MAX_VALUE, ZERO;\r
-       \r
-       static long MASK = 0xFFl;\r
-       public static final long L_MAX_VALUE = 0xFFL;\r
-       public static final long L_MIN_VALUE = 0;\r
-\r
-       /** Value container */\r
-       int value;\r
-\r
-    public static UnsignedByte valueOf(long value) {\r
-               if (value>=0 && value<CACHE.length) return CACHE[(int)value];\r
-               return new UnsignedByte.Immutable(value);       \r
-    }\r
-    \r
-    public static UnsignedByte fromBits(int intBits) {\r
-               if (intBits>=0 && intBits<CACHE.length) return CACHE[intBits];\r
-       UnsignedByte result = new UnsignedByte.Immutable();\r
-       result.value = intBits & 0xFFFF;\r
-       return result;\r
-    }  \r
-       \r
-       public static class Mutable extends UnsignedByte {\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 Mutable fromBits(int intBits) {\r
-               Mutable result = new Mutable();\r
-               result.value = intBits;\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 final class Immutable extends UnsignedByte {\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
-       }\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 UnsignedByte == false) return false;\r
-               UnsignedByte other = (UnsignedByte) 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 UnsignedByte.Immutable[] CACHE;\r
-       static {\r
-               CACHE = new UnsignedByte.Immutable[CACHE_SIZE];\r
-               for (int i=0; i<CACHE_SIZE; i++) CACHE[i] = new UnsignedByte.Immutable(i);\r
-               ZERO = MIN_VALUE = CACHE[0];\r
-               MAX_VALUE = new UnsignedByte.Immutable(L_MAX_VALUE);\r
-       }\r
-\r
-}\r
+package org.simantics.databoard.primitives;
+
+
+
+/**
+ * Unsigned 8-bit integer value. The value is between 0 and 255.
+ *
+ * @author Toni Kalajainen <toni.kalajainen@iki.fi>
+ */
+public abstract class UnsignedByte extends Number implements Comparable<Number> {
+
+       private static final long serialVersionUID = 1L;
+
+       public static final UnsignedByte MIN_VALUE, MAX_VALUE, ZERO;
+       
+       static long MASK = 0xFFl;
+       public static final long L_MAX_VALUE = 0xFFL;
+       public static final long L_MIN_VALUE = 0;
+
+       /** Value container */
+       int value;
+
+    public static UnsignedByte valueOf(long value) {
+               if (value>=0 && value<CACHE.length) return CACHE[(int)value];
+               return new UnsignedByte.Immutable(value);       
+    }
+    
+    public static UnsignedByte fromBits(int intBits) {
+               if (intBits>=0 && intBits<CACHE.length) return CACHE[intBits];
+       UnsignedByte result = new UnsignedByte.Immutable();
+       result.value = intBits & 0xFFFF;
+       return result;
+    }  
+       
+       public static class Mutable extends UnsignedByte {
+               
+               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 Mutable fromBits(int intBits) {
+               Mutable result = new Mutable();
+               result.value = intBits;
+               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 final class Immutable extends UnsignedByte {
+
+               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 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 UnsignedByte == false) return false;
+               UnsignedByte other = (UnsignedByte) 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 UnsignedByte.Immutable[] CACHE;
+       static {
+               CACHE = new UnsignedByte.Immutable[CACHE_SIZE];
+               for (int i=0; i<CACHE_SIZE; i++) CACHE[i] = new UnsignedByte.Immutable(i);
+               ZERO = MIN_VALUE = CACHE[0];
+               MAX_VALUE = new UnsignedByte.Immutable(L_MAX_VALUE);
+       }
+
+}