Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.statcato.utils
Class HelperFunctions

    java.lang.Object
      org.statcato.utils.HelperFunctions

    public class HelperFunctions

extends java.lang.Object

Miscellaneous utilities functions.

Author:
  Margaret Yau

Constructor Summary
`HelperFunctions()`

Method Summary
`static java.util.Vector<java.lang.Double>` | `addConstantVector(java.util.Vector<java.lang.Double> numbers, double c)` Returns a copy of a vector of double values in which a constant is added to each element.
`static java.lang.Object[]` | `ComputeCategoryFrequency(java.util.Vector<Cell> vec)` Given a vector of cells, computes the frequency of each category present in the vector.
`static java.util.Vector<java.lang.Double>` | `ComputeClassFrequency(java.util.Vector<java.lang.Double> column, java.util.Vector<java.lang.Double> limits)` Return a vector containing the frequency of each class delimited by the given vector of upper class limits.
`static java.util.Vector<java.lang.Double>` | `ComputeDiffVector(java.util.Vector<java.lang.Double> vector1, java.util.Vector<java.lang.Double> vector2)` Computes the pairwise differences between elements in two vector of numbers and returns a vector of the pairwise differences.
`static java.util.TreeMap` | `ComputeFrequency(java.util.Vector<java.lang.Double> vec)` Given a vector of double values, computes the frequency of each value present in the vector.
`static java.util.Vector<java.lang.String>` | `ConvertCellVectorToStringVector(java.util.Vector<Cell> vector)`
`static double[]` | `ConvertDoubleVectorToArray(java.util.Vector<java.lang.Double> vector)` Converts a vector of Double values to an array of double values.
`static java.util.Vector<java.lang.String>` | `ConvertDoubleVectorToString(java.util.Vector<java.lang.Double> vector)` Convert a vector of Double to a vector of String.
`static java.util.Vector<java.lang.Double>` | `ConvertInputVectorToDoubles(java.util.Vector<Cell> vector)` Converts a vector of Cell to a vector of Double.
`static java.lang.Object[]` | `ConvertInputVectorToNumbers(java.util.Vector<Cell> vector)` Converts a vector of Cell to a vector of numbers.
`static java.lang.Object[]` | `ConvertInputVectorToNumbers2(java.util.Vector<Cell> vector)` Converts a vector of Cell to a vector of numbers.
`static int[]` | `ConvertIntegerVectorToArray(java.util.Vector<java.lang.Integer> vector)` Converts a vector of Integer values to an array of integervalues.
`static java.lang.String` | `convertVectorToString(java.util.Vector vec)` Converts the contents of a vector to a string, each item separated by a space.
`static java.lang.String` | `formatFloat(double num)` Returns a string format of a double.
`static java.lang.String` | `formatFloat(java.lang.Double num)` Returns a string format of a Double using `formatFloat(double)`.
`static java.lang.String` | `formatFloat(double num, int places)` Returns a string format of a double with a specified number of decimal places.
`static java.lang.String` | `formatFloat2(double num)` Returns a string format of a double.
`static java.lang.String` | `getCellValue(org.apache.poi.hssf.usermodel.HSSFCell cell)` Returns the value of a HSSFCell as a string.
`static java.lang.String` | `getCurrentTimeString()` Returns a string representing the current date and time (mmddyyyyhhss).
`static java.lang.String` | `getDateTime()` Returns a string of formatted date and time.
`static java.lang.String` | `getFileContents(java.io.File file)` Returns a string of textual data stored in the given file.
`static int` | `getNumDecimalPlaces(java.lang.String s)`
`static java.lang.String` | `getVersionNumberFromWeb()` Returns the current version number from the Statcato web site.
`static java.util.Vector<java.lang.Double>` | `logVector(java.util.Vector<java.lang.Double> numbers)` Returns a copy of a vector of Double in which each element is replaced by its natural logarithm.
`static java.lang.String` | `parseCSV(java.lang.String str)` Parses a string of comma-separated values and converts it into a string of tab-delimited values.
`static java.util.Vector<java.lang.String>` | `parseString(java.lang.String str)` Returns a vector of substrings in the given input string.
`static java.util.Vector<java.lang.Double>` | `powerVector(java.util.Vector<java.lang.Double> numbers, double power)` Returns a copy of a vector of Double in which each element is raised to a given power.
`static java.util.Vector<java.lang.Double>` | `powerVector(java.util.Vector<java.lang.Double> numbers, int power)` Returns a copy of a vector of Double in which each element is raised to a given power.
`static java.lang.String` | `printDoubleVectorToString(java.util.Vector<java.lang.Double> vec)`
`static void` | `printVector(java.util.Vector vec)` Displays to standard output the contents of a vector.
`static void` | `printVectors(java.util.Vector<java.util.Vector<Cell>> vec)` Prints the contents of a vector of vectors to the standard output.
`static java.lang.String` | `printVectorToString(java.util.Vector vec)`
`static java.util.Vector<java.lang.String>` | `readExcelFile(java.io.File file)` Reads an Excel file and returns its contents as a vector of strings of tab-delimited values.
`static java.util.Vector<Cell>` | `removeEndingEmptyCells(java.util.Vector<Cell> vector)` Returns a copy of a vector of Double in which all the null elements at the end are removed.
`static java.util.Vector<java.lang.Double>` | `removeEndingNullValues(java.util.Vector<java.lang.Double> numbers)` Returns a copy of a vector of Double in which all the null elements at the end are removed.
`static java.util.Vector<Cell>` | `removeNullCells(java.util.Vector<Cell> numbers)` Returns a copy of a vector of Cell in which all the null elements are moved.
`static java.util.Vector<java.lang.Double>` | `removeNullValues(java.util.Vector<java.lang.Double> numbers)` Returns a copy of a vector of Double in which all the null elements are removed.
`static void` | `showErrorDialog(javax.swing.JFrame frame, java.lang.String message)` Displays an error dialog with the given message.
`static java.lang.Object[]` | `splitValuesVector(java.util.Vector<Cell> Values)` Given a vector of two possible values, separate the vector of values corresponding to the labels into two vectors.
`static java.lang.Object[]` | `splitValuesVectorByLabels(java.util.Vector<Cell> Labels, java.util.Vector<Cell> Values)` Given a vector of two possible population labels and a vector of values, separate the vector of values corresponding to the labels into two vectors.
`static void` | `writeFile(javax.swing.JFrame frame, java.lang.String extensionDescription, java.lang.String extension, java.lang.String contents)` Opens a file chooser and saves specified contents to a file with a specified extension.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### HelperFunctions

    public HelperFunctions()

