aicas logo Jamaica 3.4 release 8

java.lang
Class Integer

java.lang.Object
  extended by java.lang.Number
      extended by java.lang.Integer
All Implemented Interfaces:
Serializable, Comparable<Integer>

public final class Integer
extends Number
implements Comparable<Integer>

Integer provides a class for integer values stored in objects.

Since:
1.0
See Also:
Serialized Form

Field Summary
static int MAX_VALUE
          The largest value an int can hold.
static int MIN_VALUE
          The smallest value an int can hold.
static int SIZE
          The size occupied by one int in bits.
static Class<Integer> TYPE
          type for int.
 
Constructor Summary
Integer(int value)
          Constructor to create an instance of Integer with the given integer value.
Integer(String s)
          Constructor to create an instance of Integer with the value provided as a string.
 
Method Summary
static int bitCount(int i)
          Calculates the number of one-bits in the given integer.
 byte byteValue()
          byteValue returns the value of this as a byte.
 int compareTo(Integer o)
          compareTo compares this to another int value
static Integer decode(String number)
          decode parses an integer given as a decimal, octal or hex number.
 double doubleValue()
          doubleValue returns the value of this as a double.
 boolean equals(Object obj)
          equals checks if this and obj represent the same value.
 float floatValue()
          floatValue returns the value of this as a float.
static Integer getInteger(String name)
          getInteger determines the value of a given integer property.
static Integer getInteger(String name, int val)
          getInteger determines the value of a given integer property.
static Integer getInteger(String name, Integer val)
          getInteger determines the value of a given integer property.
 int hashCode()
          hashCode returns a hashCode for this Integer.
static int highestOneBit(int i)
          Determine the highest "1" bit of an int.
 int intValue()
          intValue returns the value of this as an int.
 long longValue()
          longValue returns the value of this as a long.
static int lowestOneBit(int i)
          Determine the lowest "1" bit of an int.
static int numberOfLeadingZeros(int i)
          Calculates the number of zero-bits before the highest one-bit in an int.
static int numberOfTrailingZeros(int i)
          Calculates the number of zero-bits behind the lowest one-bit in an int.
static int parseInt(String s)
          parseInt parses a string that contains the decimal representation of an int and returns the int's value.
static int parseInt(String s, int radix)
          parseInt parses a string that contains the an int represented by a number using the given radix.
static int reverse(int i)
          reverse reverses the bit order of an integer.
static int reverseBytes(int i)
          reverse reverses the order of bytes in an int.
static int rotateLeft(int i, int distance)
          rotate the bits of an integer by the given distance to the left.
static int rotateRight(int i, int distance)
          rotate the bits of an integer by the given distance to the right.
 short shortValue()
          shortValue returns the value of this as a short.
static int signum(int i)
          Returns the sign of the specified value. -1 for a negative, 1 for a positive and 0 for the zero value.
static String toBinaryString(int i)
          toBinaryString creates a binary string from the given int value.
static String toHexString(int i)
          toHexString creates a hexadecimal string from the given int value.
static String toOctalString(int i)
          toOctalString creates an octal string from the given int value.
 String toString()
          toString converts the value of this int to a decimal string.
static String toString(int i)
          toString creates a decimal string from the given int value.
static String toString(int i, int radix)
          toString creates a string from the given int value using the given radix.
static Integer valueOf(int i)
          valueOf returns an integer instance with the given value.
static Integer valueOf(String s)
          valueOf returns an int instance with the value given as a decimal string.
static Integer valueOf(String s, int radix)
          valueOf returns an int instance with the value given as a string with given radix.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_VALUE

public static final int MIN_VALUE
The smallest value an int can hold.

See Also:
Constant Field Values

MAX_VALUE

public static final int MAX_VALUE
The largest value an int can hold.

See Also:
Constant Field Values

SIZE

public static final int SIZE
The size occupied by one int in bits.

Since:
1.5
See Also:
Constant Field Values

TYPE

public static final Class<Integer> TYPE
type for int.

Since:
1.1
Constructor Detail

Integer

public Integer(int value)
Constructor to create an instance of Integer with the given integer value.

Parameters:
value - the value for this instance.

Integer

public Integer(String s)
        throws NumberFormatException
Constructor to create an instance of Integer with the value provided as a string.

