public class Util extends Object
Constructor and Description |
---|
Util() |
Modifier and Type | Method and Description |
---|---|
static <T extends Serializable> |
cloneViaSerialization(T object)
Creates Serializable object copy using serialization/deserialization.
|
static XMLReader |
createXmlReader()
Creates an XMLReader with default feature set.
|
static String |
encodeXmlAttribute(String string)
Encodes a string so that it can be used as an attribute value in an XML
document.
|
static String |
extractFileExtension(String fileName)
Extracts extension from the file name.
|
static Class<?> |
getJavaClass(String className)
Deprecated.
since 4.0 this method based on statically defined class
loading algorithm is not going to work in environments like
OSGi.
AdhocObjectFactory should be used as it can
provide the environment-specific class loading policy. |
static String |
getPackagePath(String className)
Returns package name for the Java class as a path separated with forward
slash ("/").
|
static int |
hashCode(Collection<?> c)
Builds a hashCode of Collection.
|
static boolean |
isAccessible(Member member)
Returns true if a Member is accessible via reflection under normal Java
access controls.
|
static boolean |
isEmptyString(String string)
Returns true, if the String is null or an empty string.
|
static String |
join(Iterable<?> objects,
String separator) |
static <T> int |
nullSafeCompare(boolean nullsFirst,
Comparable<T> o1,
T o2)
Compares two objects similar to "Comparable.compareTo(Object)".
|
static boolean |
nullSafeEquals(Object o1,
Object o2)
Compares two objects similar to "Object.equals(Object)".
|
static String |
prettyTrim(String str,
int maxLength)
Trims long strings substituting middle part with "...".
|
static <T> Iterator<T> |
sortedIterator(Iterator<T> it,
Comparator<T> comparator)
Returns a sorted iterator from an unsorted one.
|
static String |
specialCharsToJava(String string)
Replaces special chars with human-readable and Java-id-compatible symbols.
|
static Pattern |
sqlPatternToPattern(String pattern,
boolean ignoreCase) |
static String |
stringFromFile(File file)
Reads file contents, returning it as a String, using System default line
separator.
|
static String |
stringFromFile(File file,
String joinWith)
Reads file contents, returning it as a String, joining lines with
provided separator.
|
static String |
stripFileExtension(String fileName)
Strips extension from the file name.
|
static String |
stripLineBreaks(String string,
char replaceWith)
Strips "\n", "\r\n", "\r" from the argument string, replacing them with a
provided character.
|
static String |
stripPackageName(String className)
Returns an unqualified class name for the fully qualified name.
|
static String |
substBackslashes(String string)
Replaces all backslashes "\" with forward slashes "/".
|
static File |
toFile(URL url)
Converts URL to file.
|
static <K,V> Map<K,V> |
toMap(K[] keys,
V[] values)
Creates a mutable map out of two arrays with keys and values.
|
static String |
underscoredToJava(String name,
boolean capitalize)
Converts names like "ABCD_EFG_123" to Java-style names like "abcdEfg123".
|
static Throwable |
unwindException(Throwable th)
Looks up and returns the root cause of an exception.
|
public static File toFile(URL url) throws IllegalArgumentException
IllegalArgumentException
if the URL
is not a "file://" URL.IllegalArgumentException
public static String stringFromFile(File file) throws IOException
IOException
public static String stringFromFile(File file, String joinWith) throws IOException
IOException
public static String join(Iterable<?> objects, String separator)
objects
- An Iterable of objects that will be converted to Strings and joined together.separator
- The separator between the strings.public static String substBackslashes(String string)
public static Throwable unwindException(Throwable th)
public static boolean nullSafeEquals(Object o1, Object o2)
public static <T> int nullSafeCompare(boolean nullsFirst, Comparable<T> o1, T o2)
public static boolean isEmptyString(String string)
public static <T extends Serializable> T cloneViaSerialization(T object) throws Exception
Exception
public static XMLReader createXmlReader() throws SAXException, ParserConfigurationException
public static String getPackagePath(String className)
public static String stripPackageName(String className)
public static <K,V> Map<K,V> toMap(K[] keys, V[] values)
public static String extractFileExtension(String fileName)
public static String stripFileExtension(String fileName)
public static String stripLineBreaks(String string, char replaceWith)
public static String encodeXmlAttribute(String string)
public static String prettyTrim(String str, int maxLength)
str
- String to trim.maxLength
- maximum allowable length. Must be at least 5, or an
IllegalArgumentException is thrown.public static <T> Iterator<T> sortedIterator(Iterator<T> it, Comparator<T> comparator)
public static int hashCode(Collection<?> c)
public static Pattern sqlPatternToPattern(String pattern, boolean ignoreCase)
public static boolean isAccessible(Member member)
@Deprecated public static Class<?> getJavaClass(String className) throws ClassNotFoundException
AdhocObjectFactory
should be used as it can
provide the environment-specific class loading policy.ClassNotFoundException
public static String underscoredToJava(String name, boolean capitalize)
capitalize
is true, returned name is capitalized (for instance if
this is a class name).Copyright © 2001–2018 Apache Cayenne. All rights reserved.