United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4900166 : static fields in java.lang wrappers for byte sizes (useful for NIO buffers)

Details
Type:
Enhancement
Submit Date:
2003-08-01
Status:
Resolved
Updated Date:
2003-08-30
Project Name:
JDK
Resolved Date:
2003-08-30
Component:
core-libs
OS:
generic,windows_2000
Sub-Component:
java.lang
CPU:
x86,generic
Priority:
P5
Resolution:
Fixed
Affected Versions:
1.1.6,1.2.0,1.4.1
Fixed Versions:
5.0 (tiger)

Related Reports
Duplicate:
Relates:

Sub Tasks

Description

Name: jl125535			Date: 08/01/2003


A DESCRIPTION OF THE REQUEST :
Please add public static int fields in all primitive wrapper classes that contain the size of the type in bytes.

This is trivial, but it gets annoying once you add your own static fields to classes a few different times.

JUSTIFICATION :
Currently, whenever dealing with ByteBuffers and you need to retrieve primitive types using their absolute position within the Buffer, you always need to have your own fields in your class with the size of each primitive type in bytes. While this is not a terrible hardship, it would be simpler, much more elegant, and logical for each primitive wrapper to have constant fields available so that it is immediately apparent what you're up to.

EXPECTED VERSUS ACTUAL BEHAVIOR :
When retrieving data from some buffer, for instance one you have received from a DatagramChannel, and you know the data is stored like this:

a short with the message type
a long with the timestamp
two ints with data

and if you want to retrieve your data using absolute positioning, it seems reasonable to be able retreive it like this:

short type = buffer.getShort(0 * Short.SIZE);
long timeStampe = buffer.getShort(Short.SIZE);
int firstData = buffer.getShort(Short.SIZE + Long.SIZE);
int secondData = buffer.getShort(Short.SIZE + Long.SIZE + Integer.SIZE);
You define your own static fields.
    

CUSTOMER SUBMITTED WORKAROUND :
Define your own static variables, or use relative reading (you can store the initial position and then put the 'cursor' back there when you're done).
(Incident Review ID: 182352) 
======================================================================

                                    

Comments
SUGGESTED FIX

src/share/classes/java/lang>sccs sccsdiff -r1.85 -r1.86 Float.java

------- Float.java -------
71a72,78
>      * The number of bits used to represent a <tt>float</tt> value.
>      *
>      * @since 1.5
>      */
>     public static final int SIZE = 32;
> 
>     /**
753,757c760,761
<      * This ensures that <code>Float.compareTo(Object)</code> (which
<      * forwards its behavior to this method) obeys the general
<      * contract for <code>Comparable.compareTo</code>, and that the
<      * <i>natural order</i> on <code>Float</code>s is <i>consistent
<      * with equals</i>.
---
>      * This ensures that the <i>natural ordering</i> of <tt>Float</tt>
>      * objects imposed by this method is <i>consistent with equals</i>.

src/share/classes/java/lang>sccs sccsdiff -r1.86 -r1.87 Double.java

------- Double.java -------
71a72,78
>      * The number of bits used to represent a <tt>double</tt> value.
>      *
>      * @since 1.5
>      */
>     public static final int SIZE = 64;
> 
>     /**
851,854c858,859
<      * This ensures that <code>Double.compareTo(Object)</code> (which
<      * forwards its behavior to this method) obeys the general
<      * contract for <code>Comparable.compareTo</code>, and that the
<      * <i>natural order</i> on <code>Double</code>s is <i>consistent
---
>      * This ensures that the <i>natural ordering</i> of
>      * <tt>Double</tt> objects imposed by this method is <i>consistent
867d871
<      * @see Comparable#compareTo(Object)

###@###.### 2003-08-20
                                     
2003-08-20
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b18


                                     
2004-06-14
EVALUATION

Bug 4495754 Add library support for common bit manipulation operations includes a SIZE fields, in bits, for the primitive types other than float and double.

Simliar fields could be added to Float and Double.

###@###.### 2003-08-05
                                     
2003-08-05



Hardware and Software, Engineered to Work Together