Back to index

plt-scheme  4.2.1
Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Package Attributes | Static Private Member Functions | Private Attributes | Static Private Attributes
java.lang.Long Class Reference

Instances of class Long represent primitive long values. More...

Inheritance diagram for java.lang.Long:
Inheritance graph
[legend]
Collaboration diagram for java.lang.Long:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Long (long value)
 Create a Long object representing the value of the long argument.
 Long (String s)
 Create a Long object representing the value of the argument after conversion to a long.
byte byteValue ()
 Return the value of this Long as a byte.
short shortValue ()
 Return the value of this Long as a short.
int intValue ()
 Return the value of this Long as an int.
long longValue ()
 Return the value of this Long.
float floatValue ()
 Return the value of this Long as a float.
double doubleValue ()
 Return the value of this Long as a double.
String toString ()
 Converts the Long value to a String and assumes a radix of 10.
int hashCode ()
 Return a hashcode representing this Object.
boolean equals (Object obj)
 Returns true if obj is an instance of Long and represents the same long value.
int compareTo (Long l)
 Compare two Longs numerically by comparing their long values.
int compareTo (Object o)
 Behaves like compareTo(Long) unless the Object is not a Long.

Static Public Member Functions

static String toString (long num, int radix)
 Converts the long to a String using the specified radix (base).
static String toHexString (long l)
 Converts the long to a String assuming it is unsigned in base 16.
static String toOctalString (long l)
 Converts the long to a String assuming it is unsigned in base 8.
static String toBinaryString (long l)
 Converts the long to a String assuming it is unsigned in base 2.
static String toString (long num)
 Converts the long to a String and assumes a radix of 10.
static long parseLong (String str, int radix)
 Converts the specified String into an int using the specified radix (base).
static long parseLong (String s)
 Converts the specified String into a long.
static Long valueOf (String s, int radix)
 Creates a new Long object using the String and specified radix (base).
static Long valueOf (String s)
 Creates a new Long object using the String, assuming a radix of 10.
static Long decode (String str)
 Convert the specified String into a Long.
static Long getLong (String nm)
 Get the specified system property as a Long.
static Long getLong (String nm, long val)
 Get the specified system property as a Long, or use a default long value if the property is not found or is not decodable.
static Long getLong (String nm, Long def)
 Get the specified system property as a Long, or use a default Long value if the property is not found or is not decodable.

Static Public Attributes

static final long MIN_VALUE = 0x8000000000000000L
 The minimum value a long can represent is -9223372036854775808L (or -263).
static final long MAX_VALUE = 0x7fffffffffffffffL
 The maximum value a long can represent is 9223372036854775807 (or 263 - 1).

Static Package Attributes

static final char[] digits
 Table for calculating digits, used in Character, Long, and Integer.

Static Private Member Functions

static String toUnsignedString (long num, int exp)
 Helper for converting unsigned numbers to String.
static long parseLong (String str, int radix, boolean decode)
 Helper for parsing longs.

Private Attributes

final long value
 The primitive type long is represented by this Class object.

Static Private Attributes

static final long serialVersionUID = 4290774380558885855L
 Compatible with JDK 1.0.2+.

Detailed Description

Instances of class Long represent primitive long values.

Additionally, this class provides various helper functions and variables related to longs.

Author:
Paul Fisher
John Keiser
Warren Levy
Eric Blake ebb9@.nosp@m.emai.nosp@m.l.byu.nosp@m..edu
Since:
1.0 updated to 1.4

Definition at line 55 of file Long.java.


Constructor & Destructor Documentation

java.lang.Long.Long ( long  value) [inline]

Create a Long object representing the value of the long argument.

Parameters:
valuethe value to use

Definition at line 94 of file Long.java.

  {
    this.value = value;
  }

Here is the caller graph for this function:

java.lang.Long.Long ( String  s) [inline]

Create a Long object representing the value of the argument after conversion to a long.

Parameters:
sthe string to convert
Exceptions:
NumberFormatExceptionif the String does not contain a long
See also:
valueOf(String)

Definition at line 107 of file Long.java.

  {
    value = parseLong(s, 10, false);
  }

Here is the call graph for this function:


Member Function Documentation

Return the value of this Long as a byte.

Returns:
the byte value

Reimplemented from java.lang.Number.

Definition at line 326 of file Long.java.

  {
    return (byte) value;
  }

Compare two Longs numerically by comparing their long values.

The result is positive if the first is greater, negative if the second is greater, and 0 if the two are equal.

Parameters:
lthe Long to compare
Returns:
the comparison
Since:
1.2

Definition at line 492 of file Long.java.

  {
    if (value == l.value)
      return 0;
    // Returns just -1 or 1 on inequality; doing math might overflow the long.
    return value > l.value ? 1 : -1;
  }

Here is the caller graph for this function:

