activemq-cpp-3.6.0
decaf::lang::Integer Class Reference

#include <src/main/decaf/lang/Integer.h>

Inheritance diagram for decaf::lang::Integer:

Public Member Functions

 Integer (int value)
 Integer (const std::string &value)
 Constructs a new Integer and attempts to convert the given string to an int value, assigning it to the new object is successful or throwing a NumberFormatException if the string is not a properly formatted int.
virtual ~Integer ()
virtual int compareTo (const Integer &i) const
 Compares this Integer instance with another.
bool equals (const Integer &i) const
virtual bool operator== (const Integer &i) const
 Compares equality between this object and the one passed.
virtual bool operator< (const Integer &i) const
 Compares this object to another and returns true if this object is considered to be less than the one passed.
virtual int compareTo (const int &i) const
 Compares this Integer instance with another.
bool equals (const int &i) const
virtual bool operator== (const int &i) const
 Compares equality between this object and the one passed.
virtual bool operator< (const int &i) const
 Compares this object to another and returns true if this object is considered to be less than the one passed.
std::string toString () const
virtual double doubleValue () const
 Answers the double value which the receiver represents.
virtual float floatValue () const
 Answers the float value which the receiver represents.
virtual unsigned char byteValue () const
 Answers the byte value which the receiver represents.
virtual short shortValue () const
 Answers the short value which the receiver represents.
virtual int intValue () const
 Answers the int value which the receiver represents.
virtual long long longValue () const
 Answers the long value which the receiver represents.
- Public Member Functions inherited from decaf::lang::Number
virtual ~Number ()
- Public Member Functions inherited from decaf::lang::Comparable< Integer >
virtual ~Comparable ()
- Public Member Functions inherited from decaf::lang::Comparable< int >
virtual ~Comparable ()

Static Public Member Functions

static Integer decode (const std::string &value)
 Decodes a String into a Integer.
static int reverseBytes (int value)
 Returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified int value.
static int reverse (int value)
 Returns the value obtained by reversing the order of the bits in the two's complement binary representation of the specified int value.
static int parseInt (const std::string &s, int radix)
 Parses the string argument as a signed int in the radix specified by the second argument.
static int parseInt (const std::string &s)
 Parses the string argument as a signed decimal int.
static Integer valueOf (int value)
 Returns a Integer instance representing the specified int value.
static Integer valueOf (const std::string &value)
 Returns a Integer object holding the value given by the specified std::string.
static Integer valueOf (const std::string &value, int radix)
 Returns a Integer object holding the value extracted from the specified std::string when parsed with the radix given by the second argument.
static int bitCount (int value)
 Returns the number of one-bits in the two's complement binary representation of the specified int value.
static std::string toString (int value)
 Converts the int to a String representation.
static std::string toString (int value, int radix)
 Returns a string representation of the first argument in the radix specified by the second argument.
static std::string toHexString (int value)
 Returns a string representation of the integer argument as an unsigned integer in base 16.
static std::string toOctalString (int value)
 Returns a string representation of the integer argument as an unsigned integer in base 8.
static std::string toBinaryString (int value)
 Returns a string representation of the integer argument as an unsigned integer in base 2.
static int highestOneBit (int value)
 Returns an int value with at most a single one-bit, in the position of the highest-order ("leftmost") one-bit in the specified int value.
static int lowestOneBit (int value)
 Returns an int value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit in the specified int value.
static int numberOfLeadingZeros (int value)
 Returns the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complement binary representation of the specified int value.
static int numberOfTrailingZeros (int value)
 Returns the number of zero bits following the lowest-order ("rightmost") one-bit in the two's complement binary representation of the specified int value.
static int rotateLeft (int value, int distance)
 Returns the value obtained by rotating the two's complement binary representation of the specified int value left by the specified number of bits.
static int rotateRight (int value, int distance)
 Returns the value obtained by rotating the two's complement binary representation of the specified int value right by the specified number of bits.
static int signum (int value)
 Returns the signum function of the specified int value.

Static Public Attributes

static const int SIZE = 32
 The size in bits of the primitive int type.
static const int MAX_VALUE = (int)0x7FFFFFFF
 The maximum value that the primitive type can hold.
static const int MIN_VALUE = (int)0x80000000
 The minimum value that the primitive type can hold.

Constructor & Destructor Documentation

decaf::lang::Integer::Integer ( int  value)
Parameters
valueThe primitive value to wrap in an Integer instance.
decaf::lang::Integer::Integer ( const std::string &  value)

Constructs a new Integer and attempts to convert the given string to an int value, assigning it to the new object is successful or throwing a NumberFormatException if the string is not a properly formatted int.

