eu.etaxonomy.cdm.common
Class CdmUtils

java.lang.Object
  extended by eu.etaxonomy.cdm.common.CdmUtils

public class CdmUtils
extends Object

Author:
a.mueller, a.kohlbecker

Field Summary
static File perUserCdmFolder
          The per user cdm folder "~/.cdmLibrary"
 
Constructor Summary
CdmUtils()
           
 
Method Summary
static boolean areBlank(String... strings)
           
static ArrayList<String> buildList(String value)
          Builds a list of strings by splitting an input string with delimiters whitespace, comma, or semicolon
static String concat(CharSequence separator, String[] strings)
          Concatenates an array of strings using the defined seperator.
Null values are interpreted as empty strings.
If all strings are null then null is returned.
static String concat(CharSequence separator, String string1, String string2)
          Concatenates two strings, using the defined seperator.
Null values are interpreted as empty Strings.
If both strings are null then null is returned.
static String findLibrary(Class<?> clazz)
          Returns the file name for the file in which 'clazz' is to be found (helps finding according libraries)
static Map<String,Field> getAllFields(Class clazz, Class highestClass, boolean includeStatic, boolean includeTransient, boolean makeAccessible, boolean includeHighestClass)
          Computes all fields recursively
static File getCdmHomeDir()
           
static String getFolderSeperator()
           
static String getHomeDir()
           
static InputStream getReadableResourceStream(String resourceFileName)
          Returns the an InputStream for a read-only source
static InputStreamReader getUtf8ResourceReader(String resourceFileName)
          Returns the an InputStream for a read-only source
static boolean isBlank(String string)
          Returns true if string is null, "" or string.trim() is ""
static boolean isCapital(String string)
          Returns true if the passed string starts with an upper case letter.
static boolean isEmpty(String string)
          Deprecated. use isBlank(String) instead
static boolean isNotBlank(String string)
          Returns false if string is null, "" or string.trim() is ""
static boolean isNotEmpty(String string)
          Deprecated. use isNotBlank(String) instead
static boolean isNumeric(String string)
           
protected static boolean isTransient(Field field)
          Returns true, if field has an annotation of type javax.persistence.Annotation
static boolean nullSafeEqual(Object obj1, Object obj2)
          Tests if two objects are equal or both null.
static Integer Nz(Integer value)
          Returns value if value is not null.
static Long Nz(Long value)
          Returns value if value is not null.
static String Nz(String value)
          Returns value if value is not null.
static String Nz(String value, String defaultValue)
          Returns value if value is not null.
static String NzTrim(String value)
          Returns the trimmed value string if value is not null.
static String readInputLine(String inputQuestion)
           
static String removeBrackets(String text)
          Returns surrounding brackets "(",")".
static CharSequence removeDuplicateWhitespace(CharSequence inputStr)
          Returns a version of the input where all contiguous whitespace characters are replaced with a single space.
static String removeTrailingDot(String string)
          Trims the string and if the string ends with a dot removes it.
static URI string2Uri(String string)
           
static String testMe()
           
static boolean urlExists(String strUrl, boolean withWarning)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

perUserCdmFolder

public static final File perUserCdmFolder
The per user cdm folder "~/.cdmLibrary"

Constructor Detail

CdmUtils

public CdmUtils()
Method Detail

getHomeDir

public static String getHomeDir()
                         throws IOException
Throws:
IOException

getCdmHomeDir

public static File getCdmHomeDir()

getReadableResourceStream

public static InputStream getReadableResourceStream(String resourceFileName)
                                             throws IOException
Returns the an InputStream for a read-only source

Parameters:
resourceFileName - the resources path within the classpath(!)
Returns:
Throws:
IOException

getUtf8ResourceReader

public static InputStreamReader getUtf8ResourceReader(String resourceFileName)
                                               throws IOException
Returns the an InputStream for a read-only source

Parameters:
resourceFileName - the resources path within the classpath(!)
Returns:
Throws:
IOException

getFolderSeperator

public static String getFolderSeperator()
Returns:

findLibrary

public static String findLibrary(Class<?> clazz)
Returns the file name for the file in which 'clazz' is to be found (helps finding according libraries)