Parameters:
s - the string representation of the value.
Throws:
NumberFormatException - if s could not be parsed as an int.
Method Detail

valueOf

public static Integer valueOf(int i)
valueOf returns an integer instance with the given value. A cache is used to avoid multiple allocations of the same Integer instance.

Parameters:
i - the int value
Returns:
an instance with value equal to i.
Since:
1.5

toString

public static String toString(int i)
toString creates a decimal string from the given int value.

Parameters:
i - the int value
Returns:
the corresponding decimal string, e.g. "-128", "3", "127".

toString

public static String toString(int i,
                              int radix)
toString creates a string from the given int value using the given radix.

Parameters:
i - the int value
radix - the radix, if not in the range Character.MIN_RADIX .. Character.MAX_RADIX, then 10 is used.
Returns:
the corresponding string, e.g. toString(3277473,21) returns "ghij3".

toHexString

public static String toHexString(int i)
toHexString creates a hexadecimal string from the given int value.

Parameters:
i - the int value
Returns:
the corresponding string, e.g. toHexString(65535) returns "ffff".
Since:
JDK 1.0.2

toOctalString

public static String toOctalString(int i)
toOctalString creates an octal string from the given int value.

Parameters:
i - the int value
Returns:
the corresponding string, e.g. toOctalString(65535) returns "177777".
Since:
JDK 1.0.2

toBinaryString

public static String toBinaryString(int i)
toBinaryString creates a binary string from the given int value.

Parameters:
i - the int value
Returns:
the corresponding string, e.g. toBinaryString(65535) returns "1111111111111111".
Since:
JDK 1.0.2

parseInt

public static int parseInt(String s)
                    throws NumberFormatException
parseInt parses a string that contains the decimal representation of an int and returns the int's value.

Parameters:
s - the string, e.g, "-128", "3", "127".
Returns:
the int value.
Throws:
NumberFormatException - if s is not parseable or out of the legal range for ints.

parseInt

public static int parseInt(String s,
                           int radix)
                    throws NumberFormatException
parseInt parses a string that contains the an int represented by a number using the given radix. Returns the int's value.

Parameters:
s - the string
radix - the radix
Returns:
the int value.
Throws:
NumberFormatException - if s is not parseable, radix is out of the legal range or the value is out of the legal range for ints.

valueOf

public static Integer valueOf(String s,
                              int radix)
                       throws NumberFormatException
valueOf returns an int instance with the value given as a string with given radix. A cache is used to avoid multiple allocations of the same Integer instance.

Parameters:
s - the string
radix - the radix
Returns:
an Integer instance with the given value.
Throws:
NumberFormatException - if s is not parseable, radix is out of the legal range or the value is out of the legal range for ints.

valueOf

public static Integer valueOf(String s)
                       throws NumberFormatException
valueOf returns an int instance with the value given as a decimal string. A cache is used to avoid multiple allocations of the same Integer instance.

Parameters:
s - the string, e.g, "-128", "3", "127".
Returns:
an Integer instance with the given value.
Throws:
NumberFormatException - if s is not parseable or the value is out of the legal range for ints.

byteValue

public byte byteValue()
byteValue returns the value of this as a byte.

Overrides:
byteValue in class Number
Returns:
the value converted to byte.

shortValue

public short shortValue()
shortValue returns the value of this as a short.

Overrides:
shortValue in class Number
Returns:
the value converted to short.

intValue

public int intValue()
intValue returns the value of this as an int.

Specified by:
intValue in class Number
Returns:
the value of this.

longValue

public long longValue()
longValue returns the value of this as a long.

Specified by:
longValue in class Number
Returns:
the value converted to long.

floatValue

public float floatValue()
floatValue returns the value of this as a float.

Specified by:
floatValue in class Number
Returns:
the value converted to float.

doubleValue

public double doubleValue()
doubleValue returns the value of this as a double.

Specified by:
doubleValue in class Number
Returns:
the value converted to double.

toString

public String toString()
toString converts the value of this int to a decimal string.

Overrides:
toString in class Object
Returns:
the string, e.g. "-128", "127", "3".

hashCode

public int hashCode()
hashCode returns a hashCode for this Integer.

Overrides:
hashCode in class Object
Returns:
the integer value

equals

public boolean equals(Object obj)
equals checks if this and obj represent the same value.

