dLife Home Page

dlife.sys
Class Utility

java.lang.Object
  extended by dlife.sys.Utility

public class Utility
extends Object

A catch-all class for some small utility functions that are used throughout the dlife package.

Version:
May 12, 2007
Author:
Grant Braught, Dickinson College

Constructor Summary
Utility()
           
 
Method Summary
static void beep()
          Emit a standard beep.
static Object invokeMethod(Object obj, String name, Class<?>[] argTypes, Object[] args)
          Invoke the specified private/protected/package method on the specified object with the specified arguments.
static int roundHalfUp(double val)
          Round the provided double value to the nearest integer according to the HALF_UP rounding mode as described by the RoundingMode enum.
static boolean runningInTest()
          This method returns true if a junit test is running and false otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utility

public Utility()
Method Detail

runningInTest

public static boolean runningInTest()
This method returns true if a junit test is running and false otherwise. It determines if it has been called as part of a junit test by examining the call stack of every running thread for any class the junit.framework package.

Returns:
true if this method is invoked during the execution of a junit test and false otherwise.

roundHalfUp

public static int roundHalfUp(double val)
Round the provided double value to the nearest integer according to the HALF_UP rounding mode as described by the RoundingMode enum. The HALF_UP rounding mode rounds out away from 0. For example:
  -1.1 -> -1 
  +1.1 -> +1 
  -1.7 -> -2 
  +1.7 -> +2
 

Note that to reduce overhead this method does not actually use the HALF_UP RoudingMode, which would require the creation of a BigDecimal. Rather it just rounds using the same rules as HALF_UP.

Parameters:
val - the value to be rounded.
Returns:
the value rounded according to the HALF_UP rounding mode.

beep

public static void beep()
Emit a standard beep.


invokeMethod

public static Object invokeMethod(Object obj,
                                  String name,
                                  Class<?>[] argTypes,
                                  Object[] args)
Invoke the specified private/protected/package method on the specified object with the specified arguments. The argTypes array must contain the types of the arguments. Use Integer.TYPE, Double.TYPE etc for primitive type arguments in the argTypes array. The corresponding values in the args array must then be Integer or Double values.

Returns:
the value returned from the method or null.

dLife Home Page