From 22d67ed564eff63a349334f1b1d94f2f0c8023b5 Mon Sep 17 00:00:00 2001 From: mduigou Date: Tue, 13 Nov 2012 20:02:39 -0800 Subject: [PATCH] 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: dholmes --- src/share/classes/java/lang/Byte.java | 8 ++++++++ src/share/classes/java/lang/Character.java | 8 ++++++++ src/share/classes/java/lang/Double.java | 7 +++++++ src/share/classes/java/lang/Float.java | 7 +++++++ src/share/classes/java/lang/Integer.java | 8 ++++++++ src/share/classes/java/lang/Long.java | 8 ++++++++ src/share/classes/java/lang/Short.java | 8 ++++++++ 7 files changed, 54 insertions(+) diff --git a/src/share/classes/java/lang/Byte.java b/src/share/classes/java/lang/Byte.java index c4dd62ecf..43a558ade 100644 --- a/src/share/classes/java/lang/Byte.java +++ b/src/share/classes/java/lang/Byte.java @@ -507,6 +507,14 @@ public final class Byte extends Number implements Comparable { */ 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 index 03134d06d..0f440067b 100644 --- a/src/share/classes/java/lang/Character.java +++ b/src/share/classes/java/lang/Character.java @@ -7170,6 +7170,14 @@ class Character implements java.io.Serializable, Comparable { */ 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 index 040cca700..a20f79e6c 100644 --- a/src/share/classes/java/lang/Double.java +++ b/src/share/classes/java/lang/Double.java @@ -122,6 +122,13 @@ public final class Double extends Number implements Comparable { */ 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 index 1e8f6e354..0c071e2b0 100644 --- a/src/share/classes/java/lang/Float.java +++ b/src/share/classes/java/lang/Float.java @@ -120,6 +120,13 @@ public final class Float extends Number implements Comparable { */ 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 index 50627e991..3496d039c 100644 --- a/src/share/classes/java/lang/Integer.java +++ b/src/share/classes/java/lang/Integer.java @@ -1297,6 +1297,14 @@ public final class Integer extends Number implements Comparable { */ 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 diff --git a/src/share/classes/java/lang/Long.java b/src/share/classes/java/lang/Long.java index 9197a6d1e..6509f88f1 100644 --- a/src/share/classes/java/lang/Long.java +++ b/src/share/classes/java/lang/Long.java @@ -1319,6 +1319,14 @@ public final class Long extends Number implements Comparable { */ 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 diff --git a/src/share/classes/java/lang/Short.java b/src/share/classes/java/lang/Short.java index f117095ab..6042b13f9 100644 --- a/src/share/classes/java/lang/Short.java +++ b/src/share/classes/java/lang/Short.java @@ -470,6 +470,14 @@ public final class Short extends Number implements Comparable { */ 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. -- GitLab