Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## rice.p2p.util
Class MathUtils

    java.lang.Object
      rice.p2p.util.MathUtils

public class MathUtils
extends java.lang.Object

This class contains a large number of static methods for performing math operations.

Version:
  $Id: MathUtils.java,v 1.3 2005/03/11 00:58:16 jeffh Exp $
Author:
  amislove

Field Summary
`static char[]` | `HEX_ARRAY` The array used for conversion to hexidecimal

Method Summary
`static int` | `byteArrayToInt(byte[] input)` Utility method for converting a byte[] into a int
`static long` | `byteArrayToLong(byte[] input)` Utility method for converting a byte[] into a long
`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[]` | `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)` Method which returns a specified number of random bytes
`static int` | `randomInt()` Method which returns a random int
`static java.lang.String` | `toHex(byte[] text)` Utility method which converts a byte[] to a hexidecimal string of characters, in lower case
`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

### HEX_ARRAY

    public static final char[] HEX_ARRAY

  The array used for conversion to hexidecimal

Method Detail

### mod

    public static int mod(int a,
                          int b)

  Utility which does *proper* modding, where the result is guaranteed to be positive.

  Parameters:
    `a` - The modee
    `b` - The value to mod by
  Returns:
    The result

### xor

    public static byte[] xor(byte[] a,
                             byte[] b)

  Utility method which xors two given byte arrays, of equal length, and returns the results

  Parameters:
    `a` - The first array
    `b` - The second array
  Returns:
    A new byte array, xored

### randomBytes

    public static byte[] randomBytes(int len)

  Method which returns a specified number of random bytes

  Parameters:
    `len` - The number of random bytes to generate
  Returns:
    DESCRIBE THE RETURN VALUE

### randomInt

    public static int randomInt()

  Method which returns a random int

  Returns:
    DESCRIBE THE RETURN VALUE

### toHex

    public static java.lang.String toHex(byte[] text)

  Utility method which converts a byte[] to a hexidecimal string of characters, in lower case

  Parameters:
    `text` - The array to convert
  Returns:
    A string representation

### intToByteArray

    public static byte[] intToByteArray(int input)

  Utility method for converting a int into a byte[]

  Parameters:
    `input` - The log to convert
  Returns:
    a byte[] representation

### intToByteArray

    public static void intToByteArray(int input,
                                      byte[] output,
                                      int offset)

  Utility method for converting a int into a byte[]

  Parameters:
    `input` - The log to convert
    `output` - DESCRIBE THE PARAMETER
    `offset` - DESCRIBE THE PARAMETER

### byteArrayToInt

    public static int byteArrayToInt(byte[] input)

  Utility method for converting a byte[] into a int

  Parameters:
    `input` - The byte[] to convert
  Returns:
    a int representation

### longToByteArray

    public static byte[] longToByteArray(long input)

  Utility method for converting a long into a byte[]

  Parameters:
    `input` - The log to convert
  Returns:
    a byte[] representation

### longToByteArray

    public static void longToByteArray(long input,
                                       byte[] output,
                                       int offset)

  Utility method for converting a long into a byte[]

  Parameters:
    `input` - The log to convert
    `output` - DESCRIBE THE PARAMETER
    `offset` - DESCRIBE THE PARAMETER

### byteArrayToLong

    public static long byteArrayToLong(byte[] input)

  Utility method for converting a byte[] into a long

  Parameters:
    `input` - The byte[] to convert
  Returns:
    a long representation

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2005 - Rice Pastry.