Class ExtensionsKt
-
- All Implemented Interfaces:
public final class ExtensionsKt
-
-
Field Summary
Fields Modifier and Type Field Description private final static StringformatSizeInMibprivate final static Longkibibytesprivate final static Longmebibytesprivate final static Longgibibytesprivate final static RegexNON_LINUX_LINE_BREAKS
-
Method Summary
Modifier and Type Method Description final StringgetFormatSizeInMib()final LonggetKibibytes()final LonggetMebibytes()final LonggetGibibytes()final RegexgetNON_LINUX_LINE_BREAKS()A regular expression matching the non-linux line breaks "\r\n" and "\r". final static <T extends Any> TalsoIfNull(T $self, Function1<T, Unit> block)Call also only if the receiver is null, e.g. final static <T extends Any, K extends Any> Map<K, List<T>>getDuplicates(Collection<T> $self, Function1<T, K> keySelector)Return a map that associates duplicates as identified by keySelector with belonging lists of collection entries. final static <T extends Any> Set<T>getDuplicates(Collection<T> $self)Return a set of duplicate entries of a collection. final static List<Pair<Integer, Integer>>collapseToRanges(Collection<Integer> $self)Collapse consecutive values to a list of pairs that each denote a range. final static StringprettyPrintRanges(Collection<Pair<Integer, Integer>> $self)Return a string of common-separated ranges as denoted by the list of pairs. final static <Error class: unknown class>format(Double $self, Integer decimalPlaces)Format this Double as a string with the provided number of decimalPlaces. final static <E extends Enum<E>> EnumSet<E>plus(EnumSet<E> $self, EnumSet<E> other)Return an EnumSet that contains the elements of this and other. final static FileexpandTilde(File $self)If the SHELL environment variable is set, return the absolute file with a leading "~" expanded to the current user's home directory, otherwise return just the absolute file. final static StringexpandTilde(String $self)If the SHELL environment variable is set, return the string with a leading "~" expanded to the current user's home directory, otherwise return the string unchanged. final static BooleanisSymbolicLink(File $self)Return true if and only if this file is a symbolic link. final static FilerealFile(File $self)Resolve the file to the real underlying file. final static UnitsafeDeleteRecursively(File $self, File baseDirectory)Delete a directory recursively without following symbolic links (Unix) or junctions (Windows). final static FilesafeMkdirs(File $self)Create all missing intermediate directories without failing if any already exists. final static FilesearchUpwardsForSubdirectory(File $self, String searchDirName)Search this directory upwards towards the root until a contained subdirectory called searchDirName is found and return the parent of searchDirName, or return null if no such directory is found. final static URItoSafeUri(File $self)Construct a "file:" URI in a safe way by never using a null authority for wider compatibility. final static <T extends Any> TnextOrNull(Iterator<T> $self)Return the next value in the iteration, or null if there is no next value. final static Iterator<String>fieldNamesOrEmpty(JsonNode $self)final static Iterator<Entry.Map<String, JsonNode>>fieldsOrEmpty(JsonNode $self)final static BooleanisNotEmpty(JsonNode $self)Return true if and only if this JsonNode final static StringtextValueOrEmpty(JsonNode $self)Convenience function for JsonNode that returns an empty string if JsonNode.textValue is called on a null object, or the text value is null. final static <K extends Any, V extends Any> Map<K, V>zip(Map<K, V> $self, Map<K, V> other, Function2<V, V, V> operation)Merge two maps by iterating over the combined key set of both maps and calling operation with any conflicting values for the same key. final static <K extends Any, V extends Set<T>, T extends Any> Map<K, V>zipWithSets(Map<K, V> $self, Map<K, V> other)Merge two maps which have sets as values by creating the combined key set of both maps and merging the sets. final static DoublebytesToMib(Number $self)Converts this Number from bytes to mebibytes (MiB). final static <Error class: unknown class>collapseWhitespace(String $self)Trim leading and trailing whitespace, and collapse consecutive inner whitespace to a single space. final static StringencodeOr(String $self, String emptyValue)Return the string encoded for safe use as a file name or emptyValue encoded for safe use as a file name, if this string is empty. final static StringencodeOrUnknown(String $self)Return the string encoded for safe use as a file name or "unknown", if the string is empty. final static <Error class: unknown class>fileSystemEncode(String $self)Return the string encoded for safe use as a file name. final static <Error class: unknown class>isValidUri(String $self)True if the string is a valid URI, false otherwise. final static <Error class: unknown class>normalizeLineBreaks(String $self)Replace "\r\n" and "\r" line breaks with "\n". final static StringpercentEncode(String $self)Return the percent-encoded string. final static <Error class: unknown class>replaceCredentialsInUri(String $self, String userInfo)Replace any username / password in the URI represented by this String with userInfo. final static List<String>splitOnWhitespace(String $self)Return all substrings that do not contain any whitespace as a list. final static <Error class: unknown class>titlecase(String $self)Return this string lower-cased except for the first character which is upper-cased. final static <Error class: unknown class>toUri(String $self)Return a Result that indicates whether the conversion of this String to a URI was successful. final static <R extends Any> <Error class: unknown class>toUri(String $self, Function1<URI, R> transform)Return a Result that indicates whether the conversion of this String to a URI was successful, and transform the URI if so. final static <Error class: unknown class>unquote(String $self, Boolean trimWhitespace)Return this string with (nested) single- and double-quotes removed. final static <Error class: unknown class>uppercaseFirstChar(String $self)Return this string with the first character upper-cased. final static StringwithoutPrefix(String $self, String prefix, Function0<String> missingPrefixValue)If this string starts with prefix, return the string without the prefix, otherwise return missingPrefixValue. final static StringwithoutSuffix(String $self, String suffix, Function0<String> missingSuffixValue)If this string ends with suffix, return the string without the suffix, otherwise return missingSuffixValue. final static StringcollectMessages(Throwable $self)Recursively collect the messages of this Throwable and all its causes and join them to a single String. final static Map<String, List<String>>getQueryParameters(URI $self)Retrieve query parameters of this URI. -
-
Method Detail
-
getFormatSizeInMib
final String getFormatSizeInMib()
-
getKibibytes
final Long getKibibytes()
-
getMebibytes
final Long getMebibytes()
-
getGibibytes
final Long getGibibytes()
-
getNON_LINUX_LINE_BREAKS
final Regex getNON_LINUX_LINE_BREAKS()
A regular expression matching the non-linux line breaks "\r\n" and "\r".
-
alsoIfNull
final static <T extends Any> T alsoIfNull(T $self, Function1<T, Unit> block)
Call also only if the receiver is null, e.g. for error handling, and return the receiver in any case.
-
getDuplicates
final static <T extends Any, K extends Any> Map<K, List<T>> getDuplicates(Collection<T> $self, Function1<T, K> keySelector)
Return a map that associates duplicates as identified by keySelector with belonging lists of collection entries.
-
getDuplicates
final static <T extends Any> Set<T> getDuplicates(Collection<T> $self)
Return a set of duplicate entries of a collection.
-
collapseToRanges
final static List<Pair<Integer, Integer>> collapseToRanges(Collection<Integer> $self)
Collapse consecutive values to a list of pairs that each denote a range. A single value is represented as a range whose first and last elements are equal.
-
prettyPrintRanges
final static String prettyPrintRanges(Collection<Pair<Integer, Integer>> $self)
Return a string of common-separated ranges as denoted by the list of pairs.
-
format
final static <Error class: unknown class> format(Double $self, Integer decimalPlaces)
Format this Double as a string with the provided number of decimalPlaces.
-
plus
final static <E extends Enum<E>> EnumSet<E> plus(EnumSet<E> $self, EnumSet<E> other)
Return an EnumSet that contains the elements of this and other.
-
expandTilde
final static File expandTilde(File $self)
If the SHELL environment variable is set, return the absolute file with a leading "~" expanded to the current user's home directory, otherwise return just the absolute file.
-
expandTilde
final static String expandTilde(String $self)
If the SHELL environment variable is set, return the string with a leading "~" expanded to the current user's home directory, otherwise return the string unchanged.
-
isSymbolicLink
final static Boolean isSymbolicLink(File $self)
Return true if and only if this file is a symbolic link.
-
realFile
final static File realFile(File $self)
Resolve the file to the real underlying file. In contrast to Java's File.getCanonicalFile, this also works to resolve symbolic links on Windows.
-
safeDeleteRecursively
final static Unit safeDeleteRecursively(File $self, File baseDirectory)
Delete a directory recursively without following symbolic links (Unix) or junctions (Windows). If a baseDirectory is provided, all empty parent directories along the path to baseDirectory are also deleted; baseDirectory itself is not deleted. Throws an IOException if a directory or file could not be deleted.
-
safeMkdirs
final static File safeMkdirs(File $self)
Create all missing intermediate directories without failing if any already exists. Returns the File it was called on if successful, otherwise throws an IOException.
-
searchUpwardsForSubdirectory
final static File searchUpwardsForSubdirectory(File $self, String searchDirName)
Search this directory upwards towards the root until a contained subdirectory called searchDirName is found and return the parent of searchDirName, or return null if no such directory is found.
-
toSafeUri
final static URI toSafeUri(File $self)
Construct a "file:" URI in a safe way by never using a null authority for wider compatibility.
-
nextOrNull
final static <T extends Any> T nextOrNull(Iterator<T> $self)
Return the next value in the iteration, or null if there is no next value.
-
fieldNamesOrEmpty
final static Iterator<String> fieldNamesOrEmpty(JsonNode $self)
-
fieldsOrEmpty
final static Iterator<Entry.Map<String, JsonNode>> fieldsOrEmpty(JsonNode $self)
-
isNotEmpty
final static Boolean isNotEmpty(JsonNode $self)
Return true if and only if this JsonNode
-
textValueOrEmpty
final static String textValueOrEmpty(JsonNode $self)
Convenience function for JsonNode that returns an empty string if JsonNode.textValue is called on a null object, or the text value is null.
-
zip
final static <K extends Any, V extends Any> Map<K, V> zip(Map<K, V> $self, Map<K, V> other, Function2<V, V, V> operation)
Merge two maps by iterating over the combined key set of both maps and calling operation with any conflicting values for the same key. In case of a SortedMap the iteration order is maintained.
-
zipWithSets
final static <K extends Any, V extends Set<T>, T extends Any> Map<K, V> zipWithSets(Map<K, V> $self, Map<K, V> other)
Merge two maps which have sets as values by creating the combined key set of both maps and merging the sets. If there is no entry for a key in one of the maps, the value from the other map is used.
-
bytesToMib
final static Double bytesToMib(Number $self)
Converts this Number from bytes to mebibytes (MiB).
-
collapseWhitespace
final static <Error class: unknown class> collapseWhitespace(String $self)
Trim leading and trailing whitespace, and collapse consecutive inner whitespace to a single space.
-
encodeOr
final static String encodeOr(String $self, String emptyValue)
Return the string encoded for safe use as a file name or emptyValue encoded for safe use as a file name, if this string is empty. Throws an exception if emptyValue is empty.
-
encodeOrUnknown
final static String encodeOrUnknown(String $self)
Return the string encoded for safe use as a file name or "unknown", if the string is empty.
-
fileSystemEncode
final static <Error class: unknown class> fileSystemEncode(String $self)
Return the string encoded for safe use as a file name. Also limit the length to 255 characters which is the maximum length in most modern filesystems, see comparison of file system limits.
-
isValidUri
final static <Error class: unknown class> isValidUri(String $self)
True if the string is a valid URI, false otherwise.
-
normalizeLineBreaks
final static <Error class: unknown class> normalizeLineBreaks(String $self)
Replace "\r\n" and "\r" line breaks with "\n".
-
percentEncode
final static String percentEncode(String $self)
Return the percent-encoded string.
-
replaceCredentialsInUri
final static <Error class: unknown class> replaceCredentialsInUri(String $self, String userInfo)
Replace any username / password in the URI represented by this String with userInfo. If userInfo is null, the username / password are stripped. Return the unmodified String if it does not represent a URI.
-
splitOnWhitespace
final static List<String> splitOnWhitespace(String $self)
Return all substrings that do not contain any whitespace as a list.
-
titlecase
final static <Error class: unknown class> titlecase(String $self)
Return this string lower-cased except for the first character which is upper-cased.
-
toUri
final static <R extends Any> <Error class: unknown class> toUri(String $self, Function1<URI, R> transform)
Return a Result that indicates whether the conversion of this String to a URI was successful, and transform the URI if so.
-
unquote
final static <Error class: unknown class> unquote(String $self, Boolean trimWhitespace)
Return this string with (nested) single- and double-quotes removed. If trimWhitespace is true, then intermediate whitespace is also removed, otherwise it is kept.
-
uppercaseFirstChar
final static <Error class: unknown class> uppercaseFirstChar(String $self)
Return this string with the first character upper-cased.
-
withoutPrefix
final static String withoutPrefix(String $self, String prefix, Function0<String> missingPrefixValue)
If this string starts with prefix, return the string without the prefix, otherwise return missingPrefixValue.
-
withoutSuffix
final static String withoutSuffix(String $self, String suffix, Function0<String> missingSuffixValue)
If this string ends with suffix, return the string without the suffix, otherwise return missingSuffixValue.
-
collectMessages
final static String collectMessages(Throwable $self)
Recursively collect the messages of this Throwable and all its causes and join them to a single String.
-
getQueryParameters
final static Map<String, List<String>> getQueryParameters(URI $self)
Retrieve query parameters of this URI. Multiple values of a single key are supported if they are split by a comma, or if keys are repeated as defined in RFC6570 section 3.2.9, see https://datatracker.ietf.org/doc/rfc6570.
-
-
-
-