Package me.hsgamer.hscore.common
Class CollectionUtils
java.lang.Object
me.hsgamer.hscore.common.CollectionUtils
Methods on collections
-
Method Summary
Modifier and TypeMethodDescriptioncreateStringListFromObject(@Nullable Object value) Create a list of stringcreateStringListFromObject(@Nullable Object value, boolean trim) Create a list of stringstatic <T> TpickRandom(@NotNull Collection<T> collection) Pick a random element from the collectionstatic <T> TpickRandom(@NotNull Collection<T> collection, @NotNull Predicate<T> matchCondition) Pick a random element from the collectionstatic <T> TpickRandom(T[] array) Pick a random element from the arraystatic <T> TpickRandom(T[] array, @NotNull Predicate<T> matchCondition) Pick a random element from the arraystatic <T> @NotNull List<T> repeatCollection(@NotNull Collection<T> original, int repeat) Repeat the collectionstatic <T> @NotNull List<T> repeatElement(@NotNull Collection<T> original, int repeat) Repeat the element of the collectionstatic <T> @NotNull List<T> reverse(@NotNull Collection<T> original) Reverse a collectionstatic <T> @NotNull List<T> rotate(@NotNull Collection<T> original, int distance) Rotate a collectionsplitAll(@NotNull String regex, @NotNull Collection<String> strings) Split the strings from the string list
-
Method Details
-
createStringListFromObject
@NotNull public static @NotNull List<String> createStringListFromObject(@Nullable @Nullable Object value, boolean trim) Create a list of string- Parameters:
value- the objecttrim- 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
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 collectiondistance- 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 collectionrepeat- 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 collectionrepeat- 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 expressionstrings- 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 collectionmatchCondition- 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
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 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 arraymatchCondition- 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 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
-