Method Detail

### ConvertDoubleVectorToArray

    public static double[] ConvertDoubleVectorToArray(java.util.Vector<java.lang.Double> vector)

  Converts a vector of Double values to an array of double values.

  Parameters:
    `vector` - vector of Double
  Returns:
    array of double

### ConvertIntegerVectorToArray

    public static int[] ConvertIntegerVectorToArray(java.util.Vector<java.lang.Integer> vector)

  Converts a vector of Integer values to an array of integervalues.

  Parameters:
    `vector` - vector of Integer
  Returns:
    array of integer

### ConvertInputVectorToDoubles

    public static java.util.Vector<java.lang.Double> ConvertInputVectorToDoubles(java.util.Vector<Cell> vector)

  Converts a vector of Cell to a vector of Double. Returns the converted vector, or null if the conversion fails.

  Parameters:
    `vector` - vector of Cell
  Returns:
    vector of Double, of null if conversion fails

### ComputeDiffVector

    public static java.util.Vector<java.lang.Double> ComputeDiffVector(java.util.Vector<java.lang.Double> vector1,
                                                                       java.util.Vector<java.lang.Double> vector2)

  Computes the pairwise differences between elements in two vector of numbers and returns a vector of the pairwise differences.

  Parameters:
    `vector1` - vector of Double
    `vector2` - vector of Double, assumed to have the same size as vector1
  Returns:
    vector of pairwise differences, or null if there is any unmatch pairs

### printVector

    public static void printVector(java.util.Vector vec)

  Displays to standard output the contents of a vector.

  Parameters:
    `vec` - a vector to be displayed

### printVectorToString

    public static java.lang.String printVectorToString(java.util.Vector vec)

### printDoubleVectorToString

    public static java.lang.String printDoubleVectorToString(java.util.Vector<java.lang.Double> vec)

### printVectors

    public static void printVectors(java.util.Vector<java.util.Vector<Cell>> vec)

  Prints the contents of a vector of vectors to the standard output.

  Parameters:
    `vec` - vector of vectors of Cell

### convertVectorToString

    public static java.lang.String convertVectorToString(java.util.Vector vec)

  Converts the contents of a vector to a string, each item separated by a space.

  Parameters:
    `vec` - vector
  Returns:
    string containing items in the input vector separated by a space

### ConvertInputVectorToNumbers

    public static java.lang.Object[] ConvertInputVectorToNumbers(java.util.Vector<Cell> vector)

  Converts a vector of Cell to a vector of numbers. Returns an array of Object containing the converted vector of Double, the number of missing numbers, and the number of nonmissing numbers.

  Parameters:
    `vector` - vector of Cell
  Returns:
    array of Object containing the converted vector of Double, the number of missing numbers, and the number of nonmissing numbers

### ConvertCellVectorToStringVector

    public static java.util.Vector<java.lang.String> ConvertCellVectorToStringVector(java.util.Vector<Cell> vector)

