//
// UnsignedInt64.java
//
// The contents of this file are subject to the SNIA Public License Version 1.0
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
//	http://www.snia.org/resources/openSource.html
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is UnsignedInt64.java
// 
// The Initial Developer of the Original Code is David Simons.
//
// Contributor(s): Peter Rivera
//
// This source uses the Solaris WBEM APIs version 2.2. 
// Synchronization will be maintained with the Solaris WBEM APIS,
// which are being standardized through the Java Community Process.
//
//
// $Id: UnsignedInt64.java,v 1.1 2003/07/17 18:32:55 kumpf Exp $
//
// $Log: UnsignedInt64.java,v $
// Revision 1.1  2003/07/17 18:32:55  kumpf
// HP-BAPU: PEP-64 CIM Client and CIM Listener Java Interface
//
// Revision 1.1.1.1  2001/10/31 18:14:42  karl
// import of SNIA 0_7
//
// Revision 1.5  2001/07/23 21:18:16  davidsi
// - Fixed various typos (etc) in previous check in.
//
// Revision 1.4  2001/07/22 15:09:08  davidsi
// - Work around for serialization problems with 1.3 JDK - Klaus Olszowi
//   noted that if one doesn't extend from BigInteger everything serializes
//   correctly. Therefore now provide a standalone UnsignedInt64
//   implementation which wraps the BigInteger instance.
//
// Revision 1.3  2001/03/20 13:05:42  davidsi
// - Added validation.
//
// Revision 1.2  2001/01/02 19:34:35  davidsi
// - Fixed off by one error in definition of MAX value.
//
// Revision 1.1  2000/11/18 14:22:13  davidsi
// - Initial version.
//
//
//
package org.snia.wbem.cim;

import java.math.BigInteger;
import java.io.Serializable;
import java.io.IOException;

/**
    Creates and instantiates an unsigned 64-bit integer object.
 */

public class UnsignedInt64  implements Serializable {

    public transient static final BigInteger MAX_VALUE=new BigInteger("18446744073709551615");
    public transient static final BigInteger MIN_VALUE=new BigInteger("0");

    private BigInteger value;

    // Pam Wright, Imation Add a constructor with a BigInteger parameter
    public UnsignedInt64(BigInteger inVal)  {
	value = new BigInteger(inVal.toByteArray());
	value = value.and(new BigInteger("ffffffffffffffff",16));
    }

    // Pam Wright, Imation Add validation
    public UnsignedInt64(java.lang.String inStr) throws java.lang.NumberFormatException {
	value = new BigInteger(inStr);
        if (compareTo(MIN_VALUE)<0 || compareTo(MAX_VALUE)>0)
            throw new java.lang.NumberFormatException("Not an unsigned 64 bit integer");
	and(new BigInteger("ffffffffffffffff",16));
    }


    //
    // All remaining methods simply proxy to the real BigInteger - this
    // seems to work around serialization problems
    //

    // Returns a BigInteger whose value is the absolute value of 
    // this BigInteger. 
    public BigInteger abs() {
	return(value.abs());
    }

    // Returns a BigInteger whose value is (this + val). 
    public BigInteger add(BigInteger val) {
	return(value.add(val));
    }


    // Returns a BigInteger whose value is (this & val). 
    public BigInteger and(BigInteger val) {
	return(value.and(val));
    }

    // Returns a BigInteger whose value is (this & ~val). 
    public BigInteger andNot(BigInteger val) {
	return(value.andNot(val));
    }


    // Returns the number of bits in the two's complement 
    // representation of this BigInteger that differ from its sign bit. 
    int bitCount() {
	return(value.bitCount());
    }


    // Returns the number of bits in the minimal two's-complement
    // representation of this BigInteger, excluding a sign bit. 
    public int bitLength()  {
	return(value.bitLength());
    }

    // Returns a BigInteger whose value is equivalent to this
    // BigInteger with the designated bit cleared. 
    public BigInteger clearBit(int n) {
	return(value.clearBit(n));
    }


    // Compares this BigInteger with the specified BigInteger. 
    public int compareTo(BigInteger val) {
	return(value.compareTo(val));
    }


    // Compares this BigInteger with the specified Object. 
    public int compareTo(Object o) {
	return( value.compareTo(o));
    }


    // Returns a BigInteger whose value is (this / val). 
    public BigInteger divide(BigInteger val)  {
	return(value.divide(val));
    }


    // Returns an array of two BigIntegers containing 
    // (this / val) followed by (this % val). 
    public BigInteger[] divideAndRemainder(BigInteger val) {
	return(value.divideAndRemainder(val));
    }



    // Converts this BigInteger to a double. 
    public double doubleValue() {
	return(value.doubleValue());
    }


    // Compares this BigInteger with the specified Object for equality. 
    public boolean equals(Object x) {
	return(value.equals(x));
    }


    // Returns a BigInteger whose value is equivalent to this
    // BigInteger with the designated bit flipped. 
    public BigInteger flipBit(int n)  {
	return(value.flipBit(n));
    }


    // Converts this BigInteger to a float. 
    public float floatValue() {
	return(value.floatValue());
    }


    // Returns a BigInteger whose value is the greatest common
    // divisor of abs(this) and abs(val). 
    public BigInteger gcd(BigInteger val) {
	return(value.gcd(val));
    }


    // Returns the index of the rightmost (lowest-order) one bit in
    // this BigInteger (the number of zero bits to the right of the
    // rightmost one bit). 
    public int getLowestSetBit() {
	return(value.getLowestSetBit());
    }


    // Returns the hash code for this BigInteger. 
    public int hashCode()  {
	return(value.hashCode());
    }


    // Converts this BigInteger to an int. 
    public int intValue() {
	return(value.intValue());
    }



    // Returns true if this BigInteger is probably prime, false if
    // it's definitely composite. 
    public boolean isProbablePrime(int certainty) {
	return(value.isProbablePrime(certainty));
    }


    // Converts this BigInteger to a long. 
    public long longValue() {
	return(value.longValue());
    }



    // Returns the maximum of this BigInteger and val. 
    public BigInteger max(BigInteger val)  {
	return(value.max(val));
    }

    // Returns the minimum of this BigInteger and val. 
    public BigInteger min(BigInteger val) {
	return(value.min(val));
    }

    // Returns a BigInteger whose value is (this mod m). 
    public BigInteger mod(BigInteger m) {
	return(value.mod(m));
    }


    // Returns a BigInteger whose value is (this-1 mod m). 
    public BigInteger modInverse(BigInteger m) {
	return(value.modInverse(m));
    }


    // Returns a BigInteger whose value is (thisexponent mod m). 
    public BigInteger modPow(BigInteger exponent, BigInteger m) {
	return(value.modPow(exponent,m));
    }
 
    // Returns a BigInteger whose value is (this * val). 
    public BigInteger multiply(BigInteger val) {
	return(value.multiply(val));
    }

    // Returns a BigInteger whose value is (-this). 
    public BigInteger negate() {
	return(value.negate());
    }

    // Returns a BigInteger whose value is (~this). 
    public BigInteger not() {
	return(value.not());
    }


    // Returns a BigInteger whose value is (this | val). 
    public BigInteger or(BigInteger val) {
	return(value.or(val));
    }


    // Returns a BigInteger whose value is (thisexponent). 
    public BigInteger pow(int exponent) {
	return(value.pow(exponent));
    }


    // Returns a BigInteger whose value is (this % val). 
    public BigInteger remainder(BigInteger val)  {
	return(value.remainder(val));
    }



    // Returns a BigInteger whose value is equivalent to this
    // BigInteger with the designated bit set. 
    public BigInteger setBit(int n) {
	return(value.setBit(n));
    }

    // Returns a BigInteger whose value is (this << n). 
    public BigInteger shiftLeft(int n) {
	return(value.shiftLeft(n));
    }


    // Returns a BigInteger whose value is (this >> n). 
    public BigInteger shiftRight(int n)  {
	return(value.shiftRight(n));
    }



    // Returns the signum function of this BigInteger. 
    public int signum() {
	return(value.signum());
    }


    // Returns a BigInteger whose value is (this - val). 
    public BigInteger subtract(BigInteger val) {
	return(value.subtract(val));
    }


    // Returns true if and only if the designated bit is set. 
    public boolean testBit(int n) {
	return(value.testBit(n));
    }



    // Returns a byte array containing the two's-complement representation
    //  of this BigInteger. 
    public byte[] toByteArray() {
	return(value.toByteArray());
    }

    // Returns the decimal String representation of this BigInteger. 
    public String toString() {
	return(value.toString());
    }


    // Returns the String representation of this BigInteger in the given radix. 
    public  String toString(int radix) {
	return(value.toString(radix));
    }


    // Returns a BigInteger whose value is equal to that of the specified long. 
    static public  BigInteger valueOf(long val) {
	return(BigInteger.valueOf(val));
    }

    // Returns a BigInteger whose value is (this ^ val). 
    public BigInteger xor(BigInteger val) {
	return(value.xor(val));
    }

}
