com.acsinet_solutions.util
Class Utils

java.lang.Object
  extended by com.acsinet_solutions.util.Utils

public final class Utils
extends java.lang.Object

Useful utility methods that are so generic to put in more specialized classes.

Author:
Santiago Arriaga

Method Summary
static int compare(java.lang.Comparable obj1, java.lang.Comparable obj2)
          Compare two objects.
static java.util.Map<java.lang.Integer,java.lang.String> createIntMap(int from, int to)
          Create an ordered map with Integer keys and String values whose values go between the given limits ( both inclusive )
static boolean equal(java.lang.Object obj1, java.lang.Object obj2)
          Test equality between the given objects.
static java.util.Set getDifference(java.util.Set set1, java.util.Set set2)
          Get a Set that results from the difference between set1 and set2
static java.lang.String getFileName(java.lang.String path)
          Get the file name for the given path.
static int getFirstInt(java.util.List list)
          Get the first element of the list as an int value.
static java.util.Locale getLocale(java.lang.String language, java.lang.String country, java.lang.String variant)
          Obtain a locale for the given language, country and variant values.
static java.lang.String getString(java.util.Map map, java.lang.String key, java.lang.Object[] params)
          Get the possible formatted text.
static java.lang.String getString(java.util.ResourceBundle bundle, java.lang.String key, java.lang.Object[] params)
          Get the possible formatted text.
static int hashCode(java.lang.Object obj)
          Return the hashCode for the given object.
static void homologate(java.util.Set source, java.util.Set target)
          Homologate the contents of source set into target set
static boolean isAbsoluteURLPath(java.lang.String path)
          Check if the provided path represents an absolute URL path ( starts with '/' or with 'http:' or with 'https:' ).
static boolean isWellFormedEMail(java.lang.String str)
          Check whether the given input string is a well-formed email or not.
static boolean isWellFormedHost(java.lang.String str)
          Check whether the given input string is a well-formed hostname or IP Address or not.
static java.lang.String limit(java.lang.String str, int limit, int threshold, java.lang.String append)
          Limit a string to a given size
static java.lang.String readerToString(java.io.Reader reader)
          Get the given reader into a String instance
static
<T extends java.io.Serializable>
T
serializedCopy(T source)
          Copy a bean class using serialization mechanisms
static void write(java.io.InputStream istream, java.io.OutputStream ostream)
          Write the contents of the given input stream into the output stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

equal

public static boolean equal(java.lang.Object obj1,
                            java.lang.Object obj2)
Test equality between the given objects. both obj1 and obj2 may be null

Parameters:
obj1 - A maybe-null Object instance
obj2 - A maybe-null Object instance
Returns:
true if both objects are equal ( if both are null, they are equal ); false otherwise

hashCode

public static int hashCode(java.lang.Object obj)
Return the hashCode for the given object. The object may be null.

Parameters:
obj - A maybe-null Object reference
Returns:
An int value

compare

public static int compare(java.lang.Comparable obj1,
                          java.lang.Comparable obj2)
Compare two objects. both obj1 and obj2 may be null

Parameters:
obj1 - A maybe-null Object instance
obj2 - A maybe-null Object instance
Returns:
true if both objects are equal ( if both are null, they are equal ); false otherwise

limit

public static final java.lang.String limit(java.lang.String str,
                                           int limit,
                                           int threshold,
                                           java.lang.String append)
Limit a string to a given size

Parameters:
str - A not-null not-empty String instance
limit - A nonnegative int value

isWellFormedHost

public static boolean isWellFormedHost(java.lang.String str)
Check whether the given input string is a well-formed hostname or IP Address or not. This class does not recognize ( yet ) IPv6 addresses.

Parameters:
str - A not-null String that may contain a hostname of IP Address
Returns:
true if the input string is a well-formed host or IP Address; false otherwise

isWellFormedEMail

public static boolean isWellFormedEMail(java.lang.String str)
Check whether the given input string is a well-formed email or not.

Parameters:
str - A not-null String that may contain an email
Returns:
true if the input string is a well-formed email; false otherwise

isAbsoluteURLPath

public static boolean isAbsoluteURLPath(java.lang.String path)
Check if the provided path represents an absolute URL path ( starts with '/' or with 'http:' or with 'https:' ). The provided path string must be not null.


getDifference

public static java.util.Set getDifference(java.util.Set set1,
                                          java.util.Set set2)
Get a Set that results from the difference between set1 and set2

Parameters:
set1 - A not-null Set instance
set2 - A not-null Set instance

homologate

public static void homologate(java.util.Set source,
                              java.util.Set target)
Homologate the contents of source set into target set


createIntMap

public static java.util.Map<java.lang.Integer,java.lang.String> createIntMap(int from,
                                                                             int to)
Create an ordered map with Integer keys and String values whose values go between the given limits ( both inclusive )

Parameters:
from - the initial value; must be lower than to
to - the final value

getFirstInt

public static int getFirstInt(java.util.List list)
Get the first element of the list as an int value. Convenience methods


readerToString

public static java.lang.String readerToString(java.io.Reader reader)
                                       throws java.io.IOException
Get the given reader into a String instance

Parameters:
reader - A not-null reader instnace
Returns:
A not-null String value
Throws:
java.io.IOException

write

public static void write(java.io.InputStream istream,
                         java.io.OutputStream ostream)
                  throws java.io.IOException
Write the contents of the given input stream into the output stream

Throws:
java.io.IOException

serializedCopy

public static <T extends java.io.Serializable> T serializedCopy(T source)
Copy a bean class using serialization mechanisms


getFileName

public static final java.lang.String getFileName(java.lang.String path)
Get the file name for the given path. java.io.File is not used because we have to deal equally with paths of Win and Unix platforms.


getLocale

public static java.util.Locale getLocale(java.lang.String language,
                                         java.lang.String country,
                                         java.lang.String variant)
Obtain a locale for the given language, country and variant values. Variant may be null, and country may be null ( variant ignored ). This method is handy for configuration classes because regular Locale classes accept no nulls as parameters.


getString

public static java.lang.String getString(java.util.ResourceBundle bundle,
                                         java.lang.String key,
                                         java.lang.Object[] params)
Get the possible formatted text. Convenience method that combines resource bundles and text formatters.


getString

public static java.lang.String getString(java.util.Map map,
                                         java.lang.String key,
                                         java.lang.Object[] params)
Get the possible formatted text. Convenience method that combines Maps acting as resource bundles and text formatters.