Back to index

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

Instances of class Integer represent primitive int values. More...

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

List of all members.

Public Member Functions

 Integer (int value)
 Create an Integer object representing the value of the int argument.
 Integer (String s)
 Create an Integer object representing the value of the argument after conversion to an int.
byte byteValue ()
 Return the value of this Integer as a byte.
short shortValue ()
 Return the value of this Integer as a short.
int intValue ()
 Return the value of this Integer.
long longValue ()
 Return the value of this Integer as a long.
float floatValue ()
 Return the value of this Integer as a float.
double doubleValue ()
 Return the value of this Integer as a double.
String toString ()
 Converts the Integer 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 Integer and represents the same int value.
int compareTo (Integer i)
 Compare two Integers numerically by comparing their int values.
int compareTo (Object o)
 Behaves like compareTo(Integer) unless the Object is not an Integer.

Static Public Member Functions

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

Static Public Attributes

static final int MIN_VALUE = 0x80000000
 The minimum value an int can represent is -2147483648 (or -231).
static final int MAX_VALUE = 0x7fffffff
 The maximum value an int can represent is 2147483647 (or 231 - 1).

Static Package Functions

static String toUnsignedString (int num, int exp)
 Helper for converting unsigned numbers to String.
static int parseInt (String str, int radix, boolean decode)
 Helper for parsing ints, used by Integer, Short, and Byte.

Static Package Attributes

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

Private Attributes

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

Static Private Attributes

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

Detailed Description

Instances of class Integer represent primitive int values.

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

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 Integer.java.


Constructor & Destructor Documentation

java.lang.Integer.Integer ( int  value) [inline]

Create an Integer object representing the value of the int argument.

Parameters:
valuethe value to use

Definition at line 94 of file Integer.java.

  {
    this.value = value;
  }

Here is the caller graph for this function:

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

Create an Integer object representing the value of the argument after conversion to an int.

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

Definition at line 107 of file Integer.java.

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

Here is the call graph for this function:


Member Function Documentation

Return the value of this Integer as a byte.

Returns:
the byte value

Reimplemented from java.lang.Number.

Definition at line 286 of file Integer.java.

  {
    return (byte) value;
  }

Compare two Integers numerically by comparing their int values.

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

Parameters:
ithe Integer to compare
Returns:
the comparison
Since:
1.2

Definition at line 487 of file Integer.java.

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

Here is the caller graph for this function:

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

Behaves like compareTo(Integer) unless the Object is not an Integer.

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

Definition at line 506 of file Integer.java.

  {
    return compareTo((Integer) o);
  }

Here is the call graph for this function:

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

Convert the specified String into an Integer.

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.

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

Definition at line 473 of file Integer.java.

  {
    return new Integer(parseInt(str, 10, true));
  }

Here is the call graph for this function:

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

Return the value of this Integer as a double.

Returns:
the double value

Implements java.lang.Number.

Definition at line 335 of file Integer.java.

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

Returns true if obj is an instance of Integer and represents the same int value.

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

Definition at line 369 of file Integer.java.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Return the value of this Integer as a float.

Returns:
the float value

Implements java.lang.Number.

Definition at line 325 of file Integer.java.

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

Get the specified system property as an Integer.

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 an Integer, 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 386 of file Integer.java.

  {
    return getInteger(nm, null);
  }

Here is the caller graph for this function:

static Integer java.lang.Integer.getInteger ( String  nm,
int  val 
) [inline, static]

Get the specified system property as an Integer, or use a default int 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 404 of file Integer.java.

  {
    Integer result = getInteger(nm, null);
    return result == null ? new Integer(val) : result;
  }

Here is the call graph for this function:

static Integer java.lang.Integer.getInteger ( String  nm,
Integer  def 
) [inline, static]

Get the specified system property as an Integer, or use a default Integer 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 423 of file Integer.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.

Integer's hash code is simply its value.

Returns:
this Object's hash code

Definition at line 357 of file Integer.java.

  {
    return value;
  }
int java.lang.Integer.intValue ( ) [inline, virtual]

Return the value of this Integer.

Returns:
the int value

Implements java.lang.Number.

Definition at line 305 of file Integer.java.

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

Return the value of this Integer as a long.

Returns:
the long value

Implements java.lang.Number.

Definition at line 315 of file Integer.java.

  {
    return value;
  }