Parameters:
clazz -
Returns:

testMe

public static String testMe()

readInputLine

public static String readInputLine(String inputQuestion)

NzTrim

public static String NzTrim(String value)
Returns the trimmed value string if value is not null. Returns the empty string if value is null.

Parameters:
value -
Returns:

Nz

public static String Nz(String value)
Returns value if value is not null. Returns empty string if value is null.

Parameters:
value -
Returns:

Nz

public static String Nz(String value,
                        String defaultValue)
Returns value if value is not null. Returns defaultValue if value is null.

Parameters:
value -
Returns:

Nz

public static Integer Nz(Integer value)
Returns value if value is not null. Returns 0 if value is null.

Parameters:
value -
Returns:

Nz

public static Long Nz(Long value)
Returns value if value is not null. Returns 0 if value is null.

Parameters:
value -
Returns:

concat

public static String concat(CharSequence separator,
                            String[] strings)
Concatenates an array of strings using the defined seperator.
Null values are interpreted as empty strings.
If all strings are null then null is returned.

Parameters:
strings -
seperator -
Returns:
String

concat

public static String concat(CharSequence separator,
                            String string1,
                            String string2)
Concatenates two strings, using the defined seperator.
Null values are interpreted as empty Strings.
If both strings are null then null is returned.

Parameters:
seperator -
string1 -
string2 -
Returns:
String
See Also:
concat(CharSequence, String[])

removeDuplicateWhitespace

public static CharSequence removeDuplicateWhitespace(CharSequence inputStr)
Returns a version of the input where all contiguous whitespace characters are replaced with a single space. Line terminators are treated like whitespace.

Parameters:
inputStr -
Returns:

buildList

public static ArrayList<String> buildList(String value)
Builds a list of strings by splitting an input string with delimiters whitespace, comma, or semicolon

Parameters:
value -
Returns:

urlExists

public static boolean urlExists(String strUrl,
                                boolean withWarning)

string2Uri

public static URI string2Uri(String string)

isNumeric

public static boolean isNumeric(String string)

isCapital

public static boolean isCapital(String string)
Returns true if the passed string starts with an upper case letter.

Parameters:
string -
Returns:

isBlank

public static boolean isBlank(String string)
Returns true if string is null, "" or string.trim() is ""

Parameters:
string -
Returns:
See Also:
isNotEmpty(String string)

isNotBlank

public static boolean isNotBlank(String string)
Returns false if string is null, "" or string.trim() is ""

Parameters:
string -
Returns:
See Also:
isNotEmpty(String string)

isEmpty

@Deprecated
public static boolean isEmpty(String string)
Deprecated. use isBlank(String) instead

Parameters:
string -
Returns:
See Also:
isBlank(String)

areBlank

public static boolean areBlank(String... strings)

nullSafeEqual

public static boolean nullSafeEqual(Object obj1,
                                    Object obj2)
Tests if two objects are equal or both null. Otherwise returns false

Parameters:
obj1 -
obj2 -
Returns:

isNotEmpty

@Deprecated
public static boolean isNotEmpty(String string)
Deprecated. use isNotBlank(String) instead

Returns false if string is null, "" or string.trim() is "" Else true.

Parameters:
string -
Returns:
See Also:
isBlank(String string), isNotBlank(String)

getAllFields

public static Map<String,Field> getAllFields(Class clazz,
                                             Class highestClass,
                                             boolean includeStatic,
                                             boolean includeTransient,
                                             boolean makeAccessible,
                                             boolean includeHighestClass)
Computes all fields recursively

Parameters:
clazz -
Returns:

isTransient

protected static boolean isTransient(Field field)
Returns true, if field has an annotation of type javax.persistence.Annotation

Parameters:
field -
Returns:

removeTrailingDot

public static String removeTrailingDot(String string)
Trims the string and if the string ends with a dot removes it.

Parameters:
string -
Returns:

removeBrackets

public static String removeBrackets(String text)
Returns surrounding brackets "(",")". Trim the string if necessary.

Parameters:
text -
Returns:


Copyright © 2007-2013 EDIT. All Rights Reserved.