Class Utils


  • public class Utils
    extends Object
    • Constructor Detail

      • Utils

        public Utils()
    • Method Detail

      • ifNull

        public static <T> T ifNull​(T receiver,
                                   T altValue)
      • ifNullOr

        public static <T> T ifNullOr​(T receiver,
                                     boolean condition,
                                     T altValue)
      • ifNullOrNot

        public static <T> T ifNullOrNot​(T receiver,
                                        boolean condition,
                                        T altValue)
      • ifNullOr

        public static <T> T ifNullOr​(T receiver,
                                     Function<T,​Boolean> condition,
                                     T altValue)
      • ifNullOrNot

        public static <T> T ifNullOrNot​(T receiver,
                                        Function<T,​Boolean> condition,
                                        T altValue)
      • ifNullOrEmpty

        public static String ifNullOrEmpty​(String receiver,
                                           String altValue)
      • ifNullOrBlank

        public static String ifNullOrBlank​(String receiver,
                                           String altValue)
      • ifEmptyNullArgs

        public static String ifEmptyNullArgs​(String receiver,
                                             String ifEmptyArg,
                                             String ifNotEmptyArg)
      • isBlank

        public static boolean isBlank​(String receiver)
      • isWhiteSpaceNoEOL

        public static boolean isWhiteSpaceNoEOL​(String receiver)
      • orEmpty

        public static String orEmpty​(String receiver)
      • wrapWith

        public static String wrapWith​(String receiver,
                                      char prefixSuffix)
      • wrapWith

        public static String wrapWith​(String receiver,
                                      char prefix,
                                      char suffix)
      • suffixWith

        public static String suffixWith​(String receiver,
                                        char suffix)
      • suffixWithEol

        public static String suffixWithEol​(String receiver)
      • suffixWith

        public static String suffixWith​(String receiver,
                                        char suffix,
                                        boolean ignoreCase)
      • suffixWith

        public static String suffixWith​(String receiver,
                                        String suffix,
                                        boolean ignoreCase)
      • prefixWith

        public static String prefixWith​(String receiver,
                                        char prefix)
      • prefixWith

        public static String prefixWith​(String receiver,
                                        char prefix,
                                        boolean ignoreCase)
      • prefixWith

        public static String prefixWith​(String receiver,
                                        String prefix,
                                        boolean ignoreCase)
      • isIn

        public static boolean isIn​(String receiver,
                                   String... list)
      • endsWith

        public static boolean endsWith​(String receiver,
                                       String... needles)
      • endsWith

        public static boolean endsWith​(String receiver,
                                       boolean ignoreCase,
                                       String... needles)
      • startsWith

        public static boolean startsWith​(String receiver,
                                         String... needles)
      • startsWith

        public static boolean startsWith​(String receiver,
                                         boolean ignoreCase,
                                         String... needles)
      • count

        public static int count​(String receiver,
                                char c,
                                int startIndex,
                                int endIndex)
      • count

        public static int count​(String receiver,
                                String c,
                                int startIndex,
                                int endIndex)
      • removePrefix

        public static String removePrefix​(String receiver,
                                          char prefix)
      • removeAnyPrefix

        public static String removeAnyPrefix​(String receiver,
                                             String... prefixes)
      • removePrefixIncluding

        public static String removePrefixIncluding​(String receiver,
                                                   String delimiter)
      • removeSuffix

        public static String removeSuffix​(String receiver,
                                          char suffix)
      • removeAnySuffix

        public static String removeAnySuffix​(String receiver,
                                             String... suffixes)
      • regexGroup

        public static String regexGroup​(String receiver)
      • regionMatches

        public static boolean regionMatches​(CharSequence receiver,
                                            int thisOffset,
                                            String other,
                                            int otherOffset,
                                            int length,
                                            boolean ignoreCase)
      • endsWith

        public static boolean endsWith​(CharSequence receiver,
                                       String suffix,
                                       boolean ignoreCase)
      • startsWith

        public static boolean startsWith​(CharSequence receiver,
                                         String prefix,
                                         boolean ignoreCase)
      • getLongestCommonPrefix

        public static String getLongestCommonPrefix​(String... s)
        Longest Common Prefix for a set of strings
        Parameters:
        s - array of strings or null
        Returns:
        longest common prefix
      • getAbbreviatedText

        public static String getAbbreviatedText​(String text,
                                                int maxLength)
      • repeat

        public static String repeat​(String text,
                                    int repeatCount)
      • max

        public static int max​(int receiver,
                              int... others)
      • min

        public static int min​(int receiver,
                              int... others)
      • minLimit

        public static int minLimit​(int receiver,
                                   int... minBound)
      • maxLimit

        public static int maxLimit​(int receiver,
                                   int... maxBound)
      • rangeLimit

        public static int rangeLimit​(int receiver,
                                     int minBound,
                                     int maxBound)
      • max

        public static float max​(float receiver,
                                float... others)
      • min

        public static float min​(float receiver,
                                float... others)
      • minLimit

        public static float minLimit​(float receiver,
                                     float... minBound)
      • maxLimit

        public static float maxLimit​(float receiver,
                                     float... maxBound)
      • rangeLimit

        public static float rangeLimit​(float receiver,
                                       float minBound,
                                       float maxBound)
      • compare

        public static int compare​(@Nullable
                                  @Nullable Number n1,
                                  @Nullable
                                  @Nullable Number n2)
      • compareNullable

        public static <T extends Comparable<T>> int compareNullable​(T i1,
                                                                    T i2)
      • putIfMissing

        public static <K,​V> V putIfMissing​(Map<K,​V> receiver,
                                                 K key,
                                                 Supplier<V> value)
      • withDefaults

        public static <K,​V> Map<K,​V> withDefaults​(Map<K,​V> receiver,
                                                              Map<K,​V> defaults)
      • removeIf

        public static <K,​V> void removeIf​(Map<K,​V> receiver,
                                                BiFunction<K,​V,​Boolean> removeFilter)
      • getResourceAsString

        public static String getResourceAsString​(Class<?> clazz,
                                                 String resourcePath)
      • escapeJavaString

        @NotNull
        public static @NotNull String escapeJavaString​(@Nullable
                                                       @Nullable CharSequence param)
      • quoteJavaString

        @NotNull
        public static @NotNull String quoteJavaString​(@Nullable
                                                      @Nullable CharSequence param)
      • escapeJavaString

        public static void escapeJavaString​(@NotNull
                                            @NotNull StringBuilder out,
                                            @NotNull
                                            @NotNull CharSequence chars)
      • getOrNull

        public static <T> T getOrNull​(@NotNull
                                      @NotNull List<T> list,
                                      int index)
      • getOrNull

        public static <T,​S extends T> S getOrNull​(@NotNull
                                                        @NotNull List<T> list,
                                                        int index,
                                                        Class<S> elementClass)
      • setOrAdd

        public static <T> T setOrAdd​(@NotNull
                                     @NotNull List<T> list,
                                     int index,
                                     T value)