static int java.lang.Integer.parseInt ( 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 '+'.

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

Definition at line 229 of file Integer.java.

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

Here is the caller graph for this function:

static int java.lang.Integer.parseInt ( String  s) [inline, static]

Converts the specified String into an int.

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 an int
See also:
parseInt(String, int)

Definition at line 244 of file Integer.java.

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

Here is the call graph for this function:

static int java.lang.Integer.parseInt ( String  str,
int  radix,
boolean  decode 
) [inline, static, package]

Helper for parsing ints, used by Integer, Short, and Byte.

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

Definition at line 549 of file Integer.java.

  {
    if (! decode && str == null)
      throw new NumberFormatException("parseInt cannot convert an empty String into an int");
    int index = 0;
    int len = str.length();
    boolean isNeg = false;
    if (len == 0)
      throw new NumberFormatException("parseInt cannot convert and empty String into an int");
    int ch = (int) str.charAt(index);
    if (ch == '-')
      {
        if (len == 1)
          throw new NumberFormatException("parseInt cannot convert - into an int");
        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("parseInt cannot convert " + str + " into an int");

    int 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;

    int val = 0;
    while (index < len)
      {
       if (val < 0 || val > max)
         throw new NumberFormatException("Number given to parseInt exceeded allowed size.");

        ch = Character.digit(str.charAt(index++), radix);
        val = val * radix + ch;
        if (ch < 0 || (val < 0 && (! isNeg || val != MIN_VALUE)))
          throw new NumberFormatException("Input given to parseInt contains non-numeric character");
      }
    return isNeg ? -val : val;
  }
short java.lang.Integer.shortValue ( ) [inline]

Return the value of this Integer as a short.

Returns:
the short value

Reimplemented from java.lang.Number.

Definition at line 296 of file Integer.java.

  {
    return (short) value;
  }
static String java.lang.Integer.toBinaryString ( int  i) [inline, static]

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

Parameters:
ithe int to convert to String
Returns:
the String representation of the argument

Definition at line 192 of file Integer.java.

  {
    return toUnsignedString(i, 1);
  }

Here is the call graph for this function:

static String java.lang.Integer.toHexString ( int  i) [inline, static]

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

Parameters:
ithe int to convert to String
Returns:
the String representation of the argument

Definition at line 168 of file Integer.java.

  {
    return toUnsignedString(i, 4);
  }

Here is the call graph for this function:

static String java.lang.Integer.toOctalString ( int  i) [inline, static]

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

Parameters:
ithe int to convert to String
Returns:
the String representation of the argument

Definition at line 180 of file Integer.java.

  {
    return toUnsignedString(i, 3);
  }

Here is the call graph for this function:

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

Converts the int 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 int 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 Integer.java.

  {
    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[33];
    int i = 33;
    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[num % radix];
        num /= radix;
      }
    while (num > 0);

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

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

Here is the caller graph for this function:

static String java.lang.Integer.toString ( int  i) [inline, static]

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

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

Definition at line 205 of file Integer.java.

  {
    // This is tricky: in libgcj, String.valueOf(int) is a fast native
    // implementation.  In Classpath it just calls back to
    // Integer.toString(int, int).
    return String.valueOf(i);
  }
String java.lang.Integer.toString ( ) [inline]

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

Returns:
the String representation

Definition at line 346 of file Integer.java.

  {
    return String.valueOf(value);
  }
static String java.lang.Integer.toUnsignedString ( int  num,
int  exp 
) [inline, static, package]

Helper for converting unsigned numbers to String.

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

Definition at line 518 of file Integer.java.

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

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

Here is the caller graph for this function:

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

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

Parameters:
sthe String to convert
radixthe radix (base) to convert with
Returns:
the new Integer
Exceptions:
NumberFormatExceptionif s cannot be parsed as an int
See also:
parseInt(String, int)

Definition at line 260 of file Integer.java.

  {
    return new Integer(parseInt(s, radix, false));
  }

Here is the call graph for this function:

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

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

Parameters:
sthe String to convert
Returns:
the new Integer
Exceptions:
NumberFormatExceptionif s cannot be parsed as an int
See also:
Integer(String)
parseInt(String)

Definition at line 276 of file Integer.java.

  {
    return new Integer(parseInt(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 int java.lang.Integer.MAX_VALUE = 0x7fffffff [static]

The maximum value an int can represent is 2147483647 (or 231 - 1).

Definition at line 72 of file Integer.java.

final int java.lang.Integer.MIN_VALUE = 0x80000000 [static]

The minimum value an int can represent is -2147483648 (or -231).

Definition at line 66 of file Integer.java.

final long java.lang.Integer.serialVersionUID = 1360826667806852920L [static, private]

Compatible with JDK 1.0.2+.

Reimplemented from java.lang.Number.

Definition at line 60 of file Integer.java.

final int java.lang.Integer.value [private]

The primitive type int is represented by this Class object.

Since:
1.1 The immutable value of this Integer.

the wrapped int

Definition at line 86 of file Integer.java.


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