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) Deprecated, for removal: This API element is subject to removal in a future version.unusedstatic <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.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) Deprecated.since 5.0 in favor of the JDK'sComparator.nullsFirst(java.util.Comparator)/Comparator.nullsLast(java.util.Comparator)combined withComparator.naturalOrder().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) Deprecated, for removal: This API element is subject to removal in a future version.unusedstatic DocumentreadDocument(URL url) Deprecated, for removal: This API element is subject to removal in a future version.unusedstatic <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) Deprecated, for removal: This API element is subject to removal in a future version.unusedstatic StringstringFromFile(File file) Deprecated, for removal: This API element is subject to removal in a future version.unusedstatic StringstringFromFile(File file, String joinWith) Deprecated, for removal: This API element is subject to removal in a future version.unusedstatic 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) Deprecated, for removal: This API element is subject to removal in a future version.unusedstatic 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.static ThrowableunwindException(Throwable th, Class<? extends Throwable> upTo) Unwinds an exception chain likeunwindException(Throwable), but never unwinds past the innermost exception that is an instance ofupTo.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
toFile
Converts URL to file. ThrowsIllegalArgumentExceptionif the URL is not a "file://" URL.- Throws:
IllegalArgumentException
-
stringFromFile
@Deprecated(since="5.0", forRemoval=true) public static String stringFromFile(File file) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.unusedReads file contents, returning it as a String, using System default line separator.- Throws:
IOException
-
stringFromFile
@Deprecated(since="5.0", forRemoval=true) public static String stringFromFile(File file, String joinWith) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.unusedReads 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
-
unwindException
Unwinds an exception chain likeunwindException(Throwable), but never unwinds past the innermost exception that is an instance ofupTo. If the chain contains such an exception, the innermost matching one is returned; otherwise the fully unwound root cause is returned. This lets callers strip generic wrappers while preserving a meaningful exception type that itself wraps a lower-level cause.- Since:
- 5.0
-
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
@Deprecated(since="5.0") public static <T> int nullSafeCompare(boolean nullsFirst, Comparable<T> o1, T o2) Deprecated.since 5.0 in favor of the JDK'sComparator.nullsFirst(java.util.Comparator)/Comparator.nullsLast(java.util.Comparator)combined withComparator.naturalOrder().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
Deprecated, for removal: This API element is subject to removal in a future version.unusedCapitalizes the first letter of the property name.- Since:
- 4.1
-
uncapitalized
Deprecated, for removal: This API element is subject to removal in a future version.unusedReturns string with lowercased first letter- Since:
- 4.2
-
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
Deprecated, for removal: This API element is subject to removal in a future version.unused- Since:
- 4.1
-
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
@Deprecated(since="5.0", forRemoval=true) public static String prettyTrim(String str, int maxLength) Deprecated, for removal: This API element is subject to removal in a future version.unusedTrims long strings substituting middle part with "...". -
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
@Deprecated(since="5.0", forRemoval=true) public static Pattern sqlPatternToPattern(String pattern, boolean ignoreCase) Deprecated, for removal: This API element is subject to removal in a future version.unused- Since:
- 1.2
-
isAccessible
Returns true if a Member is accessible via reflection under normal Java access controls.- Since:
- 1.2
-
getJavaClass
Deprecated.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
-