support.Flight
Class StandardOps

java.lang.Object
  |
  +--support.Flight.StandardOps

public class StandardOps
extends java.lang.Object

Some operations the support code likes to do. You may also want to use them for debugging output, or for allowing the user to input a time.

Note that all functions are static, so you call them as:

  StandardOps.printInt(1, 5, '0'); 
And so on.


Field Summary
private static int HOURLEN
           
private static int HOUROFF
           
private static int MERIDIANLEN
           
private static int MERIDIANOFF
           
private static int MINUTELEN
           
private static int MINUTEOFF
           
static int NOON
           
 
Constructor Summary
private StandardOps()
          Can't construct one of these; don't need to, either.
 
Method Summary
static int parseInt(java.lang.String str)
          Parses the string as an integer.
static int parseTime(java.lang.String str)
          Parses a String in the format of printTime(.) as a time.
static java.lang.String printInt(int toprint, int width, char fill)
          Creates a string corresponding to the integer with the specified width and left-fill.
static java.lang.String printInt(int toprint, int width, java.lang.String fill)
          Similar to above, but fills with a String.
static java.lang.String printTime(int time)
          Creates a string corresponding to the time.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

NOON

public static int NOON

HOURLEN

private static final int HOURLEN

MINUTELEN

private static final int MINUTELEN

MERIDIANLEN

private static final int MERIDIANLEN

HOUROFF

private static final int HOUROFF

MINUTEOFF

private static final int MINUTEOFF

MERIDIANOFF

private static final int MERIDIANOFF
Constructor Detail

StandardOps

private StandardOps()
Can't construct one of these; don't need to, either.
Method Detail

printInt

public static java.lang.String printInt(int toprint,
                                        int width,
                                        char fill)
Creates a string corresponding to the integer with the specified width and left-fill. The width is a minimum; if the integer does not fit, it will be wider.

Example:

  StandardOps.printInt(1, 5, '0'); 
will print
  00001
Parameters:
toprint - The integer to print
width - The minimum width of the integer
fill - The character with which to left-fill the string
Returns:
The String corresponding to the integer.

printInt

public static java.lang.String printInt(int toprint,
                                        int width,
                                        java.lang.String fill)
Similar to above, but fills with a String. Not too useful.

Example:

  StandardOps.printInt(1, 5, "abcde"); 
will print
  abcd1
Parameters:
toprint - The integer to print
width - The minimum width of the integer
fill - The filler string; uses the substring corresponding to the first i characters of the filler, where i is the amount of room free.
Returns:
The String corresponding to the integer.

parseInt

public static int parseInt(java.lang.String str)
Parses the string as an integer. Deals with leading sign, leading zeros, and leading whitespace. Essentially, a kinder, saner version of Integer.parseInt.

Example:

  StandardOps.parseInt("  -09a"); 
will return -9.
Parameters:
str - The string to parse.
Returns:
The integer to which the string corresponds, or 0 if the string doesn't parse.
See Also:
Integer.parseInt(java.lang.String)

printTime

public static java.lang.String printTime(int time)
Creates a string corresponding to the time. The time is assumed to be in minutes since midnight. The output format is hhmmM -- that is, 2-digit hours, 2-digit minutes, 1-character meridian. Hours and minutes are left-filled with zeros. Note 1259P is one minute before 0100P.

Example:

  StandardOps.printTime(60); 
will print
  0100A
Parameters:
time - The time to print, in minutes since midnight.
Returns:
The String corresponding to the time, formatted as on airplane tickets.

parseTime

public static int parseTime(java.lang.String str)
                     throws java.lang.IllegalArgumentException
Parses a String in the format of printTime(.) as a time. Takes a string in the format hhmmM and returns the number of minutes since midnight to which the string corresponds. Throws an IllegalArgumentException if the conversion fails.

Example:

  StandardOps.parseTime("0100A"); 
will return 60.
Parameters:
str - The string to parse.
Returns:
The corresponding number of minutes since midnight.
Throws:
java.lang.IllegalArgumentException - if the string cannot be converted (it is too short, or the meridian field is not A, N, or P, or is not a valid time).