Class ExtensionsKt

  • All Implemented Interfaces:

    
    public final class ExtensionsKt
    
                        
    • Constructor Detail

    • Method Detail

      • 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.

      • encodeHex

         final static String encodeHex(ByteArray $self)

        Return a string of lowercase hexadecimal digits representing the bytes in the array.

      • 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.

      • 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.

      • 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, Boolean force, File baseDirectory)

        Delete files recursively without following symbolic links (Unix) or junctions (Windows). If force is true, files which were not deleted in the first attempt are set to be writable and then tried to be deleted again. If baseDirectory is given, all empty parent directories along the path to baseDirectory are also deleted; baseDirectory itself is not deleted. Throws an IOException if a 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.

      • 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, W extends Any> Map<K, W> zip(Map<K, V> $self, Map<K, V> other, Function2<V, V, W> operation)

        Merge two maps by iterating over the combined key set of both maps and applying operation to the entries for the same key. Arguments passed to operation can be null if there is no entry for a key in the respective map.

      • zipWithDefault

         final static <K extends Any, V extends Any, W extends Any> Map<K, W> zipWithDefault(Map<K, V> $self, Map<K, V> other, V default, Function2<V, V, W> operation)

        Merge two maps by iterating over the combined key set of both maps and applying operation to the entries for the same key. If there is no entry for a key in one of the maps, default is used as the value for that map.

      • zipWithCollections

         final static <K extends Any, V extends Collection<T>, T extends Any> Map<K, V> zipWithCollections(Map<K, V> $self, Map<K, V> other)

        Merge two maps which have collections as values by creating the combined key set of both maps and merging the collections. If there is no entry for a key in one of the maps, the value from the other map is used.

      • 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.

      • collapseWhitespace

         final static String 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.

      • isFalse

         final static Boolean isFalse(String $self)

        Return true if the string represents a false value, otherwise return false.

      • isTrue

         final static Boolean isTrue(String $self)

        Return true if the string represents a true value, otherwise return false.

      • replaceCredentialsInUri

         final static String 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.

      • titlecase

         final static String titlecase(String $self)

        Return this string lower-cased except for the first character which is upper-cased.

      • toUri

         final static <R extends Any> Result<R> 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 String 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.

      • 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.

      • 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.