Parameters
valueThe string to convert to a primitive type to wrap.
Exceptions
NumberFormatExceptionif the string is not a a valid integer.
virtual decaf::lang::Integer::~Integer ( )
inlinevirtual

Member Function Documentation

static int decaf::lang::Integer::bitCount ( int  value)
static

Returns the number of one-bits in the two's complement binary representation of the specified int value.

This function is sometimes referred to as the population count.

Parameters
value- the int to count
Returns
the number of one-bits in the two's complement binary representation of the specified int value.
virtual unsigned char decaf::lang::Integer::byteValue ( ) const
inlinevirtual

Answers the byte value which the receiver represents.

Returns
int the value of the receiver.

Reimplemented from decaf::lang::Number.

virtual int decaf::lang::Integer::compareTo ( const Integer i) const
virtual

Compares this Integer instance with another.

Parameters
i- the Integer instance to be compared
Returns
zero if this object represents the same integer value as the argument; a positive value if this object represents a value greater than the passed in value, and -1 if this object represents a value less than the passed in value.

Implements decaf::lang::Comparable< Integer >.

virtual int decaf::lang::Integer::compareTo ( const int &  i) const
virtual

Compares this Integer instance with another.

Parameters
i- the Integer instance to be compared
Returns
zero if this object represents the same integer value as the argument; a positive value if this object represents a value greater than the passed in value, and -1 if this object represents a value less than the passed in value.

Implements decaf::lang::Comparable< int >.

static Integer decaf::lang::Integer::decode ( const std::string &  value)
static

Decodes a String into a Integer.

Accepts decimal, hexadecimal, and octal numbers given by the following grammar:

The sequence of characters following an (optional) negative sign and/or radix specifier ("0x", "0X", "#", or leading zero) is parsed as by the Integer.parseInteger method with the indicated radix (10, 16, or 8). This sequence of characters must represent a positive value or a NumberFormatException will be thrown. The result is negated if first character of the specified String is the minus sign. No whitespace characters are permitted in the string.

Parameters
value- The string to decode
Returns
a Integer object containing the decoded value
Exceptions
NumberFomatExceptionif the string is not formatted correctly.
virtual double decaf::lang::Integer::doubleValue ( ) const
inlinevirtual

Answers the double value which the receiver represents.

Returns
double the value of the receiver.

Implements decaf::lang::Number.

bool decaf::lang::Integer::equals ( const Integer i) const
inlinevirtual
Parameters
i- the Integer object to compare against.
Returns
true if the two Integer Objects have the same value.

Implements decaf::lang::Comparable< Integer >.

bool decaf::lang::Integer::equals ( const int &  i) const
inlinevirtual
Parameters
i- the Integer object to compare against.
Returns
true if the two Integer Objects have the same value.

Implements decaf::lang::Comparable< int >.

virtual float decaf::lang::Integer::floatValue ( ) const
inlinevirtual

Answers the float value which the receiver represents.

Returns
float the value of the receiver.

Implements decaf::lang::Number.

static int decaf::lang::Integer::highestOneBit ( int  value)
static

Returns an int value with at most a single one-bit, in the position of the highest-order ("leftmost") one-bit in the specified int value.

Returns zero if the specified value has no one-bits in its two's complement binary representation, that is, if it is equal to zero.

Parameters
value- the int to be inspected
Returns
an int value with a single one-bit, in the position of the highest-order one-bit in the specified value, or zero if the specified value is itself equal to zero.
virtual int decaf::lang::Integer::intValue ( ) const
inlinevirtual

Answers the int value which the receiver represents.

Returns
int the value of the receiver.

Implements decaf::lang::Number.

virtual long long decaf::lang::Integer::longValue ( ) const
inlinevirtual

Answers the long value which the receiver represents.

Returns
long the value of the receiver.

Implements decaf::lang::Number.

static int decaf::lang::Integer::lowestOneBit ( int  value)
static

Returns an int value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit in the specified int value.

Returns zero if the specified value has no one-bits in its two's complement binary representation, that is, if it is equal to zero.

Parameters
value- the int to be inspected
Returns
an int value with a single one-bit, in the position of the lowest-order one-bit in the specified value, or zero if the specified value is itself equal to zero.
static int decaf::lang::Integer::numberOfLeadingZeros ( int  value)
static

Returns the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complement binary representation of the specified int value.

Returns 32 if the specified value has no one-bits in its two's complement representation, in other words if it is equal to zero.

Note that this method is closely related to the logarithm base 2. For all positive int values x:

