triptracker.core
Class Utils

java.lang.Object
  extended by triptracker.core.Utils

public class Utils
extends Object

Miscellaneous utility methods.


Constructor Summary
Utils()
           
 
Method Summary
static String dateToString(Date date)
           
static String dateToString(Date date, String datePattern)
           
static String friendlyString(Date date1, Date date2)
           
static String getExtension(String fileName)
          Return the file extension of a file.
static ImageIcon getImageIcon(String file)
          Retrieve an ImageIcon from a resource file located in the "/resources/" folder.
static URL getResource(String file)
          Retrieve an URL for a resource.
static Date parseDate(String dateString)
           
static Date parseDate(String dateString, String datePattern)
           
static double round(double number, int decimals)
          Rounds a number according to Math.round(double) with the specified number of decimals.
static String roundStr(double number, int decimals)
          Rounds a number according to Math.round(double) with the specified number of decimals and returns a string with the exact number of decimals.
static boolean strToBool(String string)
          Returns a boolean value from a string.
static boolean strToBool(String string, boolean def)
          Returns a boolean value from a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

getExtension

public static String getExtension(String fileName)
Return the file extension of a file. Everything after the last "." is returned.

Parameters:
fileName - filename to check
Returns:
file extension

getResource

public static URL getResource(String file)
Retrieve an URL for a resource. This method ensures universal resource retrieval regardless if the application is packaged as a JAR file or not.

Parameters:
file - resource to retrieve
Returns:
resource URL

getImageIcon

public static ImageIcon getImageIcon(String file)
Retrieve an ImageIcon from a resource file located in the "/resources/" folder. This method also works when the application is packaged as a JAR file.

Parameters:
file - resource to retrieve
Returns:
ImageIcon object

round

public static double round(double number,
                           int decimals)
Rounds a number according to Math.round(double) with the specified number of decimals. It also works to set decimals to a negative number to round down to whole hundreds, thousands, etc.

Parameters:
number - number to round
decimals - number of decimals to preserve
Returns:
rounded number

roundStr

public static String roundStr(double number,
                              int decimals)
Rounds a number according to Math.round(double) with the specified number of decimals and returns a string with the exact number of decimals.

Parameters:
number - number to round
decimals - number of decimals to preserve
Returns:
rounded number

parseDate

public static Date parseDate(String dateString)

parseDate

public static Date parseDate(String dateString,
                             String datePattern)

dateToString

public static String dateToString(Date date)

dateToString

public static String dateToString(Date date,
                                  String datePattern)

friendlyString

public static String friendlyString(Date date1,
                                    Date date2)

strToBool

public static boolean strToBool(String string)
Returns a boolean value from a string. The return value is true if, and only if the value is 1. In all other cases it returns false. It has the same effect as calling strToBool(String, boolean) with the default value set to false.

Parameters:
string - string with the integer to parse
Returns:
true if string == 1, false if string != 1
Throws:
NumberFormatException - if the string is bogus
See Also:
strToBool(String, boolean)

strToBool

public static boolean strToBool(String string,
                                boolean def)
Returns a boolean value from a string. The return value is false if the value is 0, and true if the value is 1. If the string is any other number then the returned value is defined by the def parameter.

Parameters:
string - string with the integer to parse
def - default value if the value is neither 0 nor 1.
Returns:
true if string == 1, false if string != 1
Throws:
NumberFormatException - if the string is bogus
See Also:
strToBool(String, boolean)


Copyright © 2006 Team Trip Tracker. All Rights Reserved.