Class StringIterate


  • public final class StringIterate
    extends java.lang.Object
    A string is essentially an array of characters. In Smalltalk a String is a subclass of ArrayedCollection, which means it supports the Collection protocol. StringIterate implements the methods available on the collection protocol that make sense for Strings. Some methods are over-specialized, in the form of englishToUppercase() which is a fast form of uppercase, but does not work for different locales.
    • Constructor Detail

      • StringIterate

        private StringIterate()
    • Method Detail

      • asCharAdapter

        public static CharAdapter asCharAdapter​(java.lang.String string)
        Since:
        7.0.
      • asCodePointAdapter

        public static CodePointAdapter asCodePointAdapter​(java.lang.String string)
        Since:
        7.0.
      • toCodePointList

        public static CodePointList toCodePointList​(java.lang.String string)
        Since:
        7.0.
      • csvTokensToSortedList

        @Deprecated
        public static MutableList<java.lang.String> csvTokensToSortedList​(java.lang.String string)
        Deprecated.
        in 3.0. Inlineable. Poorly named method. Does not actually deal properly with CSV. This is better handled in a separate library.
        Converts a string of tokens separated by the specified separator to a sorted MutableList.
      • csvTrimmedTokensToSortedList

        @Deprecated
        public static MutableList<java.lang.String> csvTrimmedTokensToSortedList​(java.lang.String string)
        Deprecated.
        in 3.0. Inlineable. Poorly named method. Does not actually deal properly with CSV. This is better handled in a separate library.
        Converts a string of tokens separated by the specified separator to a sorted MutableList.
      • tokensToSortedList

        public static MutableList<java.lang.String> tokensToSortedList​(java.lang.String string,
                                                                       java.lang.String separator)
        Converts a string of tokens separated by the specified separator to a sorted MutableList.
      • trimmedTokensToSortedList

        public static MutableList<java.lang.String> trimmedTokensToSortedList​(java.lang.String string,
                                                                              java.lang.String separator)
        Converts a string of tokens separated by the specified separator to a sorted MutableList.
      • csvTokensToList

        @Deprecated
        public static MutableList<java.lang.String> csvTokensToList​(java.lang.String string)
        Deprecated.
        in 3.0. Inlineable. Poorly named method. Does not actually deal properly with CSV. This is better handled in a separate library.
        Converts a string of tokens separated by commas to a MutableList.
      • csvTrimmedTokensToList

        @Deprecated
        public static MutableList<java.lang.String> csvTrimmedTokensToList​(java.lang.String string)
        Deprecated.
        in 3.0. Inlineable. Poorly named method. Does not actually deal properly with CSV. This is better handled in a separate library.
        Converts a string of tokens separated by commas to a MutableList.
      • tokensToList

        public static MutableList<java.lang.String> tokensToList​(java.lang.String string,
                                                                 java.lang.String separator)
        Converts a string of tokens separated by the specified separator to a MutableList.
      • trimmedTokensToList

        public static MutableList<java.lang.String> trimmedTokensToList​(java.lang.String string,
                                                                        java.lang.String separator)
        Converts a string of tokens separated by the specified separator to a MutableList.
      • trimStringList

        private static <L extends java.util.List<java.lang.String>> L trimStringList​(L strings)
        Applies String.trim() to each String in the List
        Returns:
        the input list, mutated in place, containing trimmed strings.
      • csvTokensToSet

        @Deprecated
        public static MutableSet<java.lang.String> csvTokensToSet​(java.lang.String string)
        Deprecated.
        in 3.0. Inlineable. Poorly named method. Does not actually deal properly with CSV. This is better handled in a separate library.
        Converts a string of tokens separated by commas to a MutableSet.
      • tokensToSet

        public static MutableSet<java.lang.String> tokensToSet​(java.lang.String string,
                                                               java.lang.String separator)
        Converts a string of tokens to a MutableSet.
      • tokensToMap

        public static MutableMap<java.lang.String,​java.lang.String> tokensToMap​(java.lang.String string)
        Converts a string of tokens to a MutableMap using a | to separate pairs, and a : to separate key and value. e.g. "1:Sunday|2:Monday|3:Tuesday|4:Wednesday|5:Thursday|6:Friday|7:Saturday"
      • tokensToMap

        public static MutableMap<java.lang.String,​java.lang.String> tokensToMap​(java.lang.String string,
                                                                                      java.lang.String pairSeparator,
                                                                                      java.lang.String keyValueSeparator)
        Converts a string of tokens to a MutableMap using the specified separators.
      • tokensToMap

        public static <K,​V> MutableMap<K,​V> tokensToMap​(java.lang.String string,
                                                                    java.lang.String separator,
                                                                    java.lang.String keyValueSeparator,
                                                                    Function<java.lang.String,​K> keyFunction,
                                                                    Function<java.lang.String,​V> valueFunction)
        Converts a string of tokens to a MutableMap using the specified 'key' and 'value' Functions. e.g. "1:2,2:1,3:3" with both functions as Functions.getStringToInteger(), will be translated a map {[1,2],[2,1],[3,3]}
      • csvTokensToReverseSortedList

        @Deprecated
        public static MutableList<java.lang.String> csvTokensToReverseSortedList​(java.lang.String string)
        Deprecated.
        in 3.0. Inlineable. Poorly named method. Does not actually deal properly with CSV. This is better handled in a separate library.
        Converts a string of tokens separated by the specified separator to a reverse sorted MutableList.
      • tokensToReverseSortedList

        public static MutableList<java.lang.String> tokensToReverseSortedList​(java.lang.String string,
                                                                              java.lang.String separator)
        Converts a string of tokens separated by the specified separator to a reverse sorted MutableList.
      • forEachToken

        public static void forEachToken​(java.lang.String string,
                                        java.lang.String separator,
                                        Procedure<java.lang.String> procedure)
        For each token in a string separated by the specified separator, execute the specified StringProcedure by calling the valueOfString method.
      • injectIntoTokens

        public static <T,​R> R injectIntoTokens​(java.lang.String string,
                                                     java.lang.String separator,
                                                     R injectedValue,
                                                     Function2<? super R,​java.lang.String,​? extends R> function)
        For each token in a string separated by the specified separator, execute the specified Function2, returning the result value from the function. For more information, see Iterate.injectInto(Object, Iterable, Function2)
      • forEachTrimmedToken

        public static void forEachTrimmedToken​(java.lang.String string,
                                               java.lang.String separator,
                                               Procedure<java.lang.String> procedure)
        For each token in a string separated by the specified separator, execute the specified Procedure.
      • forEachChar

        public static void forEachChar​(java.lang.String string,
                                       CharProcedure procedure)
        For each char in the string, execute the CharProcedure.
        Since:
        7.0
      • forEachCodePoint

        public static void forEachCodePoint​(java.lang.String string,
                                            CodePointProcedure procedure)
        For each int code point in the string, execute the CodePointProcedure.
        Since:
        7.0
      • reverseForEachChar

        public static void reverseForEachChar​(java.lang.String string,
                                              CharProcedure procedure)
        For each char in the string in reverse order, execute the CharProcedure.
        Since:
        7.0
      • reverseForEachCodePoint

        public static void reverseForEachCodePoint​(java.lang.String string,
                                                   CodePointProcedure procedure)
        For each int code point in the string in reverse order, execute the CodePointProcedure.
        Since:
        7.0
      • lastIndex

        private static int lastIndex​(java.lang.String string)
      • numberOfChars

        public static int numberOfChars​(java.lang.String string,
                                        int i)
      • isSurrogate

        public static boolean isSurrogate​(java.lang.String string,
                                          int i)
      • count

        @Deprecated
        public static int count​(java.lang.String string,
                                CharPredicate predicate)
        Deprecated.
        since 3.0.
        Count the number of elements that return true for the specified predicate.
      • count

        @Deprecated
        public static int count​(java.lang.String string,
                                CharPredicate predicate)
        Deprecated.
        since 7.0. Use countChar(String, CharPredicate) instead.
        Count the number of elements that return true for the specified predicate.
      • countChar

        public static int countChar​(java.lang.String string,
                                    CharPredicate predicate)
        Count the number of elements that return true for the specified predicate.
        Since:
        7.0
      • countCodePoint

        public static int countCodePoint​(java.lang.String string,
                                         CodePointPredicate predicate)
        Count the number of elements that return true for the specified predicate.
        Since:
        7.0
      • collectChar

        public static java.lang.String collectChar​(java.lang.String string,
                                                   CharToCharFunction function)
        Transform the char elements to a new string using the specified function function.
        Since:
        7.0
      • collectCodePoint

        public static java.lang.String collectCodePoint​(java.lang.String string,
                                                        CodePointFunction function)
        Transform the int code point elements to a new string using the specified function function.
        Since:
        7.0
      • englishToUpperCase

        public static java.lang.String englishToUpperCase​(java.lang.String string)
      • englishToLowerCase

        public static java.lang.String englishToLowerCase​(java.lang.String string)
      • detect

        @Deprecated
        public static java.lang.Character detect​(java.lang.String string,
                                                 CharPredicate predicate)
        Deprecated.
        since 7.0. Use detectChar(String, CharPredicate) instead.
        Find the first element that returns true for the specified predicate.
      • detectChar

        public static java.lang.Character detectChar​(java.lang.String string,
                                                     CharPredicate predicate)
        Find the first element that returns true for the specified predicate.
        Since:
        7.0
      • detectIfNone

        @Deprecated
        public static java.lang.Character detectIfNone​(java.lang.String string,
                                                       CharPredicate predicate,
                                                       char resultIfNone)
        Deprecated.
        Find the first element that returns true for the specified predicate. Return the default char if no value is found.
      • detectCharIfNone

        public static java.lang.Character detectCharIfNone​(java.lang.String string,
                                                           CharPredicate predicate,
                                                           char resultIfNone)
        Find the first element that returns true for the specified predicate. Return the default char if no value is found.
      • detectIfNone

        @Deprecated
        public static java.lang.Character detectIfNone​(java.lang.String string,
                                                       CharPredicate predicate,
                                                       java.lang.String resultIfNone)
        Deprecated.
        Find the first element that returns true for the specified predicate. Return the first char of the default string if no value is found.
      • detectCharIfNone

        public static java.lang.Character detectCharIfNone​(java.lang.String string,
                                                           CharPredicate predicate,
                                                           java.lang.String resultIfNone)
        Find the first element that returns true for the specified predicate. Return the first char of the default string if no value is found.
      • occurrencesOf

        @Deprecated
        public static int occurrencesOf​(java.lang.String string,
                                        char value)
        Deprecated.
        since 7.0. Use occurrencesOfChar(String, char) instead.
        Count the number of occurrences of the specified char.
      • occurrencesOfChar

        public static int occurrencesOfChar​(java.lang.String string,
                                            char value)
        Count the number of occurrences of the specified char.
        Since:
        7.0
      • occurrencesOf

        @Deprecated
        public static int occurrencesOf​(java.lang.String string,
                                        int value)
        Deprecated.
        since 7.0. Use occurrencesOfCodePoint(String, int) instead.
        Count the number of occurrences of the specified int code point.
      • occurrencesOfCodePoint

        public static int occurrencesOfCodePoint​(java.lang.String string,
                                                 int value)
        Count the number of occurrences of the specified int code point.
        Since:
        7.0
      • occurrencesOf

        public static int occurrencesOf​(java.lang.String string,
                                        java.lang.String singleCharacter)
        Count the number of occurrences of the specified string.
      • anySatisfy

        @Deprecated
        public static boolean anySatisfy​(java.lang.String string,
                                         CharPredicate predicate)
        Deprecated.
        Returns:
        true if any of the characters in the string answer true for the specified predicate.
      • anySatisfyChar

        public static boolean anySatisfyChar​(java.lang.String string,
                                             CharPredicate predicate)
        Returns:
        true if any of the characters in the string answer true for the specified predicate.
        Since:
        7.0
      • anySatisfyCodePoint

        public static boolean anySatisfyCodePoint​(java.lang.String string,
                                                  CodePointPredicate predicate)
        Returns:
        true if any of the code points in the string answer true for the specified predicate.
        Since:
        7.0
      • allSatisfy

        @Deprecated
        public static boolean allSatisfy​(java.lang.String string,
                                         CharPredicate predicate)
        Deprecated.
        Returns:
        true if all the characters in the string answer true for the specified predicate.
      • allSatisfyChar

        public static boolean allSatisfyChar​(java.lang.String string,
                                             CharPredicate predicate)
        Returns:
        true if all the characters in the string answer true for the specified predicate.
        Since:
        7.0
      • allSatisfyCodePoint

        public static boolean allSatisfyCodePoint​(java.lang.String string,
                                                  CodePointPredicate predicate)
        Returns:
        true if all the code points in the string answer true for the specified predicate.
        Since:
        7.0
      • noneSatisfy

        @Deprecated
        public static boolean noneSatisfy​(java.lang.String string,
                                          CharPredicate predicate)
        Deprecated.
        Returns:
        true if none of the characters in the string answer true for the specified predicate.
      • noneSatisfyChar

        public static boolean noneSatisfyChar​(java.lang.String string,
                                              CharPredicate predicate)
        Returns:
        true if none of the characters in the string answer true for the specified predicate.
        Since:
        7.0
      • noneSatisfyCodePoint

        public static boolean noneSatisfyCodePoint​(java.lang.String string,
                                                   CodePointPredicate predicate)
        Returns:
        true if none of the code points in the string answer true for the specified predicate.
        Since:
        7.0
      • select

        @Deprecated
        public static java.lang.String select​(java.lang.String string,
                                              CharPredicate predicate)
        Deprecated.
        since 7.0. Use selectChar(String, CharPredicate) instead.
        Returns:
        a new string with all the characters that return true for the specified predicate.
      • selectChar

        public static java.lang.String selectChar​(java.lang.String string,
                                                  CharPredicate predicate)
        Returns:
        a new string with all the characters that return true for the specified predicate.
        Since:
        7.0
      • selectCodePoint

        public static java.lang.String selectCodePoint​(java.lang.String string,
                                                       CodePointPredicate predicate)
        Returns:
        a new string with all the code points that return true for the specified predicate.
        Since:
        7.0
      • reject

        @Deprecated
        public static java.lang.String reject​(java.lang.String string,
                                              CharPredicate predicate)
        Deprecated.
        since 7.0. Use rejectChar(String, CharPredicate) instead.
        Returns:
        a new string excluding all the characters that return true for the specified predicate.
      • rejectChar

        public static java.lang.String rejectChar​(java.lang.String string,
                                                  CharPredicate predicate)
        Returns:
        a new string excluding all the characters that return true for the specified predicate.
        Since:
        7.0
      • rejectCodePoint

        public static java.lang.String rejectCodePoint​(java.lang.String string,
                                                       CodePointPredicate predicate)
        Returns:
        a new string excluding all the code points that return true for the specified predicate.
        Since:
        7.0
      • getLastToken

        public static java.lang.String getLastToken​(java.lang.String value,
                                                    java.lang.String separator)
      • getFirstToken

        public static java.lang.String getFirstToken​(java.lang.String value,
                                                     java.lang.String separator)
      • isEmpty

        public static boolean isEmpty​(java.lang.String string)
      • isEmptyOrWhitespace

        public static boolean isEmptyOrWhitespace​(java.lang.String string)
      • isWhitespace

        private static boolean isWhitespace​(java.lang.String string)
      • isNumber

        public static boolean isNumber​(java.lang.String string)
      • isAlphaNumeric

        public static boolean isAlphaNumeric​(java.lang.String string)
      • charactersSatisfy

        private static boolean charactersSatisfy​(java.lang.String string,
                                                 CodePointPredicate predicate)
      • notEmpty

        public static boolean notEmpty​(java.lang.String string)
      • notEmptyOrWhitespace

        public static boolean notEmptyOrWhitespace​(java.lang.String string)
      • repeat

        public static java.lang.String repeat​(java.lang.String template,
                                              int repeatTimes)
      • repeat

        public static java.lang.String repeat​(char c,
                                              int repeatTimes)
      • padOrTrim

        public static java.lang.String padOrTrim​(java.lang.String message,
                                                 int targetLength)
      • toList

        public static MutableList<java.lang.Character> toList​(java.lang.String string)
      • toLowercaseList

        public static MutableList<java.lang.Character> toLowercaseList​(java.lang.String string)
      • toUppercaseList

        public static MutableList<java.lang.Character> toUppercaseList​(java.lang.String string)
      • toBag

        public static MutableBag<java.lang.Character> toBag​(java.lang.String string)
      • toLowercaseBag

        public static MutableBag<java.lang.Character> toLowercaseBag​(java.lang.String string)
      • toUppercaseBag

        public static MutableBag<java.lang.Character> toUppercaseBag​(java.lang.String string)
      • toSet

        public static MutableSet<java.lang.Character> toSet​(java.lang.String string)
      • chunk

        public static MutableList<java.lang.String> chunk​(java.lang.String string,
                                                          int size)
        Partitions String in fixed size chunks.
        Parameters:
        size - the number of characters per chunk
        Returns:
        A MutableList containing Strings of size size, except the last will be truncated (i.e. shorter) if the characters don't divide evenly.
        Since:
        5.2
      • asUppercaseSet

        @Deprecated
        public static MutableSet<java.lang.Character> asUppercaseSet​(java.lang.String string)
        Deprecated.
        in 3.0. Inlineable.
      • toUppercaseSet

        public static MutableSet<java.lang.Character> toUppercaseSet​(java.lang.String string)
      • asLowercaseSet

        @Deprecated
        public static MutableSet<java.lang.Character> asLowercaseSet​(java.lang.String string)
        Deprecated.
        in 3.0. Inlineable.
      • toLowercaseSet

        public static MutableSet<java.lang.Character> toLowercaseSet​(java.lang.String string)
      • splitAtIndex

        public static Twin<java.lang.String> splitAtIndex​(java.lang.String aString,
                                                          int index)