jist.swans.misc
Class Util

java.lang.Object
  extended by jist.swans.misc.Util

public final class Util
extends java.lang.Object

Miscellaneous utility methods.

Since:
SWANS1.0
Version:
$Id: Util.java,v 1.18 2004/04/06 16:07:49 barr Exp $
Author:
Rimon Barr <barr+jist@cs.cornell.edu>

Field Summary
static java.util.Enumeration EMPTY_ENUMERATION
          An empty enumeration.
private static boolean nativeLogExists
          Whether native logarithm function is loaded.
 
Constructor Summary
Util()
           
 
Method Summary
static java.lang.Object append(java.lang.Object values, java.lang.Object value)
          Return array with new component appended.
static void assertion(boolean cond)
          Validate condition.
static byte clearFlag(byte flags, byte mask)
          Clear a flag within a byte of flags.
static boolean contains(java.lang.Object[] set, java.lang.Object item)
          Return whether a given Objects exists within an Object array.
private static float fast_log(float n)
          Native logarithm function.
static double fromDB(double x)
          Convert number from decibels.
static boolean getFlag(byte flags, byte mask)
          Return status of a single bit within a byte of flags.
static float log(float n)
          Native logarithm function wrapper.
static void printMemoryStats()
          Print memory statistics.
static long randomTime(long bound)
          Return random long between 0 (inclusive) and bound (exclusive).
static java.lang.String[] readLines(java.io.File f)
          Read all lines of a file.
static java.lang.String[] readLines(java.lang.String filename)
          Read all lines of a file.
static java.lang.Object rest(java.lang.Object values)
          Return array with all but first component.
static byte setFlag(byte flags, byte mask)
          Set a flag within a byte of flags.
static byte setFlag(byte flags, byte mask, boolean value)
          Set status of a single bit within a byte of flags.
static double square(double x)
          Return number squared.
static int square(int x)
          Return number squared.
static java.lang.String stringJoin(java.lang.Object[] objs, java.lang.String delim)
          Concatenate array of Strings separated by given delimeter.
static java.lang.String timeSeconds()
          Return current simulation time as string in seconds.
static double toDB(double x)
          Convert number to decibels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ENUMERATION

public static final java.util.Enumeration EMPTY_ENUMERATION
An empty enumeration.


nativeLogExists

private static final boolean nativeLogExists
Whether native logarithm function is loaded.

Constructor Detail

Util

public Util()
Method Detail

square

public static double square(double x)
Return number squared.

Parameters:
x - number to square
Returns:
number squared

square

public static int square(int x)
Return number squared.

Parameters:
x - number to square
Returns:
number squared

toDB

public static double toDB(double x)
Convert number to decibels.

Parameters:
x - number to convert
Returns:
number in decibels

fromDB

public static double fromDB(double x)
Convert number from decibels.

Parameters:
x - number to convert
Returns:
number on linear scale

readLines

public static java.lang.String[] readLines(java.io.File f)
                                    throws java.io.IOException
Read all lines of a file.

Parameters:
f - file to read
Returns:
array of lines read from file
Throws:
java.io.IOException - on any input error

readLines

public static java.lang.String[] readLines(java.lang.String filename)
                                    throws java.io.IOException
Read all lines of a file.

Parameters:
filename - name of file to read
Returns:
array of lines read from file
Throws:
java.io.IOException - on any input error

printMemoryStats

public static void printMemoryStats()
Print memory statistics. Displays internal VM measurements as well as (if possible) some Linux process measurements.


timeSeconds

public static java.lang.String timeSeconds()
Return current simulation time as string in seconds.

Returns:
string with current simulation time in seconds.

fast_log

private static float fast_log(float n)
Native logarithm function.

Parameters:
n - number to log
Returns:
log of given number

log

public static float log(float n)
Native logarithm function wrapper. Will use the regular Java Math.log if the native function is not available.

Parameters:
n - number to log
Returns:
log of given number

assertion

public static void assertion(boolean cond)
Validate condition.

Parameters:
cond - condition to validate

contains

public static boolean contains(java.lang.Object[] set,
                               java.lang.Object item)
Return whether a given Objects exists within an Object array.

Parameters:
set - an array of objects to test for membership
item - object to test membership
Returns:
whether given item exists in the given set

stringJoin

public static java.lang.String stringJoin(java.lang.Object[] objs,
                                          java.lang.String delim)
Concatenate array of Strings separated by given delimeter.

Parameters:
objs - array of objects to stringify and concatenate
delim - delimeter to insert between each pair of strings
Returns:
delimited concatenation of strings

rest

public static java.lang.Object rest(java.lang.Object values)
Return array with all but first component.

Parameters:
values - array to copy all but first component
Returns:
array with all but first component

append

public static java.lang.Object append(java.lang.Object values,
                                      java.lang.Object value)
Return array with new component appended.

Parameters:
values - array to copy and append to
value - component to append
Returns:
array with new value appended

randomTime

public static long randomTime(long bound)
Return random long between 0 (inclusive) and bound (exclusive).

Parameters:
bound - upper bound of range
Returns:
random long between 0 (inclusive) and bound (exclusive)

getFlag

public static boolean getFlag(byte flags,
                              byte mask)
Return status of a single bit within a byte of flags.

Parameters:
flags - byte of flags
mask - mask of bit to read
Returns:
status of masked bit

setFlag

public static byte setFlag(byte flags,
                           byte mask,
                           boolean value)
Set status of a single bit within a byte of flags.

Parameters:
flags - byte of flags
mask - mask of bit to be set
value - new value for bit
Returns:
new flags value with status of single bit set to value

setFlag

public static byte setFlag(byte flags,
                           byte mask)
Set a flag within a byte of flags.

Parameters:
flags - byte of flags
mask - mask of bit to be set
Returns:
new flags value with status of single bit set on

clearFlag

public static byte clearFlag(byte flags,
                             byte mask)
Clear a flag within a byte of flags.

Parameters:
flags - byte of flags
mask - mask of bit to be set
Returns:
new flags value with status of single bit cleared