com.github.bingoohuang.utils.joou.Unsigned Maven / Gradle / Ivy
/**
* Copyright (c) 2009-2011, Lukas Eder, [email protected]
* All rights reserved.
*
* This software is licensed to you under the Apache License, Version 2.0
* (the "License"); You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* . Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* . Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* . Neither the name "jOOU" nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.github.bingoohuang.utils.joou;
import java.math.BigInteger;
/**
* A utility class for static access to unsigned number functionality.
*
* It essentially contains factory methods for unsigned number wrappers. In
* future versions, it will also contain some arithmetic methods, handling
* regular arithmetic and bitwise operations
*
* @author Lukas Eder
*/
public final class Unsigned {
/**
* Create an unsigned byte
*
* @throws NumberFormatException If value
does not contain a
* parsable unsigned byte
.
* @see UByte#UByte(String)
*/
public static UByte ubyte(String value) throws NumberFormatException {
return value == null ? null : new UByte(value);
}
/**
* Create an unsigned byte
by masking it with 0xFF
* i.e. (byte) -1
becomes (ubyte) 255
*
* @see UByte#UByte(byte)
*/
public static UByte ubyte(byte value) {
return new UByte(value);
}
/**
* Create an unsigned byte
*
* @throws NumberFormatException If value
is not in the range
* of an unsigned byte
* @see UByte#UByte(short)
*/
public static UByte ubyte(short value) throws NumberFormatException {
return new UByte(value);
}
/**
* Create an unsigned short
*
* @throws NumberFormatException If value
does not contain a
* parsable unsigned short
.
* @see UShort#UShort(String)
*/
public static UShort ushort(String value) throws NumberFormatException {
return value == null ? null : new UShort(value);
}
/**
* Create an unsigned short
by masking it with
* 0xFFFF
i.e. (short) -1
becomes
* (ushort) 65535
*
* @see UShort#UShort(short)
*/
public static UShort ushort(short value) {
return new UShort(value);
}
/**
* Create an unsigned short
*
* @throws NumberFormatException If value
is not in the range
* of an unsigned short
* @see UShort#UShort(int)
*/
public static UShort ushort(int value) throws NumberFormatException {
return new UShort(value);
}
/**
* Create an unsigned int
*
* @throws NumberFormatException If value
does not contain a
* parsable unsigned int
.
* @see UInteger#UInteger(String)
*/
public static UInteger uint(String value) throws NumberFormatException {
return value == null ? null : new UInteger(value);
}
/**
* Create an unsigned int
by masking it with
* 0xFFFFFFFF
i.e. (int) -1
becomes
* (uint) 4294967295
*
* @see UInteger#UInteger(int)
*/
public static UInteger uint(int value) {
return new UInteger(value);
}
/**
* Create an unsigned int
*
* @throws NumberFormatException If value
is not in the range
* of an unsigned int
* @see UInteger#UInteger(long)
*/
public static UInteger uint(long value) throws NumberFormatException {
return new UInteger(value);
}
/**
* Create an unsigned long
*
* @throws NumberFormatException If value
does not contain a
* parsable unsigned long
.
* @see ULong#ULong(String)
*/
public static ULong ulong(String value) throws NumberFormatException {
return value == null ? null : new ULong(value);
}
/**
* Create an unsigned long
by masking it with
* 0xFFFFFFFFFFFFFFFF
i.e. (long) -1
becomes
* (uint) 18446744073709551615
*
* @see ULong#ULong(long)
*/
public static ULong ulong(long value) {
return new ULong(value);
}
/**
* Create an unsigned long
*
* @throws NumberFormatException If value
is not in the range
* of an unsigned long
* @see ULong#ULong(java.math.BigInteger)
*/
public static ULong ulong(BigInteger value) throws NumberFormatException {
return new ULong(value);
}
/**
* No instances
*/
private Unsigned() {}
}