Class Util
java.lang.Object
org.apache.cayenne.util.Util
Contains various unorganized static utility methods used across Cayenne.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringcapitalized(String name) Capitalizes the first letter of the property name.static <T extends Serializable>
TcloneViaSerialization(T object) Creates Serializable object copy using serialization/deserialization.static intcountMatches(String str, String sub) Returns how many times the sub appears in the str.static XMLReaderCreates an XMLReader with default feature set.static StringencodeXmlAttribute(String string) Encodes a string so that it can be used as an attribute value in an XML document.static StringextractFileExtension(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.static StringgetPackagePath(String className) Returns package name for the Java class as a path separated with forward slash ("/").static inthashCode(Collection<?> c) Deprecated, for removal: This API element is subject to removal in a future version.unusedstatic booleanisAccessible(Member member) Returns true if a Member is accessible via reflection under normal Java access controls.static booleanisBlank(CharSequence cs) Returns true, if string not empty and contains non-whitespace characters.static booleanisEmptyString(CharSequence string) Returns true, if the String is null or an empty string.static booleanDeprecated, for removal: This API element is subject to removal in a future version.usecs.chars().allMatch(Character::isDigit)or equivalentstatic StringDeprecated, for removal: This API element is subject to removal in a future version.static <T> intnullSafeCompare(boolean nullsFirst, Comparable<T> o1, T o2) Compares two objects similar to "Comparable.compareTo(Object)".static booleannullSafeEquals(Object o1, Object o2) Deprecated, for removal: This API element is subject to removal in a future version.UseObjects.equals(Object, Object)for non-array types, orObjects.deepEquals(Object, Object)when the values may be arrays.static StringprettyTrim(String str, int maxLength) Trims long strings substituting middle part with "...".static DocumentreadDocument(URL url) static <T> Iterator<T> sortedIterator(Iterator<T> it, Comparator<T> comparator) Deprecated, for removal: This API element is subject to removal in a future version.unusedstatic StringspecialCharsToJava(String string) Replaces special chars with human-readable and Java-id-compatible symbols.static PatternsqlPatternToPattern(String pattern, boolean ignoreCase) static StringstringFromFile(File file) Reads file contents, returning it as a String, using System default line separator.static StringstringFromFile(File file, String joinWith) Reads file contents, returning it as a String, joining lines with provided separator.static StringstripFileExtension(String fileName) Strips extension from the file name.static StringstripLineBreaks(String string, char replaceWith) Strips "\n", "\r\n", "\r" from the argument string, replacing them with a provided character.static StringstripPackageName(String className) Returns an unqualified class name for the fully qualified name.static StringsubstBackslashes(String string) Replaces all backslashes "\" with forward slashes "/".static FileConverts URL to file.static <K,V> Map <K, V> toMap(K[] keys, V[] values) Deprecated, for removal: This API element is subject to removal in a future version.useIntStream.range(int, int)withCollectors.toMap(Function, Function)to build a map from parallel arraysstatic Stringuncapitalized(String aString) Returns string with lowercased first letterstatic StringunderscoredToJava(String name, boolean capitalize) Converts names like "ABCD_EFG_123" to Java-style names like "abcdEfg123".static ThrowableLooks up and returns the root cause of an exception.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
toFile
Converts URL to file. ThrowsIllegalArgumentExceptionif the URL is not a "file://" URL.- Throws:
IllegalArgumentException
-
stringFromFile
Reads file contents, returning it as a String, using System default line separator.- Throws:
IOException
-
stringFromFile
Reads file contents, returning it as a String, joining lines with provided separator.- Throws:
IOException
-
join
@Deprecated(since="5.0", forRemoval=true) public static String join(Iterable<?> objects, String separator) Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
objects- An Iterable of objects that will be converted to Strings and joined together.separator- The separator between the strings.- Returns:
- A single string of all the input strings separated by the separator.
-
substBackslashes
-
unwindException
-
nullSafeEquals
@Deprecated(since="5.0", forRemoval=true) public static boolean nullSafeEquals(Object o1, Object o2) Deprecated, for removal: This API element is subject to removal in a future version.UseObjects.equals(Object, Object)for non-array types, orObjects.deepEquals(Object, Object)when the values may be arrays.Compares two objects similar to "Object.equals(Object)". Unlike Object.equals(..), this method doesn't throw an exception if any of the two objects is null. -
nullSafeCompare
Compares two objects similar to "Comparable.compareTo(Object)". Unlike Comparable.compareTo(..), this method doesn't throw an exception if any of the two objects is null.- Since:
- 1.1
-
isEmptyString
Returns true, if the String is null or an empty string. -
isBlank
Returns true, if string not empty and contains non-whitespace characters.- Since:
- 4.1
-
isNumeric
Deprecated, for removal: This API element is subject to removal in a future version.usecs.chars().allMatch(Character::isDigit)or equivalent- Since:
- 4.1
-
countMatches
-
capitalized
-
uncapitalized
-
cloneViaSerialization
Creates Serializable object copy using serialization/deserialization.- Throws:
Exception
-
createXmlReader
Creates an XMLReader with default feature set. Note that all Cayenne internal XML parsers should probably use XMLReader obtained via this method for consistency sake, and can customize feature sets as needed. -
readDocument
-
getPackagePath
-
stripPackageName
-
toMap
Deprecated, for removal: This API element is subject to removal in a future version.useIntStream.range(int, int)withCollectors.toMap(Function, Function)to build a map from parallel arraysCreates a mutable map out of two arrays with keys and values.- Since:
- 1.2
-
extractFileExtension
-
stripFileExtension
-
stripLineBreaks
-
encodeXmlAttribute
-
prettyTrim
-
sortedIterator
@Deprecated(since="5.0", forRemoval=true) public static <T> Iterator<T> sortedIterator(Iterator<T> it, Comparator<T> comparator) Deprecated, for removal: This API element is subject to removal in a future version.unusedReturns a sorted iterator from an unsorted one. Use this method as a last resort, since it is much less efficient then just sorting a collection that backs the original iterator. -
hashCode
Deprecated, for removal: This API element is subject to removal in a future version.unusedBuilds a hashCode of Collection. -
sqlPatternToPattern
-
isAccessible
Returns true if a Member is accessible via reflection under normal Java access controls.- Since:
- 1.2
-
getJavaClass
Deprecated.since 4.0 this method based on statically defined class loading algorithm is not going to work in environments like OSGi.AdhocObjectFactoryshould be used as it can provide the environment-specific class loading policy.Creates a Java class, handling regular class names as well as single-dimensional arrays and primitive types.- Throws:
ClassNotFoundException- Since:
- 1.2
-
underscoredToJava
-
specialCharsToJava
-