### ConvertInputVectorToNumbers2

    public static java.lang.Object[] ConvertInputVectorToNumbers2(java.util.Vector<Cell> vector)

  Converts a vector of Cell to a vector of numbers. Returns an array of Object containing the converted vector of Double, the number of missing numbers, and the number of nonmissing numbers. Similar to `ConvertInputVectorToNumbers(Vector)`, but count all elements in the vector in the total count.

  Parameters:
    `vector` - vector of Cell
  Returns:
    array of Object containing the converted vector of Double (null if conversion fails), the number of missing numbers, and the number of nonmissing numbers
  See Also:
    `ConvertInputVectorToNumbers(Vector)`

### ConvertDoubleVectorToString

    public static java.util.Vector<java.lang.String> ConvertDoubleVectorToString(java.util.Vector<java.lang.Double> vector)

  Convert a vector of Double to a vector of String.

  Parameters:
    `vector` - vector of Double
  Returns:
    vector of String

### removeNullValues

    public static java.util.Vector<java.lang.Double> removeNullValues(java.util.Vector<java.lang.Double> numbers)

  Returns a copy of a vector of Double in which all the null elements are removed.

  Parameters:
    `numbers` - vector of Double
  Returns:
    vector of Double in which there is no null elements

### removeEndingNullValues

    public static java.util.Vector<java.lang.Double> removeEndingNullValues(java.util.Vector<java.lang.Double> numbers)

  Returns a copy of a vector of Double in which all the null elements at the end are removed.

  Parameters:
    `numbers` - vector of Double
  Returns:
    vector of Double in which there is no null elements

### removeEndingEmptyCells

    public static java.util.Vector<Cell> removeEndingEmptyCells(java.util.Vector<Cell> vector)

  Returns a copy of a vector of Double in which all the null elements at the end are removed.

  Parameters:
    `vector` - vector of Double
  Returns:
    vector of Double in which there is no null elements

### removeNullCells

    public static java.util.Vector<Cell> removeNullCells(java.util.Vector<Cell> numbers)

  Returns a copy of a vector of Cell in which all the null elements are moved.

  Parameters:
    `numbers` - vector of Cell
  Returns:
    vector of Cell in which there is no null elements

### powerVector

    public static java.util.Vector<java.lang.Double> powerVector(java.util.Vector<java.lang.Double> numbers,
                                                                 int power)

  Returns a copy of a vector of Double in which each element is raised to a given power.

  Parameters:
    `numbers` - vector of Double
    `power` - integer to which each element in the vector is raised
  Returns:
    vector of Double

### powerVector

    public static java.util.Vector<java.lang.Double> powerVector(java.util.Vector<java.lang.Double> numbers,
                                                                 double power)

  Returns a copy of a vector of Double in which each element is raised to a given power.

  Parameters:
    `numbers` - vector of Double
    `power` - to which each element in the vector is raised
  Returns:
    vector of Double

### logVector

    public static java.util.Vector<java.lang.Double> logVector(java.util.Vector<java.lang.Double> numbers)

  Returns a copy of a vector of Double in which each element is replaced by its natural logarithm.

  Parameters:
    `numbers` - vector of Double
  Returns:
    vector of Double containing the natural logarithms of the input vector

### addConstantVector

    public static java.util.Vector<java.lang.Double> addConstantVector(java.util.Vector<java.lang.Double> numbers,
                                                                       double c)

  Returns a copy of a vector of double values in which a constant is added to each element.

  Parameters:
    `numbers` - vector of Double
    `c` - constant to be added
  Returns:
    vector of Double containing a vector added a constant

### writeFile

    public static void writeFile(javax.swing.JFrame frame,
                                 java.lang.String extensionDescription,
                                 java.lang.String extension,
                                 java.lang.String contents)

  Opens a file chooser and saves specified contents to a file with a specified extension.

  Parameters:
    `frame` - parent frame
    `extensionDescription` - string description of the file extension
    `extension` - file extension
    `contents` - string contents to be saved

### getFileContents

    public static java.lang.String getFileContents(java.io.File file)

  Returns a string of textual data stored in the given file. Each line is separated by the newline character \n.

  Parameters:
    `file` - file containing data
  Returns:
    string of data from file separated by a newline character

### parseCSV

    public static java.lang.String parseCSV(java.lang.String str)

  Parses a string of comma-separated values and converts it into a string of tab-delimited values.

  Parameters:
    `str` - string of comma-separated values
  Returns:
    string of tab-delimited values

### readExcelFile

    public static java.util.Vector<java.lang.String> readExcelFile(java.io.File file)

  Reads an Excel file and returns its contents as a vector of strings of tab-delimited values.

  Parameters:
    `file` - Excel file
  Returns:
    vector of strings of tab-delimiated values

