org.statcato.graph
Class StemAndLeafPlot

java.lang.Object
  extended by org.statcato.graph.StemAndLeafPlot

public class StemAndLeafPlot
extends java.lang.Object

A stem-and-leaf plot.

Since:
1.0
Version:
%I%, %G%
Author:
Margaret Yau

Field Summary
static boolean DEBUG
          Debug flag.
 boolean displayEmptyStem
          A boolean variable indicating whether stems with no leaves should be displayed.
 
Constructor Summary
StemAndLeafPlot(java.util.Vector<java.lang.Double> values, double u)
          Constructor.
 
Method Summary
static double computeCommonLeafUnit(java.util.Vector<java.lang.Double> units)
          Returns the common leaf unit that should be used for the given set of leaf units.
static double computeLeafUnit(double x)
          Computes and returns the proper leaf unit for the given number.
static int getLeaf(double value, double place)
          Returns the leaf of the given double value at the given leaf unit.
static int getLeafIndex(double value, double place)
          Returns the index of the starting location of the leaf in given data value.
 double getLeafUnits()
          Returns the leaf unit used in this stem-and-leaf plot.
static double getStem(double value, double place)
          Returns the stem for the given data value given the leaf unit.
static void printDebug(java.lang.String msg)
          Prints the given debug message to the standard output.
 java.lang.String toString()
          Returns an html formatted string of a table containing the stems and leaves.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEBUG

public static boolean DEBUG
Debug flag.


displayEmptyStem

public boolean displayEmptyStem
A boolean variable indicating whether stems with no leaves should be displayed.

Constructor Detail

StemAndLeafPlot

public StemAndLeafPlot(java.util.Vector<java.lang.Double> values,
                       double u)
Constructor. The data values and the leaf unit are given.

Parameters:
values - vector of double values
u - leaf unit (10^x where x is an integer, -1 if the leaf unit is not pre-determined)
Method Detail

toString

public java.lang.String toString()
Returns an html formatted string of a table containing the stems and leaves.

Overrides:
toString in class java.lang.Object
Returns:
string of html code

getLeafUnits

public double getLeafUnits()
Returns the leaf unit used in this stem-and-leaf plot.

Returns:
leaf unit (double)

getStem

public static double getStem(double value,
                             double place)
Returns the stem for the given data value given the leaf unit.

Parameters:
value - double value
place - leaf unit (double)
Returns:
stem (double)

getLeafIndex

public static int getLeafIndex(double value,
                               double place)
Returns the index of the starting location of the leaf in given data value.

Parameters:
value - double value
place - leaf unit
Returns:
integer index

getLeaf

public static int getLeaf(double value,
                          double place)
Returns the leaf of the given double value at the given leaf unit.

Parameters:
value - double value
place - leaf unit
Returns:
leaf (integer [0,9])

computeLeafUnit

public static double computeLeafUnit(double x)
Computes and returns the proper leaf unit for the given number. The leaf unit for a number is the place to the right of the leftmost non-zero digit.

Parameters:
x - a double value
Returns:
the proper leaf unit for x

computeCommonLeafUnit

public static double computeCommonLeafUnit(java.util.Vector<java.lang.Double> units)
Returns the common leaf unit that should be used for the given set of leaf units. The maximum of the given leaf units is the common leaf unit.

Parameters:
units - vector of leaf units (double values)
Returns:
common leaf unit that should be used for the given set of leaf units

printDebug

public static void printDebug(java.lang.String msg)
Prints the given debug message to the standard output.

Parameters:
msg - string