Class CollectionUtils

java.lang.Object
me.hsgamer.hscore.common.CollectionUtils

public final class CollectionUtils extends Object
Methods on collections
  • Method Details

    • createStringListFromObject

      @NotNull public static @NotNull List<String> createStringListFromObject(@Nullable @Nullable Object value, boolean trim)
      Create a list of string
      Parameters:
      value - the object
      trim - should we trim the strings
      Returns:
      the string list
    • createStringListFromObject

      @NotNull public static @NotNull List<String> createStringListFromObject(@Nullable @Nullable Object value)
      Create a list of string
      Parameters:
      value - the object
      Returns:
      the string list
    • reverse

      @NotNull public static <T> @NotNull List<T> reverse(@NotNull @NotNull Collection<T> original)
      Reverse a collection
      Type Parameters:
      T - the type of the elements
      Parameters:
      original - the original collection
      Returns:
      the reversed list
    • rotate

      @NotNull public static <T> @NotNull List<T> rotate(@NotNull @NotNull Collection<T> original, int distance)
      Rotate a collection
      Type Parameters:
      T - the type of the elements
      Parameters:
      original - the original collection
      distance - the distance to rotate
      Returns:
      the rotated list
    • repeatElement

      @NotNull public static <T> @NotNull List<T> repeatElement(@NotNull @NotNull Collection<T> original, int repeat)
      Repeat the element of the collection
      Type Parameters:
      T - the type of the elements
      Parameters:
      original - the original collection
      repeat - the times the element repeats
      Returns:
      the repeated list
    • repeatCollection

      @NotNull public static <T> @NotNull List<T> repeatCollection(@NotNull @NotNull Collection<T> original, int repeat)
      Repeat the collection
      Type Parameters:
      T - the type of the elements
      Parameters:
      original - the original collection
      repeat - the times the list repeats
      Returns:
      the repeated list
    • splitAll

      @NotNull public static @NotNull List<String> splitAll(@NotNull @NotNull String regex, @NotNull @NotNull Collection<String> strings)
      Split the strings from the string list
      Parameters:
      regex - the delimiting regular expression
      strings - the string list
      Returns:
      the split string list
    • pickRandom

      @Nullable public static <T> T pickRandom(@NotNull @NotNull Collection<T> collection, @NotNull @NotNull Predicate<T> matchCondition)
      Pick a random element from the collection
      Type Parameters:
      T - the type of the elements
      Parameters:
      collection - the collection
      matchCondition - the condition of the picked element
      Returns:
      the picked element, or null if the collection is empty or there is no element that matches the condition
    • pickRandom

      @Nullable public static <T> T pickRandom(@NotNull @NotNull Collection<T> collection)
      Pick a random element from the collection
      Type Parameters:
      T - the type of the elements
      Parameters:
      collection - the collection
      Returns:
      the picked element, or null if the collection is empty
    • pickRandom

      @Nullable public static <T> T pickRandom(@NotNull @NotNull T[] array, @NotNull @NotNull Predicate<T> matchCondition)
      Pick a random element from the array
      Type Parameters:
      T - the type of the elements
      Parameters:
      array - the array
      matchCondition - the condition of the picked element
      Returns:
      the picked element, or null if the array is empty or there is no element that matches the condition
    • pickRandom

      @Nullable public static <T> T pickRandom(@NotNull @NotNull T[] array)
      Pick a random element from the array
      Type Parameters:
      T - the type of the elements
      Parameters:
      array - the array
      Returns:
      the picked element, or null if the collection is empty