java::lang::Long Class Reference

Inheritance diagram for java::lang::Long:

Inheritance graph
java::lang::Numberjava::lang::Objectjava::lang::Interfacejava::lang::Comparable
[legend]
Collaboration diagram for java::lang::Long:

Collaboration graph
java::lang::Numberjava::lang::Objectjava::lang::Interfacejava::lang::Comparable
[legend]

List of all members.


Detailed Description

The Long class wraps a value of the primitive type long in an object.

An object of type Long contains a single field whose type is long.

In addition, this class provides several methods for converting a long to a String and a String to a long, as well as other constants and methods useful when dealing with a long.

Author:
Lee Boynton

Arthur van Hoff

Yuh-Jye Chang

Version:
1.52, 02/02/00
Since:
JDK1.0

Public Member Functions

 Long (jlong _value=0)
 Constructs a newly allocated Long object that represents the primitive long argument.
 operator jlong & ()
virtual jbyte byteValue () const
 Returns the value of this Long as a byte.
virtual jshort shortValue () const
 Returns the value of this Long as a short.
virtual jint intValue () const
 Returns the value of this Long as an int.
virtual jlong longValue () const
 Returns the value of this Long as a long.
virtual jfloat floatValue () const
 Returns the value of this Long as a float.
virtual jdouble doubleValue () const
 Returns the value of this Long as a double.
virtual jboolean equals (const Object &src) const
 Compares this object against the specified object.
virtual jint hashCode () const
 Computes a hashcode for this Long.
virtual jint compareTo (const Object &src) const
 Compares this Long to another Object.
virtual String toString () const
 Returns a String object representing this Long's value.

Static Public Member Functions

static String toString (jlong i, jint radix=10)
 Creates a string representation of the first argument in the radix specified by the second argument.
static String toHexString (jlong i)
 Creates a string representation of the long argument as an unsigned integer in base 16.
static String toOctalString (jlong i)
 Creates a string representation of the long argument as an unsigned integer in base 8.
static String toBinaryString (jlong i)
 Creates a string representation of the long argument as an unsigned integer in base 2.
static jlong parseLong (const String &s, jint radix=10)
 Parses the string argument as a signed long in the radix specified by the second argument.
static Long valueOf (const String &s, jint radix=10)
 Returns a new long object initialized to the value of the specified String.

Static Public Attributes

static const jlong MIN_VALUE
 The smallest value of type long.
static const jlong MAX_VALUE
 The largest value of type long.

Constructor & Destructor Documentation

java::lang::Long::Long ( jlong  _value = 0  ) 

Constructs a newly allocated Long object that represents the primitive long argument.

Parameters:
value the value to be represented by the Long object.


Member Function Documentation

static String java::lang::Long::toString ( jlong  i,
jint  radix = 10 
) [static]

Creates a string representation of the first argument in the radix specified by the second argument.

If the radix is smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX, then the radix 10 is used instead.