int java.lang.Long.compareTo ( Object  o) [inline]

Behaves like compareTo(Long) unless the Object is not a Long.

Parameters:
othe object to compare
Returns:
the comparison
Exceptions:
ClassCastExceptionif the argument is not a Long
See also:
compareTo(Long)
Comparable
Since:
1.2

Definition at line 511 of file Long.java.

  {
    return compareTo((Long) o);
  }

Here is the call graph for this function:

static Long java.lang.Long.decode ( String  str) [inline, static]

Convert the specified String into a Long.

The String may represent decimal, hexadecimal, or octal numbers.

The extended BNF grammar is as follows:

 DecodableString:
      ( [ - ] DecimalNumber )
    | ( [ - ] ( 0x | 0X
              | # ) HexDigit { HexDigit } )
    | ( [ - ] 0 { OctalDigit } )
 DecimalNumber:
        DecimalDigit except '0' { DecimalDigit }
 DecimalDigit:
        Character.digit(d, 10) has value 0 to 9
 OctalDigit:
        Character.digit(d, 8) has value 0 to 7
 DecimalDigit:
        Character.digit(d, 16) has value 0 to 15
 

Finally, the value must be in the range MIN_VALUE to MAX_VALUE, or an exception is thrown. Note that you cannot use a trailing 'l' or 'L', unlike in Java source code.

Parameters:
strthe String to interpret
Returns:
the value of the String as a Long
Exceptions:
NumberFormatExceptionif s cannot be parsed as a long
NullPointerExceptionif s is null
Since:
1.2

Definition at line 316 of file Long.java.

  {
    return new Long(parseLong(str, 10, true));
  }

Here is the call graph for this function:

double java.lang.Long.doubleValue ( ) [inline, virtual]

Return the value of this Long as a double.

Returns:
the double value

Implements java.lang.Number.

Definition at line 376 of file Long.java.

  {
    return value;
  }
boolean java.lang.Long.equals ( Object  obj) [inline]

Returns true if obj is an instance of Long and represents the same long value.

Parameters:
objthe object to compare
Returns:
whether these Objects are semantically equal

Definition at line 410 of file Long.java.

  {
    return obj instanceof Long && value == ((Long) obj).value;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

float java.lang.Long.floatValue ( ) [inline, virtual]

Return the value of this Long as a float.

Returns:
the float value

Implements java.lang.Number.

Definition at line 366 of file Long.java.

  {
    return value;
  }
static Long java.lang.Long.getLong ( String  nm) [inline, static]

Get the specified system property as a Long.

The decode() method will be used to interpret the value of the property.

Parameters:
nmthe name of the system property
Returns:
the system property as a Long, or null if the property is not found or cannot be decoded
Exceptions:
SecurityExceptionif accessing the system property is forbidden
See also:
System::getProperty(String)
decode(String)

Definition at line 427 of file Long.java.

  {
    return getLong(nm, null);
  }

Here is the caller graph for this function:

static Long java.lang.Long.getLong ( String  nm,
long  val 
) [inline, static]

Get the specified system property as a Long, or use a default long value if the property is not found or is not decodable.

The decode() method will be used to interpret the value of the property.

Parameters:
nmthe name of the system property
valthe default value
Returns:
the value of the system property, or the default
Exceptions:
SecurityExceptionif accessing the system property is forbidden
See also:
System::getProperty(String)
decode(String)

Definition at line 445 of file Long.java.

  {
    Long result = getLong(nm, null);
    return result == null ? new Long(val) : result;
  }

Here is the call graph for this function:

static Long java.lang.Long.getLong ( String  nm,
Long  def 
) [inline, static]

Get the specified system property as a Long, or use a default Long value if the property is not found or is not decodable.

The decode() method will be used to interpret the value of the property.

Parameters:
nmthe name of the system property
defthe default value
Returns:
the value of the system property, or the default
Exceptions:
SecurityExceptionif accessing the system property is forbidden
See also:
System::getProperty(String)
decode(String)

Definition at line 464 of file Long.java.

  {
    if (nm == null || "".equals(nm))
      return def;
    else
      return def;
    /*nm = System.getProperty(nm);
    if (nm == null)
      return def;
    try
      {
        return decode(nm);
      }
    catch (NumberFormatException e)
      {
        return def;
      }*/
  }

Here is the call graph for this function:

Return a hashcode representing this Object.

Long's hash code is calculated by (int) (value ^ (value >> 32)).

Returns:
this Object's hash code

Definition at line 398 of file Long.java.

  {
    return (int) (value ^ (value >>> 32));
  }
int java.lang.Long.intValue ( ) [inline, virtual]

Return the value of this Long as an int.

Returns:
the int value

Implements java.lang.Number.

Definition at line 346 of file Long.java.

  {
    return (int) value;
  }
long java.lang.Long.longValue ( ) [inline, virtual]

Return the value of this Long.

Returns:
the long value

Implements java.lang.Number.

Definition at line 356 of file Long.java.

  {
    return value;
  }
static long java.lang.Long.parseLong ( String  str,
int  radix 
) [inline, static]

Converts the specified String into an int using the specified radix (base).

The string must not be null or empty. It may begin with an optional '-', which will negate the answer, provided that there are also valid digits. Each digit is parsed as if by Character.digit(d, radix), and must be in the range 0 to radix - 1. Finally, the result must be within MIN_VALUE to MAX_VALUE, inclusive. Unlike Double.parseDouble, you may not have a leading '+'; and 'l' or 'L' as the last character is only valid in radices 22 or greater, where it is a digit and not a type indicator.

Parameters:
strthe String to convert
radixthe radix (base) to use in the conversion
Returns:
the String argument converted to long
Exceptions:
NumberFormatExceptionif s cannot be parsed as a long

Definition at line 232 of file Long.java.

  {
    return parseLong(str, radix, false);
  }

Here is the caller graph for this function:

static long java.lang.Long.parseLong ( String  s) [inline, static]

Converts the specified String into a long.

This function assumes a radix of 10.

Parameters:
sthe String to convert
Returns:
the int value of s
Exceptions:
NumberFormatExceptionif s cannot be parsed as a long
See also:
parseLong(String, int)

Definition at line 247 of file Long.java.

  {
    return parseLong(s, 10, false);
  }

Here is the call graph for this function:

static long java.lang.Long.parseLong ( String  str,
int  radix,
boolean  decode 
) [inline, static, private]

Helper for parsing longs.

Parameters:
strthe string to parse
radixthe radix to use, must be 10 if decode is true
decodeif called from decode
Returns:
the parsed long value
Exceptions:
NumberFormatExceptionif there is an error
NullPointerExceptionif decode is true and str is null
See also:
parseLong(String, int)
decode(String)

Definition at line 557 of file Long.java.

  {
    if (! decode && str == null)
      throw new NumberFormatException();
    int index = 0;
    int len = str.length();
    boolean isNeg = false;
    if (len == 0)
      throw new NumberFormatException();
    int ch = str.charAt(index);
    if (ch == '-')
      {
        if (len == 1)
          throw new NumberFormatException();
        isNeg = true;
        ch = str.charAt(++index);
      }
    if (decode)
      {
        if (ch == '0')
          {
            if (++index == len)
              return 0;
            if ((str.charAt(index) & ~('x' ^ 'X')) == 'X')
              {
                radix = 16;
                index++;
              }
            else
              radix = 8;
          }
        else if (ch == '#')
          {
            radix = 16;
            index++;
          }
      }
    if (index == len)
      throw new NumberFormatException();

    long max = MAX_VALUE / radix;
    // We can't directly write `max = (MAX_VALUE + 1) / radix'.
    // So instead we fake it.
    if (isNeg && MAX_VALUE % radix == radix - 1)
      ++max;

    long val = 0;
    while (index < len)
      {
       if (val < 0 || val > max)
         throw new NumberFormatException();

        ch = Character.digit(str.charAt(index++), radix);
        val = val * radix + ch;
        if (ch < 0 || (val < 0 && (! isNeg || val != MIN_VALUE)))
          throw new NumberFormatException();
      }
    return isNeg ? -val : val;
  }
short java.lang.Long.shortValue ( ) [inline]

Return the value of this Long as a short.

Returns:
the short value

Reimplemented from java.lang.Number.

Definition at line 336 of file Long.java.

  {
    return (short) value;
  }
static String java.lang.Long.toBinaryString ( long  l) [inline, static]

Converts the long to a String assuming it is unsigned in base 2.

Parameters:
lthe long to convert to String
Returns:
the String representation of the argument

Definition at line 196 of file Long.java.

  {
    return toUnsignedString(l, 1);
  }

Here is the call graph for this function:

static String java.lang.Long.toHexString ( long  l) [inline, static]

Converts the long to a String assuming it is unsigned in base 16.

Parameters:
lthe long to convert to String
Returns:
the String representation of the argument

Definition at line 172 of file Long.java.

  {
    return toUnsignedString(l, 4);
  }

Here is the call graph for this function:

static String java.lang.Long.toOctalString ( long  l) [inline, static]

Converts the long to a String assuming it is unsigned in base 8.

Parameters:
lthe long to convert to String
Returns:
the String representation of the argument

Definition at line 184 of file Long.java.

  {
    return toUnsignedString(l, 3);
  }

Here is the call graph for this function:

static String java.lang.Long.toString ( long  num,
int  radix 
) [inline, static]

Converts the long to a String using the specified radix (base).

If the radix exceeds Character.MIN_RADIX or Character.MAX_RADIX, 10 is used instead. If the result is negative, the leading character is '-' ('\u002D'). The remaining characters come from Character.forDigit(digit, radix) ('0'-'9','a'-'z').

Parameters:
numthe long to convert to String
radixthe radix (base) to use in the conversion
Returns:
the String representation of the argument

Definition at line 124 of file Long.java.

  {
    // Use the Integer toString for efficiency if possible.
    if ((int) num == num)
      return Integer.toString((int) num, radix);

    if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
      radix = 10;

    // For negative numbers, print out the absolute value w/ a leading '-'.
    // Use an array large enough for a binary number.
    char[] buffer = new char[65];
    int i = 65;
    boolean isNeg = false;
    if (num < 0)
      {
        isNeg = true;
        num = -num;

        // When the value is MIN_VALUE, it overflows when made positive
        if (num < 0)
         {
           buffer[--i] = digits[(int) (-(num + radix) % radix)];
           num = -(num / radix);
         }
      }

    do
      {
        buffer[--i] = digits[(int) (num % radix)];
        num /= radix;
      }
    while (num > 0);

    if (isNeg)
      buffer[--i] = '-';

    // Package constructor avoids an array copy.
    return new String(buffer, i, 65 - i);
  }

Here is the call graph for this function:

static String java.lang.Long.toString ( long  num) [inline, static]

Converts the long to a String and assumes a radix of 10.

Parameters:
numthe long to convert to String
Returns:
the String representation of the argument
See also:
toString(long, int)

Definition at line 209 of file Long.java.

  {
    return toString(num, 10);
  }

Here is the call graph for this function:

String java.lang.Long.toString ( ) [inline]

Converts the Long value to a String and assumes a radix of 10.

Returns:
the String representation

Definition at line 387 of file Long.java.

  {
    return toString(value, 10);
  }

Here is the caller graph for this function:

static String java.lang.Long.toUnsignedString ( long  num,
int  exp 
) [inline, static, private]

Helper for converting unsigned numbers to String.

Parameters:
numthe number
explog2(digit) (ie. 1, 3, or 4 for binary, oct, hex)

Definition at line 522 of file Long.java.

  {
    // Use the Integer toUnsignedString for efficiency if possible.
    // If NUM<0 then this particular optimization doesn't work
    // properly.
    if (num >= 0 && (int) num == num)
      return Integer.toUnsignedString((int) num, exp);

    // Use an array large enough for a binary number.
    int mask = (1 << exp) - 1;
    char[] buffer = new char[64];
    int i = 64;
    do
      {
        buffer[--i] = digits[(int) num & mask];
        num >>>= exp;
      }
    while (num != 0);

    // Package constructor avoids an array copy.
    return new String(buffer, i, 64 - i);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static Long java.lang.Long.valueOf ( String  s,
int  radix 
) [inline, static]

Creates a new Long object using the String and specified radix (base).

Parameters:
sthe String to convert
radixthe radix (base) to convert with
Returns:
the new Long
Exceptions:
NumberFormatExceptionif s cannot be parsed as a long
See also:
parseLong(String, int)

Definition at line 263 of file Long.java.

  {
    return new Long(parseLong(s, radix, false));
  }

Here is the call graph for this function:

static Long java.lang.Long.valueOf ( String  s) [inline, static]

Creates a new Long object using the String, assuming a radix of 10.

Parameters:
sthe String to convert
Returns:
the new Long
Exceptions:
NumberFormatExceptionif s cannot be parsed as a long
See also:
Long(String)
parseLong(String)

Definition at line 279 of file Long.java.

  {
    return new Long(parseLong(s, 10, false));
  }

Here is the call graph for this function:


Member Data Documentation

final char [] java.lang.Number.digits [static, package, inherited]
Initial value:
 {
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
    'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
    'u', 'v', 'w', 'x', 'y', 'z',
  }

Table for calculating digits, used in Character, Long, and Integer.

Definition at line 68 of file Number.java.

final long java.lang.Long.MAX_VALUE = 0x7fffffffffffffffL [static]

The maximum value a long can represent is 9223372036854775807 (or 263 - 1).

Definition at line 72 of file Long.java.

final long java.lang.Long.MIN_VALUE = 0x8000000000000000L [static]

The minimum value a long can represent is -9223372036854775808L (or -263).

Definition at line 66 of file Long.java.

final long java.lang.Long.serialVersionUID = 4290774380558885855L [static, private]

Compatible with JDK 1.0.2+.

Reimplemented from java.lang.Number.

Definition at line 60 of file Long.java.

final long java.lang.Long.value [private]

The primitive type long is represented by this Class object.

Since:
1.1 The immutable value of this Long.

the wrapped long

Definition at line 86 of file Long.java.


The documentation for this class was generated from the following file: