|
Rice Pastry API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object rice.p2p.util.MathUtils
public class MathUtils
This class contains a large number of static methods for performing math operations.
Field Summary | |
---|---|
static char[] |
HEX_ARRAY
The array used for conversion to hexadecimal |
Method Summary | |
---|---|
static int |
byteArrayToInt(byte[] input)
Utility method for converting a byte[] into a int |
static int |
byteArrayToInt(byte[] input,
int offset)
|
static long |
byteArrayToLong(byte[] input)
Utility method for converting a byte[] into a long |
static long |
byteArrayToLong(byte[] input,
int offset)
|
static short |
byteArrayToShort(byte[] input)
|
static short |
byteArrayToShort(byte[] input,
int offset)
|
static byte[] |
fromBase64(java.lang.String text)
Utility method which converts a base64 string to a byte[] |
static byte[] |
fromHex(java.lang.String text)
Utility method which converts a hex string to a byte[] |
protected static byte |
getByte(char c)
Utility method for converting a char to a byte |
static byte[] |
intToByteArray(int input)
Utility method for converting a int into a byte[] |
static void |
intToByteArray(int input,
byte[] output,
int offset)
Utility method for converting a int into a byte[] |
static byte |
intToUByte(int i)
|
static byte[] |
longToByteArray(long input)
Utility method for converting a long into a byte[] |
static void |
longToByteArray(long input,
byte[] output,
int offset)
Utility method for converting a long into a byte[] |
static int |
mod(int a,
int b)
Utility which does *proper* modding, where the result is guaranteed to be positive. |
static byte[] |
randomBytes(int len,
RandomSource random)
Method which returns a specified number of random bytes |
static int |
randomInt(RandomSource random)
Method which returns a random int |
static int |
simpleHash(byte[] b)
A simple and fast hash function for hashing an arbitrary length byte array into an int. |
static java.lang.String |
toBase64(byte[] text)
Utility method which converts a byte[] to a base64 string of characters, in lower case |
static java.lang.String |
toHex(byte[] text)
Utility method which converts a byte[] to a hexadecimal string of characters, in lower case |
static int |
uByteToInt(byte b)
|
static int |
uShortToInt(short b)
|
static byte[] |
xor(byte[] a,
byte[] b)
Utility method which xors two given byte arrays, of equal length, and returns the results |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final char[] HEX_ARRAY
Method Detail |
---|
public static int mod(int a, int b)
a
- The modeeb
- The value to mod by
public static byte[] xor(byte[] a, byte[] b)
a
- The first arrayb
- The second array
public static byte[] randomBytes(int len, RandomSource random)
len
- The number of random bytes to generatepublic static int randomInt(RandomSource random)
len
- The number of random bytes to generatepublic static java.lang.String toHex(byte[] text)
text
- The array to convert
public static byte[] fromHex(java.lang.String text)
text
- The text to convert
public static java.lang.String toBase64(byte[] text)
text
- The array to convert
public static byte[] fromBase64(java.lang.String text)
text
- The text to convert
public static int simpleHash(byte[] b)
b
-
protected static byte getByte(char c)
c
- The char
public static byte[] intToByteArray(int input)
input
- The log to convert
public static void intToByteArray(int input, byte[] output, int offset)
input
- The log to convertpublic static int byteArrayToInt(byte[] input)
input
- The byte[] to convert
public static int byteArrayToInt(byte[] input, int offset)
public static short byteArrayToShort(byte[] input)
public static short byteArrayToShort(byte[] input, int offset)
public static byte[] longToByteArray(long input)
input
- The log to convert
public static void longToByteArray(long input, byte[] output, int offset)
input
- The log to convertpublic static long byteArrayToLong(byte[] input)
input
- The byte[] to convert
public static long byteArrayToLong(byte[] input, int offset)
public static int uByteToInt(byte b)
public static int uShortToInt(short b)
public static byte intToUByte(int i)
|
Rice Pastry API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |