JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.util
Class JCTypeConverter

java.lang.Object
  |
  +--com.klg.jclass.util.JCTypeConverter

public class JCTypeConverter
extends Object

JCTypeConverter contains static methods for retrieving parameters from a source file or applet, and for converting parameters to particular data types.


Field Summary
static boolean reportErrors
           
 
Constructor Summary
JCTypeConverter()
           
 
Method Summary
static void checkEnum(int value, String param, int[] values)
          Checks the validity of an enum.
static void error(String msg)
          Writes a parse error message to stdout.
static void error(String s, String token)
          Writes a parse error message to stdout.
static String fromDate(Date d, String def)
          Converts a Date to a proper String that can be read back in parsed to a date.
static String fromEnum(int value, String[] strings, int[] values)
          Converts an enum to a String.
static String fromEnum(int value, String param, String type, String[][] strings, int[][] values, String def)
          Converts an enum to a String.
static String fromEnum(long value, String[] strings, long[] values)
          Converts an enum to a String where the enum index is a long.
static String fromMatchListObject(Object value, String[] strings, Object[] values)
          Finds an object within a match list of objects and returns the corresponding String from a synched-up String list.
static String fromNewLine(String s)
          Converts all occurrences of char '\n' to String "\n".
static String fromPointList(Point[] parray, char delim)
          Converts an array of Points to a String in which the x,y pairs are separated by the specified delimiter.
static String fromStringList(List slist)
          Converts a List of Strings to a comma-separated String.
static String fromStringList(List slist, char delim)
          Converts a List of Strings to a String in which values are separated by the specified delimiter.
static String fromStringList(String[] slist)
          Converts an array of Strings to a comma-separated String.
static String fromStringList(String[] slist, char delim)
          Converts an array of Strings to a String in which values are separated by the specified delimiter.
static void parseError(String token)
          Displays a parsing error.
static String removeEscape(String s)
          Removes "escape" characters (backslashes) from the String.
static boolean toBoolean(String s, boolean def)
          Converts a String to a boolean.
static Date toDate(String s, Date def)
          Converts a String to a Date.
static double toDouble(String s, double def)
          Converts a String to a double.
static Double[] toDoubleList(String s, char delim)
          Converts a String to an array of Double objects based on the provided delimiter.
static Double[] toDoubleList(String s, char delim, Double[] def)
          Converts a String to an array of integers based on the provided delimiter.
static int toEnum(String s, String[] strings, int[] values, int def)
          Converts a String to an enum.
static int toEnum(String s, String type, String[] strings, int[] values, int def)
          Converts a String to an enum.
static long toEnum(String s, String type, String[] strings, long[] values, long def)
          Converts a String to an enum.
static int toEnum(String string, String type, String param, String[][] strings, int[][] values, int def)
          Converts a String to an enum.
static int[] toEnumList(String s, String type, String[] strings, int[] values, int[] def)
          Converts a String to a list of enums.
static int toInt(String s, int def)
          Converts a String to an integer.
static Integer[] toIntegerList(String s, char delim)
          Converts a String to an array of Integer objects based on the provided delimiter.
static Integer[] toIntegerList(String s, char delim, Integer[] def)
          Converts a String to an array of integers based on the provided delimiter.
static int[] toIntList(String s, char delim)
          Converts a String to an array of integers based on the provided delimiter.
static int[] toIntList(String s, char delim, int[] def)
          Converts a String to an array of integers based on the provided delimiter.
static Object toMatchListObject(String value, String[] strings, Object[] values)
          Finds a String within a match list of Strings and returns the corresponding object from a synched-up object list.
static String toNewLine(String string)
          Converts all occurrences of "\n" in a String to newlines.
static Point[] toPointList(String s, char delim)
          Converts a String to an array of Points.
static String toString(Object o)
          Converts an object to a String.
static String[] toStringList(String s)
          Converts a String to an array of Strings.
static String[] toStringList(String s, char delim)
          Converts a String to an array of Strings.
static String[] toStringList(String s, char delim, boolean trim)
          Converts a String to an array of Strings.
static Vector toVector(String s, char delim)
          Converts a delimited list of tokens to a Vector.
static Vector toVector(String s, char delim, Vector def)
          Converts a delimited list of tokens to a Vector.
static String trim(Object obj)
          Returns a trimmed String, with trailing nulls removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reportErrors

public static boolean reportErrors
Constructor Detail

JCTypeConverter

public JCTypeConverter()
Method Detail

error

public static void error(String s,
                         String token)
Writes a parse error message to stdout.

Parameters:
s - the entire string being parsed
token - the String which could not be parsed

error

public static void error(String msg)
Writes a parse error message to stdout.

Parameters:
msg - the String which could not be parsed

parseError

public static void parseError(String token)
Displays a parsing error.

Parameters:
token - the token on which the error happened

trim

public static String trim(Object obj)
Returns a trimmed String, with trailing nulls removed.

Parameters:
obj - the object to trim
Returns:
the trimmed String

toInt

public static int toInt(String s,
                        int def)
Converts a String to an integer.

Parameters:
s - the String for conversion
def - the default value to be used when a parsing error occurs
Returns:
the integer resulting from the converson of the String

toDouble

public static double toDouble(String s,
                              double def)
Converts a String to a double.

Parameters:
s - the String for conversion
def - the default value to be used when a parsing error occurs
Returns:
the double resulting from the converson of the String

toBoolean

public static boolean toBoolean(String s,
                                boolean def)
Converts a String to a boolean.

Parameters:
s - the String for conversion
def - the default value to be used when a parsing error occurs
Returns:
the boolean resulting from the converson of the String

toStringList

public static String[] toStringList(String s)
Converts a String to an array of Strings.

Parameters:
s - the comma-separated Strings
Returns:
the String list resulting from the converson of the String

toStringList

public static String[] toStringList(String s,
                                    char delim)
Converts a String to an array of Strings. Spaces are trimmed.

Parameters:
s - the Strings separated by delimiter
delim - the delimiter
Returns:
the String list resulting from the converson of the String

toStringList

public static String[] toStringList(String s,
                                    char delim,
                                    boolean trim)
Converts a String to an array of Strings.

Parameters:
s - the Strings separated by delimiter
delim - the delimiter
trim - boolean to indicate if spaces are trimmed
Returns:
the String list resulting from the converson of the String

toPointList

public static Point[] toPointList(String s,
                                  char delim)
Converts a String to an array of Points.

Parameters:
s - A String of x,y pairs
delim - the delimiter used to separate the x,y pairs
Returns:
the Point array resulting from the conversion of the String

fromStringList

public static String fromStringList(String[] slist)
Converts an array of Strings to a comma-separated String.

Parameters:
slist - the array of Strings
Returns:
the String resulting from the converson of the String list

fromStringList

public static String fromStringList(String[] slist,
                                    char delim)
Converts an array of Strings to a String in which values are separated by the specified delimiter.

Parameters:
slist - the array of Strings
delim - the delimiter
Returns:
the String resulting from the converson of the String list

fromStringList

public static String fromStringList(List slist)
Converts a List of Strings to a comma-separated String.

Parameters:
slist - the array of Strings
Returns:
the String resulting from the converson of the String list

fromStringList

public static String fromStringList(List slist,
                                    char delim)
Converts a List of Strings to a String in which values are separated by the specified delimiter.

Parameters:
slist - the array of Strings
delim - the delimiter
Returns:
the String resulting from the converson of the List of Strings

fromPointList

public static String fromPointList(Point[] parray,
                                   char delim)
Converts an array of Points to a String in which the x,y pairs are separated by the specified delimiter.

Parameters:
parray - the array of Points
delim - the delimiter
Returns:
the String resulting from the conversion of the Point array.

toIntList

public static int[] toIntList(String s,
                              char delim)
Converts a String to an array of integers based on the provided delimiter.

Parameters:
s - the String which will be converted to integers
delim - the delimiter separating the integers in the String
Returns:
the int list resulting from the converson of the String

toIntegerList

public static Integer[] toIntegerList(String s,
                                      char delim)
Converts a String to an array of Integer objects based on the provided delimiter.

Parameters:
s - the String which will be converted to Integers
delim - the delimiter separating the Integers in the String
Returns:
the Integer list resulting from the converson of the String

toDoubleList

public static Double[] toDoubleList(String s,
                                    char delim)
Converts a String to an array of Double objects based on the provided delimiter.

Parameters:
s - the String which will be converted to Doubles
delim - the delimiter separating the Doubles in the String
Returns:
the Double list resulting from the converson of the String

toIntList

public static int[] toIntList(String s,
                              char delim,
                              int[] def)
Converts a String to an array of integers based on the provided delimiter.

Parameters:
s - the String which will be converted to integers
delim - the delimiter separating the integers in the String
def - the default value, returned if a parse error occurs
Returns:
the int list resulting from the converson of the String

toIntegerList

public static Integer[] toIntegerList(String s,
                                      char delim,
                                      Integer[] def)
Converts a String to an array of integers based on the provided delimiter.

Parameters:
s - the String which will be converted to integers
delim - the delimiter separating the integers in the String
def - the default value, returned if a parse error occurs
Returns:
the Integer list resulting from the converson of the String

toDoubleList

public static Double[] toDoubleList(String s,
                                    char delim,
                                    Double[] def)
Converts a String to an array of integers based on the provided delimiter.

Parameters:
s - the String which will be converted to integers
delim - the delimiter separating the integers in the String
def - the default value, returned if a parse error occurs
Returns:
the Double list resulting from the converson of the String

toNewLine

public static String toNewLine(String string)
Converts all occurrences of "\n" in a String to newlines.

Parameters:
string - the string to parse
Returns:
the new String with the new lines replaced

fromNewLine

public static String fromNewLine(String s)
Converts all occurrences of char '\n' to String "\n".

Parameters:
s - the String to parse
Returns:
the new String with the char '\n' occurences replaced

toVector

public static Vector toVector(String s,
                              char delim)
Converts a delimited list of tokens to a Vector.

Parameters:
s - the String to convert
delim - the delimiter that separates the tokens in the String
Returns:
the Vector resulting from the conversion of the String

toVector

public static Vector toVector(String s,
                              char delim,
                              Vector def)
Converts a delimited list of tokens to a Vector.

Parameters:
s - the String to convert
delim - the delimiter that separates the tokens in the String
def - the default value, returned if a parse error occurs
Returns:
the Vector resulting from the conversion of the String

toEnum

public static int toEnum(String string,
                         String type,
                         String param,
                         String[][] strings,
                         int[][] values,
                         int def)
Converts a String to an enum. If the String cannot be converted, an error message is written to the console.

Parameters:
string - the String to be converted
type - the enum type
param - the optional PARAM name for the enum, used for the error message
strings - the first item in each list is the enum type; each String has a corresponding value in the values array
values - list of values corresponding to the Strings
def - the default value, returned if the String could not be converted
Returns:
either the converted value or the default

toEnum

public static int toEnum(String s,
                         String type,
                         String[] strings,
                         int[] values,
                         int def)
Converts a String to an enum. If the String cannot be converted, an error message is written to the console.

Parameters:
s - the String to be converted
type - the enum type (for the console message)
strings - list of valid Strings
values - list of values corresponding to each String
def - the default value, returned if the String could not be converted
Returns:
either the converted value or the default

toEnum

public static long toEnum(String s,
                          String type,
                          String[] strings,
                          long[] values,
                          long def)
Converts a String to an enum. If the String cannot be converted, an error message is written to the console.

Parameters:
s - the String to be converted
type - the enum type (for the console message)
strings - list of valid Strings
values - list of values corresponding to each String
def - the default value, returned if the String could not be converted
Returns:
either the converted value or the default

toEnum

public static int toEnum(String s,
                         String[] strings,
                         int[] values,
                         int def)
Converts a String to an enum.

Parameters:
s - the String to be converted
strings - list of valid Strings
values - list of values corresponding to each String
def - the default value, returned if the String could not be converted
Returns:
the converted value or the default

toEnumList

public static int[] toEnumList(String s,
                               String type,
                               String[] strings,
                               int[] values,
                               int[] def)
Converts a String to a list of enums. If the String cannot be converted, an error message is written to the console.

Parameters:
s - the comma-separated list of enums
type - the enum type
strings - valid Strings
values - list of values corresponding to each String
def - the default value, returned if the String could not be converted
Returns:
either the converted value or the default

fromEnum

public static String fromEnum(int value,
                              String[] strings,
                              int[] values)
Converts an enum to a String.

Parameters:
value - the enum to be converted
strings - list of valid Strings
values - list of values corresponding to each String
Returns:
either the converted value or null

fromEnum

public static String fromEnum(long value,
                              String[] strings,
                              long[] values)
Converts an enum to a String where the enum index is a long.

Parameters:
value - the enum to be converted
strings - list of valid Strings
values - list of values corresponding to each String
Returns:
either the converted value or null

fromEnum

public static String fromEnum(int value,
                              String param,
                              String type,
                              String[][] strings,
                              int[][] values,
                              String def)
Converts an enum to a String. If the enum cannot be converted, an error message is written to the console.

Parameters:
value - the enum to be converted
param - the optional PARAM name for the enum, used for the error message
type - the enum type
strings - the first item in each list is the enum type; each String has a corresponding value in the values array
values - list of values corresponding to the Strings
def - the default value, returned if the enum could not be converted
Returns:
either the converted value or the default

fromMatchListObject

public static String fromMatchListObject(Object value,
                                         String[] strings,
                                         Object[] values)
Finds an object within a match list of objects and returns the corresponding String from a synched-up String list.

Parameters:
value - the object to be converted
strings - list of Strings corresponding to each object in the values list
values - list of objects being searched
Returns:
either the converted value or null

toMatchListObject

public static Object toMatchListObject(String value,
                                       String[] strings,
                                       Object[] values)
Finds a String within a match list of Strings and returns the corresponding object from a synched-up object list.

Parameters:
value - the String to be converted
strings - list of Strings being searched
values - list of objects corresponding to each String in the Strings list
Returns:
either the converted value or null

checkEnum

public static void checkEnum(int value,
                             String param,
                             int[] values)
Checks the validity of an enum.

Parameters:
value - the enum value to check
param - enum name, used for error message
values - the array in which to check for the value
Throws:
IllegalArgumentException - If the value is invalid.

toString

public static String toString(Object o)
Converts an object to a String. If a String, newlines are replaced by "\n". If a Vector, it is converted to a comma-separated list.

Parameters:
o - the object to be converted to a String
Returns:
the String resulting from the conversion of the object

toDate

public static Date toDate(String s,
                          Date def)
Converts a String to a Date.

Parameters:
s - the String to convert
def - the default value, returned if the String could not be converted
Returns:
the Date resulting from the conversion of the String

fromDate

public static String fromDate(Date d,
                              String def)
Converts a Date to a proper String that can be read back in parsed to a date.

Parameters:
d - the date to convert
def - the default String to return if the date could not be converted
Returns:
the String resulting from the conversion of the date

removeEscape

public static String removeEscape(String s)
Removes "escape" characters (backslashes) from the String.

Parameters:
s - the String from which the "escape" characters are to be removed
Returns:
the String which the "escape" characters removed

Copyright © 2004 Quest Software Inc..
All rights reserved.