Overrides:
equals in class Object
Parameters:
obj - another object
Returns:
true of obj is an Integer that represents the same value as this.

getInteger

public static Integer getInteger(String name)
getInteger determines the value of a given integer property.

Parameters:
name - the name of the property.
Returns:
null if the property is not set or could not be parsed as an integer, else the integer's value.

getInteger

public static Integer getInteger(String name,
                                 int val)
getInteger determines the value of a given integer property.

Parameters:
name - the name of the property.
val - the default value for the integer
Returns:
an instance of Integer set to val if the property is not set or could not be parsed as an integer, else set to the integer's value.

getInteger

public static Integer getInteger(String name,
                                 Integer val)
getInteger determines the value of a given integer property.

Parameters:
name - the name of the property.
val - the default value for the integer
Returns:
val if the property is not set or could not be parsed as an integer, else an instance of Integer set to the integer's value.

decode

public static Integer decode(String number)
                      throws NumberFormatException
decode parses an integer given as a decimal, octal or hex number. Prefix for hex is 0x, #, -0x or -#, for octal is 0 of -0.

Parameters:
number - the integer value as a string
Returns:
the corresponding integer value.
Throws:
NumberFormatException - if parsing failed or the resulting value is not representable as an int.
Since:
1.2

compareTo

public int compareTo(Integer o)
compareTo compares this to another int value

Specified by:
compareTo in interface Comparable<Integer>
Parameters:
o - the other int
Returns:
-1 if this is smaller than, 0 if this is equal to, +1 if this is larger than o.
Since:
1.2

highestOneBit

public static int highestOneBit(int i)
Determine the highest "1" bit of an int.

Parameters:
i - any int value
Returns:
an int with only the highest "1" bit of i set, or 0 if i is 0.
Since:
1.5

lowestOneBit

public static int lowestOneBit(int i)
Determine the lowest "1" bit of an int.

Parameters:
i - any int value
Returns:
an int with only the lowest "1" bit of i set, or 0 if i is 0.
Since:
1.5

numberOfLeadingZeros

public static int numberOfLeadingZeros(int i)
Calculates the number of zero-bits before the highest one-bit in an int. In the special case of i==0 it returns SIZE.

Parameters:
i - any int value
Returns:
the number of zero-bits before the hightest one-bit.
Since:
1.5

numberOfTrailingZeros

public static int numberOfTrailingZeros(int i)
Calculates the number of zero-bits behind the lowest one-bit in an int. In the special case of i==0 it returns SIZE.

Parameters:
i - any int value
Returns:
the number of zero-bits behind the lowest one-bit.
Since:
1.5

bitCount

public static int bitCount(int i)
Calculates the number of one-bits in the given integer. This is sometimes called the population.

Parameters:
i - any int value
Returns:
the population of the given integer.
Since:
1.5

rotateLeft

public static int rotateLeft(int i,
                             int distance)
rotate the bits of an integer by the given distance to the left.

Parameters:
i - the integer to be rotated.
distance - the distance, may be any value, also negative (for a right shift) or a value >= SIZE (a rotation by +/-SIZE is a NOP).
Returns:
the rotated value.
Since:
1.5

rotateRight

public static int rotateRight(int i,
                              int distance)
rotate the bits of an integer by the given distance to the right.

Parameters:
i - the integer to be rotated.
distance - the distance, may be any value, also negative (for a left shift) or a value >= SIZE (a rotation by +/-SIZE is a NOP).
Returns:
the rotated value.
Since:
1.5

reverse

public static int reverse(int i)
reverse reverses the bit order of an integer.

Parameters:
i - the integer
Returns:
a new integer whose value of bit#n is the value of bit#31-n in i.
Since:
1.5

reverseBytes

public static int reverseBytes(int i)
reverse reverses the order of bytes in an int.

Parameters:
i - an integer
Returns:
an integer with bytes # 0 and 3, and 1 and 2 swapped.
Since:
1.5

signum

public static int signum(int i)
Returns the sign of the specified value. -1 for a negative, 1 for a positive and 0 for the zero value.

Returns:
the sign of the int value.
Since:
1.5

aicas logo Jamaica 3.4 release 8

aicas GmbH, Karlsruhe - Germany    www.aicas.com
Copyright 2001-2009 aicas GmbH. All Rights Reserved.