pops.ale.codec
Class UnsignedBigInt

java.lang.Object
  extended by pops.ale.codec.UnsignedBigInt

public class UnsignedBigInt
extends java.lang.Object

This class is a recyclable, unsigned and finite java's BigInteger like, but simpler. This class wraps an array of bytes of maximum MAX_BYTES. This size is fixed for recycling the object.
This class is intended to be used for manipulating numbers on more than 64 bits. However, for better efficiency numbers that hold on maximum 7 bytes, are treated as native long. Finally, this class has the same semantics as the following union in C :

 typedef union {
   long nativeData;
   unsigned char data [MAX_BYTES];
 } UnsignedBigInt;
 
In this case, a C compiler allocates MAX_BYTES bytes of memory and the access to this memory is determined upon compilation.
In our case, this is determined manually by the data setters.

Finally, this class still depends on java's BigInteger for string conversion of data on more than 7 bytes.

Author:
pops, R.DAGHER

Constructor Summary
UnsignedBigInt()
          Constructor
 
Method Summary
static long bench_toString(byte[] data)
           
static void bench()
           
static long benchSetData()
           
static int compare(UnsignedBigInt arg1, UnsignedBigInt arg2)
          Comparison of two numbers.
 boolean equal(UnsignedBigInt val)
          Equal method
 boolean greaterEqThan(UnsignedBigInt val)
          Greater or Equal Than.
 boolean greaterThan(UnsignedBigInt val)
          Greater Than.
 boolean lessEqThan(UnsignedBigInt val)
          Less or Equal Than.
 boolean lessThan(UnsignedBigInt val)
          Less Than.
static void main(java.lang.String[] args)
           
static void postlude()
           
static void prelude()
           
 void razData()
          sets all bytes to zero
 void setData(byte[] data)
          Copies the given array for processing.
 void setData(byte[] data, int start, int length)
          Copies the given array for processing.
 void setData(byte[] data, int start, int startMask, int startShift, int length, int stopMask, int stopShift)
          Copies the given array for processing.
 void setData(long data)
           
 void setData(java.lang.String data)
          Wraps the given decimal String for processing.
 void setData(UnsignedBigInt val)
          Copies the given array for processing.
 void setNonNativeData(long data)
          Wraps the given long for processing.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UnsignedBigInt

public UnsignedBigInt()
Constructor

Method Detail

razData

public void razData()
sets all bytes to zero


setData

public void setData(UnsignedBigInt val)
Copies the given array for processing. LSB is considered first.

Parameters:
data - array of bytes

setData

public void setData(byte[] data)
Copies the given array for processing. LSB is considered first.

Parameters:
data - array of bytes

setData

public void setData(byte[] data,
                    int start,
                    int length)
Copies the given array for processing. LSB is considered first.

Parameters:
data - array of bytes
length - the amount of bytes to copy

setData

public void setData(byte[] data,
                    int start,
                    int startMask,
                    int startShift,
                    int length,
                    int stopMask,
                    int stopShift)
Copies the given array for processing. LSB is considered first.

Parameters:
data - array of bytes

setNonNativeData

public void setNonNativeData(long data)
Wraps the given long for processing. LSB is considered first.

Parameters:
data - in long : may be also a byte, short or int promoted to long.

setData

public void setData(long data)

setData

public void setData(java.lang.String data)
Wraps the given decimal String for processing. LSB is considered first.

Parameters:
data - in long

lessThan

public boolean lessThan(UnsignedBigInt val)
Less Than.

Parameters:
val - value to compare with
Returns:
true if less than given value, false otherwise

lessEqThan

public boolean lessEqThan(UnsignedBigInt val)
Less or Equal Than.

Parameters:
val - value to compare with
Returns:
true if less or equal than given value, false otherwise

greaterThan

public boolean greaterThan(UnsignedBigInt val)
Greater Than.

Parameters:
val - value to compare with
Returns:
true if greater than given value

greaterEqThan

public boolean greaterEqThan(UnsignedBigInt val)
Greater or Equal Than.

Parameters:
val - value to compare with
Returns:
true if greater than given value

equal

public boolean equal(UnsignedBigInt val)
Equal method


compare

public static int compare(UnsignedBigInt arg1,
                          UnsignedBigInt arg2)
Comparison of two numbers.

Returns:
-1, 0 or +1 as big-endian unsigned int array arg1 is less than, equal to, or greater than arg2.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
string representation of the EPC object : the URI

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

bench

public static void bench()
                  throws java.lang.Exception
Throws:
java.lang.Exception

prelude

public static void prelude()
                    throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

postlude

public static void postlude()
                     throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

benchSetData

public static long benchSetData()
                         throws java.lang.Exception
Throws:
java.lang.Exception

bench_toString

public static long bench_toString(byte[] data)
                           throws java.lang.Exception
Throws:
java.lang.Exception