# HG changeset patch # User mduigou # Date 1352329181 28800 # Node ID fb04d6175edb8e89285623c29c73cac7db815ec6 # Parent 7d50ff0e2d44a5144026b795bae34b2f1289ef7d 7088952: Add size in bytes constant "BYTES" to primitive type wrapper types Summary: Adds a constant BYTES to each of the primitive wrapper classes (Byte, Character, Double, Float, Integer, Long, Short) with the calculation Primitive.SIZE / Byte.SIZE already made. Reviewed-by: smarks, darcy diff --git a/src/share/classes/java/lang/Byte.java b/src/share/classes/java/lang/Byte.java --- a/src/share/classes/java/lang/Byte.java +++ b/src/share/classes/java/lang/Byte.java @@ -494,6 +494,14 @@ */ public static final int SIZE = 8; + /** + * The number of bytes used to represent a {@code byte} value in two's + * complement binary form. + * + * @since 1.8 + */ + public static final int BYTES = SIZE / Byte.SIZE; + /** use serialVersionUID from JDK 1.1. for interoperability */ private static final long serialVersionUID = -7183698231559129828L; } diff --git a/src/share/classes/java/lang/Character.java b/src/share/classes/java/lang/Character.java --- a/src/share/classes/java/lang/Character.java +++ b/src/share/classes/java/lang/Character.java @@ -7158,6 +7158,14 @@ public static final int SIZE = 16; /** + * The number of bytes used to represent a {@code char} value in unsigned + * binary form. + * + * @since 1.8 + */ + public static final int BYTES = SIZE / Byte.SIZE; + + /** * Returns the value obtained by reversing the order of the bytes in the * specified char value. * diff --git a/src/share/classes/java/lang/Double.java b/src/share/classes/java/lang/Double.java --- a/src/share/classes/java/lang/Double.java +++ b/src/share/classes/java/lang/Double.java @@ -123,6 +123,13 @@ public static final int SIZE = 64; /** + * The number of bytes used to represent a {@code double} value. + * + * @since 1.8 + */ + public static final int BYTES = SIZE / Byte.SIZE; + + /** * The {@code Class} instance representing the primitive type * {@code double}. * diff --git a/src/share/classes/java/lang/Float.java b/src/share/classes/java/lang/Float.java --- a/src/share/classes/java/lang/Float.java +++ b/src/share/classes/java/lang/Float.java @@ -121,6 +121,13 @@ public static final int SIZE = 32; /** + * The number of bytes used to represent a {@code float} value. + * + * @since 1.8 + */ + public static final int BYTES = SIZE / Byte.SIZE; + + /** * The {@code Class} instance representing the primitive type * {@code float}. * diff --git a/src/share/classes/java/lang/Integer.java b/src/share/classes/java/lang/Integer.java --- a/src/share/classes/java/lang/Integer.java +++ b/src/share/classes/java/lang/Integer.java @@ -1285,6 +1285,14 @@ public static final int SIZE = 32; /** + * The number of bytes used to represent a {@code int} value in two's + * complement binary form. + * + * @since 1.8 + */ + public static final int BYTES = SIZE / Byte.SIZE; + + /** * Returns an {@code int} value with at most a single one-bit, in the * position of the highest-order ("leftmost") one-bit in the specified * {@code int} value. Returns zero if the specified value has no diff --git a/src/share/classes/java/lang/Long.java b/src/share/classes/java/lang/Long.java --- a/src/share/classes/java/lang/Long.java +++ b/src/share/classes/java/lang/Long.java @@ -1307,6 +1307,14 @@ public static final int SIZE = 64; /** + * The number of bytes used to represent a {@code long} value in two's + * complement binary form. + * + * @since 1.8 + */ + public static final int BYTES = SIZE / Byte.SIZE; + + /** * Returns a {@code long} value with at most a single one-bit, in the * position of the highest-order ("leftmost") one-bit in the specified * {@code long} value. Returns zero if the specified value has no diff --git a/src/share/classes/java/lang/Short.java b/src/share/classes/java/lang/Short.java --- a/src/share/classes/java/lang/Short.java +++ b/src/share/classes/java/lang/Short.java @@ -458,6 +458,14 @@ public static final int SIZE = 16; /** + * The number of bytes used to represent a {@code short} value in two's + * complement binary form. + * + * @since 1.8 + */ + public static final int BYTES = SIZE / Byte.SIZE; + + /** * Returns the value obtained by reversing the order of the bytes in the * two's complement representation of the specified {@code short} value. *