* @author Robert Varga
*/
@Beta
-public final class Decimal64 extends Number implements Comparable<Decimal64>, Immutable {
+public class Decimal64 extends Number implements Comparable<Decimal64>, Immutable {
private static final long serialVersionUID = 1L;
private static final int MAX_FRACTION_DIGITS = 18;
this.value = negative ? -bits : bits;
}
+ protected Decimal64(final Decimal64 other) {
+ this.scaleOffset = other.scaleOffset;
+ this.value = other.value;
+ }
+
public static Decimal64 valueOf(final byte byteVal) {
return byteVal < 0 ? new Decimal64(1, -byteVal, 0, true) : new Decimal64(1, byteVal, 0, false);
}
return new Decimal64(fracLen, intPart, fracPart, negative);
}
- public BigDecimal decimalValue() {
+ public final BigDecimal decimalValue() {
return BigDecimal.valueOf(value, scaleOffset + 1);
}
@Override
- public int intValue() {
+ public final int intValue() {
return (int) intPart();
}
@Override
- public long longValue() {
+ public final long longValue() {
return intPart();
}
@Override
- public float floatValue() {
+ public final float floatValue() {
return (float) doubleValue();
}
@Override
- public double doubleValue() {
+ public final double doubleValue() {
return 1.0 * value / SCALE[scaleOffset];
}
* @return this {@code Decimal64} converted to a {@code byte}.
* @throws ArithmeticException if {@code this} has a nonzero fractional part, or will not fit in a {@code byte}.
*/
- public byte byteValueExact() {
+ public final byte byteValueExact() {
final long val = longValueExact();
final byte ret = (byte) val;
if (val != ret) {
* @return this {@code Decimal64} converted to a {@code short}.
* @throws ArithmeticException if {@code this} has a nonzero fractional part, or will not fit in a {@code short}.
*/
- public short shortValueExact() {
+ public final short shortValueExact() {
final long val = longValueExact();
final short ret = (short) val;
if (val != ret) {
* @return this {@code Decimal64} converted to an {@code int}.
* @throws ArithmeticException if {@code this} has a nonzero fractional part, or will not fit in an {@code int}.
*/
- public int intValueExact() {
+ public final int intValueExact() {
final long val = longValueExact();
final int ret = (int) val;
if (val != ret) {
* @return this {@code Decimal64} converted to a {@code long}.
* @throws ArithmeticException if {@code this} has a nonzero fractional part.
*/
- public long longValueExact() {
+ public final long longValueExact() {
if (fracPart() != 0) {
throw new ArithmeticException("Conversion of " + this + " would lose fraction");
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public int compareTo(final Decimal64 o) {
+ public final int compareTo(final Decimal64 o) {
if (this == o) {
return 0;
}
}
@Override
- public int hashCode() {
+ public final int hashCode() {
// We need to normalize the results in order to be consistent with equals()
return Long.hashCode(intPart()) * 31 + Long.hashCode(fracPart());
}
@Override
- public boolean equals(final Object obj) {
+ public final boolean equals(final Object obj) {
if (this == obj) {
return true;
}
}
@Override
- public String toString() {
+ public final String toString() {
// https://tools.ietf.org/html/rfc6020#section-9.3.2
//
// The canonical form of a positive decimal64 does not include the sign
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.annotations.Beta;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
* @author Robert Varga
*/
@Beta
-public final class Uint16 extends Number implements Comparable<Uint16>, Immutable {
+public class Uint16 extends Number implements Comparable<Uint16>, Immutable {
private static final long serialVersionUID = 1L;
private static final int MIN_VALUE = 0;
private static final int MAX_VALUE = 65535;
private final short value;
- @VisibleForTesting
Uint16(final short value) {
this.value = value;
}
+ protected Uint16(final Uint16 other) {
+ this.value = other.value;
+ }
+
private static Uint16 instanceFor(final short value) {
final int slot = Short.toUnsignedInt(value);
if (slot >= CACHE.length) {
}
@Override
- public short shortValue() {
+ public final short shortValue() {
return value;
}
@Override
- public int intValue() {
+ public final int intValue() {
return Short.toUnsignedInt(value);
}
@Override
- public long longValue() {
+ public final long longValue() {
return Short.toUnsignedLong(value);
}
@Override
- public float floatValue() {
+ public final float floatValue() {
return intValue();
}
@Override
- public double doubleValue() {
+ public final double doubleValue() {
return intValue();
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public int compareTo(final Uint16 o) {
+ public final int compareTo(final Uint16 o) {
return Integer.compare(intValue(), o.intValue());
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Short.hashCode(value);
}
@Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
-
- return obj instanceof Uint16 && value == ((Uint16)obj).value;
+ public final boolean equals(final Object obj) {
+ return this == obj || obj instanceof Uint16 && value == ((Uint16)obj).value;
}
@Override
- public String toString() {
+ public final String toString() {
return String.valueOf(intValue());
}
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.annotations.Beta;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
* @author Robert Varga
*/
@Beta
-public final class Uint32 extends Number implements Comparable<Uint32>, Immutable {
+public class Uint32 extends Number implements Comparable<Uint32>, Immutable {
private static final long serialVersionUID = 1L;
private static final long MIN_VALUE = 0;
private static final long MAX_VALUE = 0xffffffffL;
private final int value;
- @VisibleForTesting
Uint32(final int value) {
this.value = value;
}
+ protected Uint32(final Uint32 other) {
+ this.value = other.value;
+ }
+
private static Uint32 instanceFor(final int value) {
final long longSlot = Integer.toUnsignedLong(value);
if (longSlot >= CACHE.length) {
}
@Override
- public int intValue() {
+ public final int intValue() {
return value;
}
@Override
- public long longValue() {
+ public final long longValue() {
return Integer.toUnsignedLong(value);
}
@Override
- public float floatValue() {
+ public final float floatValue() {
return longValue();
}
@Override
- public double doubleValue() {
+ public final double doubleValue() {
return longValue();
}
- public UnsignedInteger toUnsignedInteger() {
+ public final UnsignedInteger toUnsignedInteger() {
return UnsignedInteger.fromIntBits(value);
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public int compareTo(final Uint32 o) {
+ public final int compareTo(final Uint32 o) {
return Integer.compareUnsigned(value, o.value);
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Integer.hashCode(value);
}
@Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
-
- return obj instanceof Uint32 && value == ((Uint32)obj).value;
+ public final boolean equals(final Object obj) {
+ return this == obj || obj instanceof Uint32 && value == ((Uint32)obj).value;
}
@Override
- public String toString() {
+ public final String toString() {
return Integer.toUnsignedString(value);
}
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.annotations.Beta;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
* @author Robert Varga
*/
@Beta
-public final class Uint64 extends Number implements Comparable<Uint64>, Immutable {
+public class Uint64 extends Number implements Comparable<Uint64>, Immutable {
private static final long serialVersionUID = 1L;
private static final long MIN_VALUE = 0;
private final long value;
- @VisibleForTesting
Uint64(final long value) {
this.value = value;
}
+ protected Uint64(final Uint64 other) {
+ this.value = other.value;
+ }
+
private static Uint64 instanceFor(final long value) {
final int slot = (int)value;
if (slot < 0 || slot >= CACHE.length) {
}
@Override
- public int intValue() {
+ public final int intValue() {
return (int)value;
}
@Override
- public long longValue() {
+ public final long longValue() {
return value;
}
@Override
- public float floatValue() {
+ public final float floatValue() {
// TODO: ditch Guava
return UnsignedLong.fromLongBits(value).floatValue();
}
@Override
- public double doubleValue() {
+ public final double doubleValue() {
// TODO: ditch Guava
return UnsignedLong.fromLongBits(value).doubleValue();
}
- public UnsignedLong toUnsignedLong() {
+ public final UnsignedLong toUnsignedLong() {
return UnsignedLong.fromLongBits(value);
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public int compareTo(final Uint64 o) {
+ public final int compareTo(final Uint64 o) {
return Long.compareUnsigned(value, o.value);
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Long.hashCode(value);
}
@Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
-
- return obj instanceof Uint64 && value == ((Uint64)obj).value;
+ public final boolean equals(final Object obj) {
+ return this == obj || obj instanceof Uint64 && value == ((Uint64)obj).value;
}
@Override
- public String toString() {
+ public final String toString() {
return Long.toUnsignedString(value);
}
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.annotations.Beta;
-import com.google.common.annotations.VisibleForTesting;
import org.opendaylight.yangtools.concepts.Immutable;
/**
* @author Robert Varga
*/
@Beta
-public final class Uint8 extends Number implements Comparable<Uint8>, Immutable {
+public class Uint8 extends Number implements Comparable<Uint8>, Immutable {
static final short MIN_VALUE = 0;
static final short MAX_VALUE = 255;
private final byte value;
- @VisibleForTesting
- Uint8(final byte value) {
+ private Uint8(final byte value) {
this.value = value;
}
+ protected Uint8(final Uint8 other) {
+ this.value = other.value;
+ }
+
private static Uint8 instanceFor(final byte value) {
final int slot = Byte.toUnsignedInt(value);
}
@Override
- public byte byteValue() {
+ public final byte byteValue() {
return value;
}
@Override
- public int intValue() {
+ public final int intValue() {
return Byte.toUnsignedInt(value);
}
@Override
- public long longValue() {
+ public final long longValue() {
return Byte.toUnsignedLong(value);
}
@Override
- public float floatValue() {
+ public final float floatValue() {
return intValue();
}
@Override
- public double doubleValue() {
+ public final double doubleValue() {
return intValue();
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public int compareTo(final Uint8 o) {
+ public final int compareTo(final Uint8 o) {
return intValue() - o.intValue();
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Byte.hashCode(value);
}
@Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
-
- return obj instanceof Uint8 && value == ((Uint8)obj).value;
+ public final boolean equals(final Object obj) {
+ return this == obj || obj instanceof Uint8 && value == ((Uint8)obj).value;
}
@Override
- public String toString() {
+ public final String toString() {
return String.valueOf(intValue());
}
final Uint16 zero = Uint16.valueOf(0);
final Uint16 max = Uint16.valueOf(65535);
- final Uint16 test = new Uint16((short) 5);
+ final Uint16 test = new Uint16(five);
assertFalse(test.equals(zero));
assertFalse(test.equals(new Object()));
assertFalse(test.equals(max));
final Uint32 zero = Uint32.valueOf(0);
final Uint32 max = Uint32.valueOf(4294967295L);
- final Uint32 test = new Uint32(5);
+ final Uint32 test = new Uint32(five);
assertFalse(test.equals(zero));
assertFalse(test.equals(new Object()));
assertFalse(test.equals(max));
final Uint64 zero = Uint64.valueOf(0);
final Uint64 max = Uint64.valueOf(4294967295L);
- final Uint64 test = new Uint64(5);
+ final Uint64 test = new Uint64(five);
assertFalse(test.equals(zero));
assertFalse(test.equals(new Object()));
assertFalse(test.equals(max));
final Uint8 zero = Uint8.valueOf(0);
final Uint8 max = Uint8.valueOf(255);
- final Uint8 test = new Uint8((byte) 5);
+ final Uint8 test = new Uint8(five);
assertFalse(test.equals(zero));
assertFalse(test.equals(new Object()));
assertFalse(test.equals(max));