If the first argument is negative, the first element of the result is the ASCII minus sign '-' ('\u002d'. If the first argument is not negative, no sign character appears in the result.

The remaining characters of the result represent the magnitude of the first argument. If the magnitude is zero, it is represented by a single zero character '0' ('&#92;u0030'); otherwise, the first character of the representation of the magnitude will not be the zero character. The following ASCII characters are used as digits: <blockquote>

   0123456789abcdefghijklmnopqrstuvwxyz
 
</blockquote> These are '&#92;u0030' through '&#92;u0039' and '&#92;u0061' through '&#92;u007a'. If the radix is N, then the first N of these characters are used as radix-N digits in the order shown. Thus, the digits for hexadecimal (radix 16) are 0123456789abcdef. If uppercase letters are desired, the java.lang.String#toUpperCase() method may be called on the result: <blockquote>
 Long.toString(n, 16).toUpperCase()
 
</blockquote>

Parameters:
i a long.
radix the radix.
Returns:
a string representation of the argument in the specified radix.

static String java::lang::Long::toHexString ( jlong  i  )  [static]

Creates a string representation of the long argument as an unsigned integer in base 16.

The unsigned long value is the argument plus 264 if the argument is negative; otherwise, it is equal to the argument.

If the unsigned magnitude is zero, it is represented by a single zero character '0' ('&#92;u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The following characters are used as hexadecimal digits: <blockquote>

 0123456789abcdef
 
</blockquote> These are the characters '&#92;u0030' through '&#92;u0039' and '&#92;u0061' through '&#92;u0066'. If uppercase letters are desired, the java.lang.String#toUpperCase() method may be called on the result: <blockquote>
 Long.toHexString(n).toUpperCase()
 
</blockquote>

Parameters:
i a long.
Returns:
the string representation of the unsigned long value represented by the argument in hexadecimal (base 16).
Since:
JDK 1.0.2

static String java::lang::Long::toOctalString ( jlong  i  )  [static]

Creates a string representation of the long argument as an unsigned integer in base 8.

The unsigned long value is the argument plus 264 if the argument is negative; otherwise, it is equal to the argument.

If the unsigned magnitude is zero, it is represented by a single zero character '0' ('&#92;u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The following characters are used as octal digits: <blockquote>

 01234567
 
</blockquote> These are the characters '&#92;u0030' through '&#92;u0037'.

Parameters:
i a long.
Returns:
the string representation of the unsigned long value represented by the argument in octal (base 8).
Since:
JDK 1.0.2

static String java::lang::Long::toBinaryString ( jlong  i  )  [static]

Creates a string representation of the long argument as an unsigned integer in base 2.

The unsigned long value is the argument plus 264 if the argument is negative; otherwise, it is equal to the argument.

If the unsigned magnitude is zero, it is represented by a single zero character '0' ('&392;u0030'); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The characters '0' ('&#92;u0030') and '1' ('&#92;u0031') are used as binary digits.

Parameters:
i a long.
Returns:
the string representation of the unsigned long value represented by the argument in binary (base 2).
Since:
JDK 1.0.2

static jlong java::lang::Long::parseLong ( const String s,
jint  radix = 10 
) [static]

Parses the string argument as a signed long in the radix specified by the second argument.

The characters in the string must all be digits of the specified radix (as determined by whether Character.digit returns a nonnegative value), except that the first character may be an ASCII minus sign '-' ('&#92;u002d' to indicate a negative value. The resulting long value is returned.

Note that neither L nor l is permitted to appear at the end of the string as a type indicator, as would be permitted in Java programming language source code - except that either L or l may appear as a digit for a radix greater than 22.

An exception of type NumberFormatException is thrown if any of the following situations occurs:

Examples: <blockquote>

 parseLong("0", 10) returns 0L
 parseLong("473", 10) returns 473L
 parseLong("-0", 10) returns 0L
 parseLong("-FF", 16) returns -255L
 parseLong("1100110", 2) returns 102L
 parseLong("99", 8) throws a NumberFormatException
 parseLong("Hazelnut", 10) throws a NumberFormatException
 parseLong("Hazelnut", 36) returns 1356099454469L
 
</blockquote>

Parameters:
s the String containing the long.
radix the radix to be used.
Returns:
the long represented by the string argument in the specified radix.
Exceptions:
NumberFormatException if the string does not contain a parsable integer.

static Long java::lang::Long::valueOf ( const String s,
jint  radix = 10 
) [static]

Returns a new long object initialized to the value of the specified String.

Throws an exception if the String cannot be parsed as a long.

The first argument is interpreted as representing a signed integer in the radix specified by the second argument, exactly as if the arguments were given to the parseLong(java.lang.String, int) method that takes two arguments. The result is a Long object that represents the integer value specified by the string.

In other words, this method returns a Long object equal to the value of: <blockquote>

 new Long(Long.parseLong(s, radix))
 
</blockquote>

Parameters:
s the String containing the long.
radix the radix to be used.
Returns:
a newly constructed Long initialized to the value represented by the string argument in the specified radix.
Exceptions:
NumberFormatException If the String does not contain a parsable long.

java::lang::Long::operator jlong & (  ) 

virtual jbyte java::lang::Long::byteValue (  )  const [virtual]

Returns the value of this Long as a byte.

Since:
JDK1.1

Reimplemented from java::lang::Number.

virtual jshort java::lang::Long::shortValue (  )  const [virtual]

Returns the value of this Long as a short.

Since:
JDK1.1

Reimplemented from java::lang::Number.

virtual jint java::lang::Long::intValue (  )  const [virtual]

Returns the value of this Long as an int.

Returns:
the int value represented by this object.

Implements java::lang::Number.

virtual jlong java::lang::Long::longValue (  )  const [virtual]

Returns the value of this Long as a long.

Returns:
the long value represented by this object that is converted to type long and the result of the conversion is returned.

Implements java::lang::Number.

virtual jfloat java::lang::Long::floatValue (  )  const [virtual]

Returns the value of this Long as a float.

Returns:
the long value represented by this object is converted to type float and the result of the conversion is returned.

Implements java::lang::Number.

virtual jdouble java::lang::Long::doubleValue (  )  const [virtual]

Returns the value of this Long as a double.

Returns:
the long value represented by this object is converted to type double and the result of the conversion is returned.

Implements java::lang::Number.

virtual jboolean java::lang::Long::equals ( const Object src  )  const [virtual]

Compares this object against the specified object.

The result is true if and only if the argument is not null and is a Long object that contains the same long value as this object.

Parameters:
obj the object to compare with.
Returns:
true if the objects are the same; false otherwise.

Reimplemented from java::lang::Object.

virtual jint java::lang::Long::hashCode (  )  const [virtual]

Computes a hashcode for this Long.

The result is the exclusive OR of the two halves of the primitive long value represented by this Long object. That is, the hashcode is the value of the expression: <blockquote>

 (int)(this.longValue()^(this.longValue()>>>32))
 
</blockquote>

Returns:
a hash code value for this object.

Reimplemented from java::lang::Object.

virtual jint java::lang::Long::compareTo ( const Object src  )  const [virtual]

Compares this Long to another Object.

If the Object is a Long, this function behaves like compareTo(Long). Otherwise, it throws a ClassCastException (as Longs are comparable only to other Longs).

Parameters:
o the Object to be compared.
Returns:
the value 0 if the argument is a Long numerically equal to this Long; a value less than 0 if the argument is a Long numerically greater than this Long; and a value greater than 0 if the argument is a Long numerically less than this Long.
Exceptions:
<code>ClassCastException</code> if the argument is not a Long.
See also:
java.lang.Comparable
Since:
1.2

Reimplemented from java::lang::Comparable.

virtual String java::lang::Long::toString (  )  const [virtual]

Returns a String object representing this Long's value.

The long integer value represented by this Long object is converted to signed decimal representation and returned as a string, exactly as if the long value were given as an argument to the toString(long) method that takes one argument.

Returns:
a string representation of this object in base 10.

Reimplemented from java::lang::Object.


Member Data Documentation

const jlong java::lang::Long::MIN_VALUE [static]

The smallest value of type long.

const jlong java::lang::Long::MAX_VALUE [static]

The largest value of type long.


The documentation for this class was generated from the following file:
Generated on Fri May 16 11:56:39 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3