com.niggle.util
Class Util

java.lang.Object
  |
  +--com.niggle.util.Util

public class Util
extends java.lang.Object

Dumping ground for utility functions that are more or less general-purpose.


Field Summary
static java.util.Enumeration EMPTY_ENUM
          An empty java.util.Enumeration, comes in handy for API's that require an Enumeration to be passed in or out.
static java.util.Iterator EMPTY_ITERATOR
          An empty java.util.Iterator, comes in handy for API's that require an Iterator to be passed in or out.
static java.lang.Integer ZERO
          A zero integer wrapper, defined statically here to avoid replications
 
Constructor Summary
Util()
           
 
Method Summary
static java.util.Enumeration arrayAsEnumeration(java.lang.Object[] arr)
          wraps an array of objects as an instance of java.util.Enumeration useful for API's that require an Enumeration to be passed in or out.
static java.lang.String convertHTMLEntities(java.lang.String s)
          Converts the literal characters in a string to HTML entities as need be.
static java.lang.Class findClass(java.lang.String className, java.lang.ClassLoader loader)
           
static java.io.InputStream getInputStream(java.lang.String location)
          Gets the specified input stream, assuming that it may be a fully specified filename, OR relative to the classpath.
static java.io.InputStream getInputStream(java.lang.String location, java.lang.ClassLoader cl)
           
static boolean hasContent(java.lang.String s)
           
static java.lang.String noNull(java.lang.String s)
           
static java.util.Iterator objectAsIterator(java.lang.Object o)
          take a single object and wrap it up as an instance of java.util.Iterator useful for API's that require an Iterator to be passed in or out.
static void printFullStackTrace(java.lang.Throwable t, java.io.PrintStream stream)
           
static boolean s2b(java.lang.String s)
          Convert a String to a boolean.
static int s2i(java.lang.String s)
          Convert a String to an int.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ENUM

public static final java.util.Enumeration EMPTY_ENUM
An empty java.util.Enumeration, comes in handy for API's that require an Enumeration to be passed in or out.

EMPTY_ITERATOR

public static final java.util.Iterator EMPTY_ITERATOR
An empty java.util.Iterator, comes in handy for API's that require an Iterator to be passed in or out.

ZERO

public static final java.lang.Integer ZERO
A zero integer wrapper, defined statically here to avoid replications
Constructor Detail

Util

public Util()
Method Detail

s2i

public static int s2i(java.lang.String s)
Convert a String to an int.

If an NumberFormatException is raised, or s is null, write an error to the error log and return Integer.MIN_VALUE.

Parameters:
s - the String to be converted.
Returns:
the integer or Integer.MIN_VALUE in case of error (null or unparsable String).

s2b

public static boolean s2b(java.lang.String s)
Convert a String to a boolean.
Parameters:
s - the string to be converted.
Returns:
the string's boolean value. false if conversion is not understood. true can be represented by:
  • t
  • true
  • y
  • yes
Acceptable values of false are easily deduced.

noNull

public static java.lang.String noNull(java.lang.String s)
Returns:
the zero-length string if s is null, otherwise just echoes

hasContent

public static boolean hasContent(java.lang.String s)
Returns:
true if the string is null or zero-length

getInputStream

public static java.io.InputStream getInputStream(java.lang.String location)
Gets the specified input stream, assuming that it may be a fully specified filename, OR relative to the classpath.

getInputStream

public static java.io.InputStream getInputStream(java.lang.String location,
                                                 java.lang.ClassLoader cl)

findClass

public static java.lang.Class findClass(java.lang.String className,
                                        java.lang.ClassLoader loader)
                                 throws java.lang.ClassNotFoundException

arrayAsEnumeration

public static java.util.Enumeration arrayAsEnumeration(java.lang.Object[] arr)
wraps an array of objects as an instance of java.util.Enumeration useful for API's that require an Enumeration to be passed in or out.

objectAsIterator

public static java.util.Iterator objectAsIterator(java.lang.Object o)
take a single object and wrap it up as an instance of java.util.Iterator useful for API's that require an Iterator to be passed in or out.

printFullStackTrace

public static void printFullStackTrace(java.lang.Throwable t,
                                       java.io.PrintStream stream)

convertHTMLEntities

public static java.lang.String convertHTMLEntities(java.lang.String s)
Converts the literal characters in a string to HTML entities as need be.
Returns:
converted string or simply echoes if no conversion was necessary.