### getCellValue

    public static java.lang.String getCellValue(org.apache.poi.hssf.usermodel.HSSFCell cell)

  Returns the value of a HSSFCell as a string.

  Parameters:
    `cell` - HSSFCell
  Returns:
    string value

### showErrorDialog

    public static void showErrorDialog(javax.swing.JFrame frame,
                                       java.lang.String message)

  Displays an error dialog with the given message.

  Parameters:
    `frame` - frame of the dialog
    `message` - message to be displayed in the dialog

### getDateTime

    public static java.lang.String getDateTime()

  Returns a string of formatted date and time.

  Returns:
    string of formatted data and time

### formatFloat2

    public static java.lang.String formatFloat2(double num)

  Returns a string format of a double. Double value of 0 is simply returns as "0". Otherwise, numbers are formatted to three decimal places.

  Parameters:
    `num` - double value to be formatted
  Returns:
    string

### formatFloat

    public static java.lang.String formatFloat(double num)

  Returns a string format of a double. Double value of 0 is simply returns as "0". Values less than 0.001 are formatted in scientific notation. Otherwise, numbers are formatted to three decimal places.

  Parameters:
    `num` - double value to be formatted
  Returns:
    string

### formatFloat

    public static java.lang.String formatFloat(java.lang.Double num)

  Returns a string format of a Double using `formatFloat(double)`.

  Parameters:
    `num` - Double to be formatted into a string
  Returns:
    string
  See Also:
    `formatFloat(double)`

### formatFloat

    public static java.lang.String formatFloat(double num,
                                               int places)

  Returns a string format of a double with a specified number of decimal places.

  Parameters:
    `num` - double value to be formatted into a string
    `places` - decimal places
  Returns:
    string
  See Also:
    `formatDecimal(double, int)`

### splitValuesVectorByLabels

    public static java.lang.Object[] splitValuesVectorByLabels(java.util.Vector<Cell> Labels,
                                                               java.util.Vector<Cell> Values)
                                                        throws java.lang.Exception

  Given a vector of two possible population labels and a vector of values, separate the vector of values corresponding to the labels into two vectors. The two vectors are assumed to have the same length.

  Parameters:
    `Labels` -
    `Values` -
  Returns:
    an array of four objects: (1) population label 1; (2) vector of values for label 1; (3) population label 2; (4) vector of values for label 2;
  Throws:
    `java.lang.Exception`

### splitValuesVector

    public static java.lang.Object[] splitValuesVector(java.util.Vector<Cell> Values)
                                                throws java.lang.Exception

  Given a vector of two possible values, separate the vector of values corresponding to the labels into two vectors. The two vectors are assumed to have the same length.

  Parameters:
    `Values` -
  Returns:
    an array of four objects: (1) category label 1; (2) vector of values for label 1; (3) category label 2; (4) vector of values for label 2;
  Throws:
    `java.lang.Exception`

### ComputeCategoryFrequency

    public static java.lang.Object[] ComputeCategoryFrequency(java.util.Vector<Cell> vec)

  Given a vector of cells, computes the frequency of each category present in the vector. Each distinct string in the vector is considered a category.

  Parameters:
    `vec` - a vector of Cell
  Returns:
    an array of two vectors: (1) a vector of Cell representing the categories, (2) a vector of Double representing the respective frequencies.

### ComputeFrequency

    public static java.util.TreeMap ComputeFrequency(java.util.Vector<java.lang.Double> vec)

  Given a vector of double values, computes the frequency of each value present in the vector.

  Parameters:
    `vec` - a vector of Cell
  Returns:
    a TreepMap where the key is a double value present in the vector and the value is the frequency of the double value

### ComputeClassFrequency

    public static java.util.Vector<java.lang.Double> ComputeClassFrequency(java.util.Vector<java.lang.Double> column,
                                                                           java.util.Vector<java.lang.Double> limits)

  Return a vector containing the frequency of each class delimited by the given vector of upper class limits.

  Parameters:
    `column` - a vector of numbers to be separated into classes
    `limits` - a vector of numbers representing the upper class limits
  Returns:
    vector of class frequencies

### parseString

    public static java.util.Vector<java.lang.String> parseString(java.lang.String str)

  Returns a vector of substrings in the given input string. Substrings are delimited by "" or space.

  Parameters:
    `str` - string to be parsed
  Returns:
    a vector of substrings

### getNumDecimalPlaces

    public static int getNumDecimalPlaces(java.lang.String s)

### getVersionNumberFromWeb

    public static java.lang.String getVersionNumberFromWeb()

  Returns the current version number from the Statcato web site.

  Returns:
    a string representing the version number or the string "error" if fails to obtain the version number

### getCurrentTimeString

    public static java.lang.String getCurrentTimeString()

  Returns a string representing the current date and time (mmddyyyyhhss).

  Returns:
    string

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD