com.marringtons.string
Class Convert

java.lang.Object
  extended bycom.marringtons.string.Convert

public class Convert
extends Object

Convert to and from a String Object from various internal forms, including integers and boolean primatives.

Author:
Paul Marrington

Nested Class Summary
static class Convert.Exception
          Thrown by any conversion utility on error.
 
Method Summary
static String pad(int number, int places)
          Return a string converted from an integer and zero padded 1 == 001.
static boolean toBoolean(String string)
          Convert a string to boolean.
static String toString(boolean flag)
          Convert a Boolean to a readable string boolean check = askUser( "Shall I check?")
static String toString(boolean flag, String type)
          Convert a Boolean to a readable string string = Convert.toString( flag, "yes"); string = Convert.toString( flag, "oui");
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toBoolean

public static boolean toBoolean(String string)
                         throws Convert.Exception
Convert a string to boolean. Can be case independant and starts with yes/true/on/oui/da/si or no/false/off/non. All can be shortened to the least unique string (y is yes).
 String question = askUser( "do it [y/n]?");
 boolean answer = Convert.toBoolean( question);
 

Parameters:
string - string to test
Returns:
boolean true if of true list, false if of false list
Throws:
Convert.Exception - throws if not in true or false list

toString

public static String toString(boolean flag)
Convert a Boolean to a readable string
 boolean check = askUser( "Shall I check?");
 System.out.print( "Check = "+Convert.toString( check));
 

Parameters:
flag - boolean to convert
Returns:
uses first in the truth/untruth array (true/false).

toString

public static String toString(boolean flag,
                              String type)
Convert a Boolean to a readable string
 string = Convert.toString( flag, "yes");
 string = Convert.toString( flag, "oui");
 

Parameters:
flag - boolean to convert
type - string type using affirmative (yes/true/on/qui/da/si).
Returns:
true/false string based on type.

pad

public static String pad(int number,
                         int places)
Return a string converted from an integer and zero padded 1 == 001.

Parameters:
number - integer to convert to a string
places - fixed number of digits
Returns:
padded number (0s on left)


Copyright © 2005 Paul Marrington http://library.marringtons.com