mapred
Class BigIntegerWritable

java.lang.Object
  extended by mapred.BigIntegerWritable
All Implemented Interfaces:
org.apache.hadoop.io.Writable

public class BigIntegerWritable
extends java.lang.Object
implements org.apache.hadoop.io.Writable

Provides an immutable implementation of a big integer for use in Hadoop framework. Similarly to the Java BigInteger class, this class supports two basic mathematical operations: addition and multiplication. Besides, it also implements the Writable interface to support reading and writing operations in Hadoop framework.

Author:
vohuudtr

Constructor Summary
BigIntegerWritable()
          Default constructor without initialization.
BigIntegerWritable(java.math.BigInteger n)
          Constructs a BigIntegerWritable object from a Java BigInteger object.
BigIntegerWritable(java.io.DataInput in)
          Constructs a BigIntegerWritable object from the input stream.
BigIntegerWritable(int n)
          Constructs a BigIntegerWritable object from an integer.
 
Method Summary
 BigIntegerWritable add(BigIntegerWritable a)
          Returns a new BigIntegerWritable object with value equal to the sum of this object's value and another object's value.
 int getSize()
          Returns the total size in bytes representing the value of the object.
 BigIntegerWritable multiply(BigIntegerWritable a)
          Returns a new BigIntegerWritable object with value equal to the product of this object's value and another object's value.
 void readFields(java.io.DataInput in)
          Initializes the object by reading data from the input stream.
 java.lang.String toString()
          Returns a string representing this object.
 void write(java.io.DataOutput out)
          Writes the object into the specified output stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BigIntegerWritable

public BigIntegerWritable()
Default constructor without initialization. This constructor is needed for the iterator used in the reduce method of MapRed-classes. Therefore, one should manually initialize the value of this object after using this constructor.


BigIntegerWritable

public BigIntegerWritable(int n)
Constructs a BigIntegerWritable object from an integer.

Parameters:
n - initialized value for the constructed object.

BigIntegerWritable

public BigIntegerWritable(java.math.BigInteger n)
Constructs a BigIntegerWritable object from a Java BigInteger object.

Parameters:
n - initialized value for the constructed object.

BigIntegerWritable

public BigIntegerWritable(java.io.DataInput in)
                   throws java.io.IOException
Constructs a BigIntegerWritable object from the input stream. This constructor is a short-hand for initializing the object with the default constructor and calling readFields(DataInput) to read the value from the input stream.

Parameters:
in - input stream
Throws:
java.io.IOException - if IO errors occur.
See Also:
for storing format of the object in the stream.
Method Detail

readFields

public void readFields(java.io.DataInput in)
                throws java.io.IOException
Initializes the object by reading data from the input stream.

The object is stored in a stream as an ordered sequence of bytes:

Specified by:
readFields in interface org.apache.hadoop.io.Writable
Parameters:
in - input stream.
Throws:
java.io.IOException - if IO errors occur.

write

public void write(java.io.DataOutput out)
           throws java.io.IOException
Writes the object into the specified output stream. The sequence of bytes representing the object is in the format described in readFields(DataInput).

Specified by:
write in interface org.apache.hadoop.io.Writable
Parameters:
out - output stream.
Throws:
java.io.IOException - if IO errors occur.
See Also:
for storing format of the object in the stream.

getSize

public int getSize()
Returns the total size in bytes representing the value of the object.

Returns:
total size in bytes.

add

public BigIntegerWritable add(BigIntegerWritable a)
Returns a new BigIntegerWritable object with value equal to the sum of this object's value and another object's value.

Parameters:
a - another object.
Returns:
result of the addition.

multiply

public BigIntegerWritable multiply(BigIntegerWritable a)
Returns a new BigIntegerWritable object with value equal to the product of this object's value and another object's value.

Parameters:
a - another object.
Returns:
result of the multiplication.

toString

public java.lang.String toString()
Returns a string representing this object.

Overrides:
toString in class java.lang.Object