sim.util
Class Utilities

java.lang.Object
  extended by sim.util.Utilities

public class Utilities
extends java.lang.Object

Various static utility methods.


Constructor Summary
Utilities()
           
 
Method Summary
static void doEnsuredRepaint(java.awt.Component component)
          Does a repaint that is guaranteed to work (on some systems, plain repaint()) fails if there's lots of updates going on as is the case in our simulator thread.
static java.lang.Thread doLater(long milliseconds, java.lang.Runnable doThis)
          Schedule something to occur at some specified point in the future in the Swing Event thread.
static java.lang.String ensureFileEndsWith(java.lang.String filename, java.lang.String ending)
          Returns a filename guaranteed to end with the given ending.
static int iCeil(double d)
          Returns the integer ceiling of a double, or as close as possible.
static int iFloor(double d)
          Returns the integer floor of a double, or as close as possible.
static void inform(java.lang.String description, java.lang.String subDescription, javax.swing.JFrame frame)
          Pops up an message dialog box.
static void informOfError(java.lang.Throwable error, java.lang.String description, javax.swing.JFrame frame)
          Pops up an error dialog box.
static int iRound(double d)
          Returns the integer floor of a double, or as close as possible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utilities

public Utilities()
Method Detail

iFloor

public static int iFloor(double d)
Returns the integer floor of a double, or as close as possible. The return value of NaN is undefined: it's often zero but doesn't have to be. This is about twice as fast as (int)Math.floor(d) up through at least Java6.


iCeil

public static int iCeil(double d)
Returns the integer ceiling of a double, or as close as possible. The return value of NaN is undefined: it's often zero but doesn't have to be. This is about twice as fast as (int)Math.ceil(d) up through at least Java6.


iRound

public static int iRound(double d)
Returns the integer floor of a double, or as close as possible. The return value of NaN is undefined: it's often zero but doesn't have to be. This is about twice as fast as (int)Math.round(d), though it can't get inlined because it's 40 bytes. :-(


ensureFileEndsWith

public static java.lang.String ensureFileEndsWith(java.lang.String filename,
                                                  java.lang.String ending)
Returns a filename guaranteed to end with the given ending.


doEnsuredRepaint

public static void doEnsuredRepaint(java.awt.Component component)
Does a repaint that is guaranteed to work (on some systems, plain repaint()) fails if there's lots of updates going on as is the case in our simulator thread. Notably, MacOS X 1.3.1 has problems.


doLater

public static java.lang.Thread doLater(long milliseconds,
                                       java.lang.Runnable doThis)
Schedule something to occur at some specified point in the future in the Swing Event thread.


informOfError

public static void informOfError(java.lang.Throwable error,
                                 java.lang.String description,
                                 javax.swing.JFrame frame)
Pops up an error dialog box. error should be the error proper, and description should be some user-informative item that's shown first (the user must explicitly ask to be shown the raw error itself). frame is a window on which the error box should be centered: if it is null, the error box will be centered in the screen. The error is also printed to the console.


inform

public static void inform(java.lang.String description,
                          java.lang.String subDescription,
                          javax.swing.JFrame frame)
Pops up an message dialog box. frame is a window on which the error box should be centered: if it is null, the error box will be centered in the screen. The error is also printed to the console.