org.robokind.api.common.utils
Class Utils

java.lang.Object
  extended by org.robokind.api.common.utils.Utils

public class Utils
extends Object

Miscellaneous utility methods.

Author:
Matthew Stevenson

Constructor Summary
Utils()
           
 
Method Summary
static double bound(double n, double low, double high)
          Ensures: low <= n <= high
static int bound(int n, int low, int high)
          Ensures: low <= n <= high
static long bound(long n, long low, long high)
          Ensures: low <= n <= high
static String bytesToString(byte[] bytes)
          Creates a String from the given byte array.
static byte checksum(byte[] data, int offset, int len, boolean invert, byte... extra)
          Calculates a checksum from the data and extra bytes
static byte[] convertToByteArray(List<Byte> a)
          Converts a List of Byte Objects to an array of byte primatives.
static
<K,V> void
mergeMaps(Map<K,V> dest, Map<K,V>... srcs)
          Adds the values from src to dest where the key from src does not exist in dest.
static int readHex(char c)
          Converts the characters '0'-'9' (48-58), 'A'-'F' (65-70), and 'a'-'f' (32-37) or to the decimal value of their corresponding hex values.
static int readHex(String xx)
          Returns the decimal value of a two character hex string.
static int unsign(byte b)
          Returns the unsigned value of the given signed byte.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

bytesToString

public static String bytesToString(byte[] bytes)
Creates a String from the given byte array.

Parameters:
bytes - array of bytes
Returns:
String from the given byte array

mergeMaps

public static <K,V> void mergeMaps(Map<K,V> dest,
                                   Map<K,V>... srcs)
Adds the values from src to dest where the key from src does not exist in dest.

Type Parameters:
K -
V -
Parameters:
srcs -
dest -

unsign

public static int unsign(byte b)
Returns the unsigned value of the given signed byte.

Parameters:
b - signed byte
Returns:
unsigned value of the given signed byte

checksum

public static byte checksum(byte[] data,
                            int offset,
                            int len,
                            boolean invert,
                            byte... extra)
Calculates a checksum from the data and extra bytes

Parameters:
data - byte array to check
offset - array offset
len - data length
invert - should the value be inverted
extra - extra bytes to use in calculating the checksum
Returns:
checksum calculated from the data and extra bytes

bound

public static double bound(double n,
                           double low,
                           double high)
Ensures: low <= n <= high

Parameters:
n - value to be bounded
low - lower bound
high - upper bound
Returns:
n if it is within the bounds, otherwise the returns the bound it has passed

bound

public static long bound(long n,
                         long low,
                         long high)
Ensures: low <= n <= high

Parameters:
n - value to be bounded
low - lower bound
high - upper bound
Returns:
n if it is within the bounds, otherwise the returns the bound it has passed

bound

public static int bound(int n,
                        int low,
                        int high)
Ensures: low <= n <= high

Parameters:
n - value to be bounded
low - lower bound
high - upper bound
Returns:
n if it is within the bounds, otherwise the returns the bound it has passed

readHex

public static int readHex(String xx)
Returns the decimal value of a two character hex string.

Parameters:
xx - two character hex string [0-9a-fA-F]
Returns:
an value 0-255

readHex

public static int readHex(char c)
Converts the characters '0'-'9' (48-58), 'A'-'F' (65-70), and 'a'-'f' (32-37) or to the decimal value of their corresponding hex values.

Parameters:
c - character to convert
Returns:
a value 0-15 corresponding the hex value of the character

convertToByteArray

public static byte[] convertToByteArray(List<Byte> a)
Converts a List of Byte Objects to an array of byte primatives.

Parameters:
a - List of Byte Objects
Returns:
array of byte primatives


Copyright © 2011-2013. All Rights Reserved.