* floor( log2(x)) = 31 - numberOfLeadingZeros(x)
* ceil( log2(x)) = 32 - numberOfLeadingZeros(x - 1)
Parameters
value- the int to be inspected
Returns
the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complement binary representation of the specified int value, or 32 if the value is equal to zero.
static int decaf::lang::Integer::numberOfTrailingZeros ( int  value)
static

Returns the number of zero bits following the lowest-order ("rightmost") one-bit in the two's complement binary representation of the specified int value.

Returns 32 if the specified value has no one-bits in its two's complement representation, in other words if it is equal to zero.

Parameters
value- the int to be inspected
Returns
the number of zero bits following the lowest-order ("rightmost") one-bit in the two's complement binary representation of the specified int value, or 32 if the value is equal to zero.
virtual bool decaf::lang::Integer::operator< ( const Integer i) const
inlinevirtual

Compares this object to another and returns true if this object is considered to be less than the one passed.

This

Parameters
i- the value to be compared to this one.
Returns
true if this object is equal to the one passed.

Implements decaf::lang::Comparable< Integer >.

virtual bool decaf::lang::Integer::operator< ( const int &  i) const
inlinevirtual

Compares this object to another and returns true if this object is considered to be less than the one passed.

This

Parameters
i- the value to be compared to this one.
Returns
true if this object is equal to the one passed.

Implements decaf::lang::Comparable< int >.

virtual bool decaf::lang::Integer::operator== ( const Integer i) const
inlinevirtual

Compares equality between this object and the one passed.

Parameters
i- the value to be compared to this one.
Returns
true if this object is equal to the one passed.

Implements decaf::lang::Comparable< Integer >.

virtual bool decaf::lang::Integer::operator== ( const int &  i) const
inlinevirtual

Compares equality between this object and the one passed.

Parameters
i- the value to be compared to this one.
Returns
true if this object is equal to the one passed.

Implements decaf::lang::Comparable< int >.

static int decaf::lang::Integer::parseInt ( const std::string &  s,
int  radix 
)
static

Parses the string argument as a signed int 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(char, int) returns a nonnegative value) except that the first character may be an ASCII minus sign '-' to indicate a negative value. The resulting byte value is returned.

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

  • The first argument is null or is a string of length zero.
  • The radix is either smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX.
  • Any character of the string is not a digit of the specified radix, except that the first character may be a minus sign '-' provided that the string is longer than length 1.
  • The value represented by the string is not a value of type int.
Parameters
s- the String containing the int representation to be parsed
radix- the radix to be used while parsing s
Returns
the int represented by the string argument in the specified radix.
Exceptions
NumberFormatException- If String does not contain a parsable int.
static int decaf::lang::Integer::parseInt ( const std::string &  s)
static

Parses the string argument as a signed decimal int.

The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' to indicate a negative value. The resulting int value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseInteger( const std::string, int ) method.

Parameters
s- String to convert to a int
Returns
the converted int value
Exceptions
NumberFormatExceptionif the string is not a int.
static int decaf::lang::Integer::reverse ( int  value)
static

Returns the value obtained by reversing the order of the bits in the two's complement binary representation of the specified int value.

Parameters
value- the value whose bits are to be reversed
Returns
the reversed bits int.
static int decaf::lang::Integer::reverseBytes ( int  value)
static

Returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified int value.

Parameters
value- the int whose bytes we are to reverse
Returns
the reversed int.
static int decaf::lang::Integer::rotateLeft ( int  value,
int  distance 
)
static

Returns the value obtained by rotating the two's complement binary representation of the specified int value left by the specified number of bits.

(Bits shifted out of the left hand, or high-order, side reenter on the right, or low-order.)

Note that left rotation with a negative distance is equivalent to right rotation: rotateLeft(val, -distance) == rotateRight(val, distance). Note also that rotation by any multiple of 32 is a no-op, so all but the last five bits of the rotation distance can be ignored, even if the distance is negative: rotateLeft(val, distance) == rotateLeft(val, distance & 0x1F).

Parameters
value- the int to be inspected
distance- the number of bits to rotate
Returns
the value obtained by rotating the two's complement binary representation of the specified int value left by the specified number of bits.
static int decaf::lang::Integer::rotateRight ( int  value,
int  distance 
)
static

Returns the value obtained by rotating the two's complement binary representation of the specified int value right by the specified number of bits.

(Bits shifted out of the right hand, or low-order, side reenter on the left, or high-order.)

Note that right rotation with a negative distance is equivalent to left rotation: rotateRight(val, -distance) == rotateLeft(val, distance). Note also that rotation by any multiple of 32 is a no-op, so all but the last five bits of the rotation distance can be ignored, even if the distance is negative: rotateRight(val, distance) == rotateRight(val, distance & 0x1F).

Parameters
value- the int to be inspected
distance- the number of bits to rotate
Returns
the value obtained by rotating the two's complement binary representation of the specified int value right by the specified number of bits.
virtual short decaf::lang::Integer::shortValue ( ) const
inlinevirtual

Answers the short value which the receiver represents.

Returns
int the value of the receiver.

Reimplemented from decaf::lang::Number.

static int decaf::lang::Integer::signum ( int  value)
static

Returns the signum function of the specified int value.

(The return value is -1 if the specified value is negative; 0 if the specified value is zero; and 1 if the specified value is positive.)

Parameters
value- the int to be inspected
Returns
the signum function of the specified int value.
static std::string decaf::lang::Integer::toBinaryString ( int  value)
static

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

The unsigned integer value is the argument plus 2^32 if the argument is negative; otherwise it is equal to the argument. This value is converted to a string of ASCII digits in binary (base 2) with no extra leading 0s. If the unsigned magnitude is zero, it is represented by a single zero character '0'; otherwise, the first character of the representation of the unsigned magnitude will not be the zero character.

The characters '0' and '1' are used as binary digits.

Parameters
value- the int to be translated to a binary string
Returns
the unsigned int value as a binary string
static std::string decaf::lang::Integer::toHexString ( int  value)
static

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

The unsigned integer value is the argument plus 2^32 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in hexadecimal (base 16) with no extra leading 0s. If the unsigned magnitude is zero, it is represented by a single zero character '0'; 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:

            0123456789abcdef

If uppercase letters are desired, the toUpperCase() method may be called on the result:

Parameters
value- the int to be translated to an Octal string
Returns
the unsigned int value as a Octal string
static std::string decaf::lang::Integer::toOctalString ( int  value)
static

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

The unsigned integer value is the argument plus 2^32 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in octal (base 8) with no extra leading 0s.

If the unsigned magnitude is zero, it is represented by a single zero character '0'; 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:

 01234567
Parameters
value- the int to be translated to an Octal string
Returns
the unsigned int value as a Octal string
std::string decaf::lang::Integer::toString ( ) const
Returns
this Integer Object as a String Representation

Referenced by decaf::util::ArrayList< Pointer< ActiveMQDestination > >::toString().

static std::string decaf::lang::Integer::toString ( int  value)
static

Converts the int to a String representation.

Parameters
valueThe int to convert to a std::string instance.
Returns
string representation
static std::string decaf::lang::Integer::toString ( int  value,
int  radix 
)
static

Returns 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 character '-'. 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'; otherwise, the first character of the representation of the magnitude will not be the zero character. The following ASCII characters are used as digits:

0123456789abcdefghijklmnopqrstuvwxyz

Parameters
value- the int to convert to a string
radix- the radix to format the string in
Returns
an int formatted to the string value of the radix given.
static Integer decaf::lang::Integer::valueOf ( int  value)
inlinestatic

Returns a Integer instance representing the specified int value.

Parameters
value- the int to wrap
Returns
the new Integer object wrapping value.
static Integer decaf::lang::Integer::valueOf ( const std::string &  value)
static

Returns a Integer object holding the value given by the specified std::string.

The argument is interpreted as representing a signed decimal int, exactly as if the argument were given to the parseInt( std::string ) method. The result is a Integer object that represents the int value specified by the string.

Parameters
value- std::string to parse as base 10
Returns
new Integer Object wrapping the primitive
Exceptions
NumberFormatExceptionif the string is not a decimal int.
static Integer decaf::lang::Integer::valueOf ( const std::string &  value,
int  radix 
)
static

Returns a Integer object holding the value extracted from the specified std::string when parsed with the radix given by the second argument.

The first argument is interpreted as representing a signed int in the radix specified by the second argument, exactly as if the argument were given to the parseInt( std::string, int ) method. The result is a Integer object that represents the int value specified by the string.

Parameters
value- std::string to parse as base ( radix )
radix- base of the string to parse.
Returns
new Integer Object wrapping the primitive
Exceptions
NumberFormatExceptionif the string is not a valid int.

Field Documentation

const int decaf::lang::Integer::MAX_VALUE = (int)0x7FFFFFFF
static

The maximum value that the primitive type can hold.

Referenced by decaf::util::concurrent::LinkedBlockingQueue< Pointer< Transport > >::drainTo().

const int decaf::lang::Integer::MIN_VALUE = (int)0x80000000
static

The minimum value that the primitive type can hold.

const int decaf::lang::Integer::SIZE = 32
static

The size in bits of the primitive int type.


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