X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Fprimitives%2FUnsignedByte.java;h=ff8d82824613d1a48f05480ce54112baf8457a78;hb=c69064f9e740eb4abe8448a63d306a085e036e1c;hp=8283b68d1864437984feb70ce21c0345b9c3fc9b;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/primitives/UnsignedByte.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/primitives/UnsignedByte.java index 8283b68d1..ff8d82824 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/primitives/UnsignedByte.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/primitives/UnsignedByte.java @@ -1,161 +1,161 @@ -package org.simantics.databoard.primitives; - - - -/** - * Unsigned 8-bit integer value. The value is between 0 and 255. - * - * @author Toni Kalajainen - */ -public abstract class UnsignedByte extends Number implements Comparable { - - 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=0 && intBitsL_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range"); - this.value = value; - } - - public Mutable(long value) throws IllegalArgumentException { - if ( valueL_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 ( valueL_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 ( valueL_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range"); - this.value = value; - } - - public void setValue(long value) { - if ( valueL_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 ( valueL_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range"); - this.value = value; - } - - public Immutable(long value) throws IllegalArgumentException { - if ( valueL_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 ( valueL_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 + */ +public abstract class UnsignedByte extends Number implements Comparable { + + 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=0 && intBitsL_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range"); + this.value = value; + } + + public Mutable(long value) throws IllegalArgumentException { + if ( valueL_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 ( valueL_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 ( valueL_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range"); + this.value = value; + } + + public void setValue(long value) { + if ( valueL_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 ( valueL_MAX_VALUE ) throw new IllegalArgumentException("Argument is not within range"); + this.value = value; + } + + public Immutable(long value) throws IllegalArgumentException { + if ( valueL_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 ( valueL_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