net.sf.xenqtt
Class XenqttUtil

java.lang.Object
  extended by net.sf.xenqtt.XenqttUtil

public final class XenqttUtil
extends Object

Provides disparate utility methods useful across the Xenqtt application ecosystem.


Method Summary
static String getDirectoryHostingRunningXenqttJar()
           
static boolean isBlank(String str)
          Determine if a particular string is blank.
static boolean isNull(String str)
          Determine if a particular string is null.
static String loadResourceFile(String resourceName)
           
static void prettyPrint(String text, boolean wrap)
          Converts tabs to 4 spaces and optionally word wraps text at about 100 characters then prints to system.out.
static void prettyPrintln(String text, boolean wrap)
          Converts tabs to 4 spaces and optionally word wraps text at about 100 characters then prints to system.out and appends a newline character.
static String[] quickSplit(String value, char delimiter)
           Split a string using a single delimiter.
static
<T extends Number>
T
validateGreaterThan(String name, T value, T max)
          Validate that a number is greater than a defined maximum.
static
<T extends Number>
T
validateGreaterThanOrEqualTo(String name, T value, T max)
          Validate that a number is greater than or equal to a defined maximum.
static
<T extends Number>
T
validateInRange(String name, T value, T start, T end)
          Validate that a number falls within a specific range.
static
<T extends Number>
T
validateLessThan(String name, T value, T max)
          Validate that a number is less than a defined maximum.
static
<T extends Number>
T
validateLessThanOrEqualTo(String name, T value, T max)
          Validate that a number is less than or equal to a defined maximum.
static
<T> Collection<T>
validateNotEmpty(String name, Collection<T> value)
          Validate that an arbitrary collection of objects of type T is not empty.
static String validateNotEmpty(String name, String value)
          Validate that a string is not empty.
static
<T> T[]
validateNotEmpty(String name, T[] value)
          Validate that an arbitrary array of objects of type T is not empty.
static
<T> T
validateNotNull(String name, T value)
          Validates that an object is not null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

quickSplit

public static String[] quickSplit(String value,
                                  char delimiter)

Split a string using a single delimiter. This method is useful in cases where one needs to split a string on a single character and desires optimal performance. The String.split(String) method builds a regular expression under the covers and, as a result, performs worse than this method does for the single character use case.

With respect to this method and the given input parameters, the following holds:

Parameters:
value - The string value that should be split
delimiter - The delimiter to split the specified value on
Returns:
An array of strings derived by splitting the value on the specified delimiter

validateNotNull

public static <T> T validateNotNull(String name,
                                    T value)
Validates that an object is not null.

Parameters:
name - The name of the object being validated. Included in the exception message if one is thrown
value - The object to validate
Returns:
The specified value
Throws:
IllegalArgumentException - If value is null

validateNotEmpty

public static String validateNotEmpty(String name,
                                      String value)
Validate that a string is not empty. An empty string is either null or the empty string. Having only whitespace in the string ( \r \n \t ' ') constitutes an empty string as well.

Parameters:
name - The name of the object being validated. Included in the exception message if one is thrown
value - The string to validate
Returns:
The specified value
Throws:
IllegalArgumentException - If value is an empty string

validateNotEmpty

public static <T> T[] validateNotEmpty(String name,
                                       T[] value)
Validate that an arbitrary array of objects of type T is not empty. The array is considered empty if it is null or contains zero elements.

Parameters:
name - The name of the object being validated. Included in the exception message if one is thrown
value - The array to validate
Returns:
The specified value
Throws:
IllegalArgumentException - If value is null or contains no elements

validateNotEmpty

public static <T> Collection<T> validateNotEmpty(String name,
                                                 Collection<T> value)
Validate that an arbitrary collection of objects of type T is not empty. The collection is considered empty if it is null or contains zero elements.

Parameters:
name - The name of the object being validated. Included in the exception message if one is thrown
value - The collection to validate
Returns:
The specified value
Throws:
IllegalArgumentException - If value is null or contains no elements

validateLessThan

public static <T extends Number> T validateLessThan(String name,
                                                    T value,
                                                    T max)
Validate that a number is less than a defined maximum.

Parameters:
name - The name of the object being validated. Included in the exception message if one is thrown
value - The value of the number
max - The maximum that the specified value must be under
Returns:
The specified value
Throws:
IllegalArgumentException - If value is null or is greater than or equal to max

validateLessThanOrEqualTo

public static <T extends Number> T validateLessThanOrEqualTo(String name,
                                                             T value,
                                                             T max)
Validate that a number is less than or equal to a defined maximum.

Parameters:
name - The name of the object being validated. Included in the exception message if one is thrown
value - The value of the number
max - The maximum that the specified value must be under
Returns:
The specified value
Throws:
IllegalArgumentException - If value is null or is greater than max

validateGreaterThan

public static <T extends Number> T validateGreaterThan(String name,
                                                       T value,
                                                       T max)
Validate that a number is greater than a defined maximum.

Parameters:
name - The name of the object being validated. Included in the exception message if one is thrown
value - The value of the number
max - The maximum that the specified value must be over
Returns:
The specified value
Throws:
IllegalArgumentException - If value is null or is less than or equal to max

validateGreaterThanOrEqualTo

public static <T extends Number> T validateGreaterThanOrEqualTo(String name,
                                                                T value,
                                                                T max)
Validate that a number is greater than or equal to a defined maximum.

Parameters:
name - The name of the object being validated. Included in the exception message if one is thrown
value - The value of the number
max - The maximum that the specified value must be over
Returns:
The specified value
Throws:
IllegalArgumentException - If value is null or is less than or equal to max

validateInRange

public static <T extends Number> T validateInRange(String name,
                                                   T value,
                                                   T start,
                                                   T end)
Validate that a number falls within a specific range. The start and end of the range are inclusive.

Parameters:
name - The name of the object being validated. Included in the exception message if one is thrown
value - The value of the number
start - The start of the range
end - The end of the range
Returns:
The specified value
Throws:
IllegalArgumentException - If value is null or falls outside of the range specified by start and end

isBlank

public static boolean isBlank(String str)
Determine if a particular string is blank. A blank string is one that is either null, the empty string, or contains only whitespace characters.

Parameters:
str - The string to check
Returns:
true if str is blank, false if it is not

isNull

public static boolean isNull(String str)
Determine if a particular string is null.

Parameters:
str - The string to check
Returns:
true if str is null, false if it is not

getDirectoryHostingRunningXenqttJar

public static String getDirectoryHostingRunningXenqttJar()
Returns:
The path to the directory currently running the xenqtt JAR file.

loadResourceFile

public static String loadResourceFile(String resourceName)
Returns:
The specified classpath resource file contents as a string

prettyPrintln

public static void prettyPrintln(String text,
                                 boolean wrap)
Converts tabs to 4 spaces and optionally word wraps text at about 100 characters then prints to system.out and appends a newline character. Lines will be continued past the specified length to avoid breaking in the middle of a word.


prettyPrint

public static void prettyPrint(String text,
                               boolean wrap)
Converts tabs to 4 spaces and optionally word wraps text at about 100 characters then prints to system.out. Lines will be continued past the specified length to avoid breaking in the middle of a word.



Copyright © 2013. All Rights Reserved.