Package com.atlassian.bamboo.util
Class BambooCollectionUtils
- java.lang.Object
-
- com.atlassian.bamboo.util.BambooCollectionUtils
-
public class BambooCollectionUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E> boolean
addIgnoreNull(@NotNull Collection<? super E> collection, E element)
Add element to the collection if it is not null.static <T> boolean
contains(@Nullable Collection<T> collection, Object object)
static @Nullable List<String>
convertToList(@Nullable String s)
static <E> E
get(@NotNull List<? extends E> list, int index)
Get Nth element from list or null if list hasn't got so many elementsstatic <T> @NotNull Collection<T>
getLastElements(@NotNull Collection<T> collection, int numberOfElements)
Returns the last N elements of a collection.static <T> HashSet<T>
newHashSet(Collection<T> collection)
static <T> @NotNull com.google.common.collect.ImmutableList<T>
newImmutableList(@Nullable Collection<T> collection)
static <T> @NotNull com.google.common.collect.ImmutableSet<T>
newImmutableSet(@Nullable Iterable<T> set)
Creates a new immutable set from the supplied set.static <T> @NotNull List<T>
nullToEmptyImmutable(@Nullable List<T> list)
static <K,V>
@NotNull Map<K,V>nullToEmptyImmutable(@Nullable Map<K,V> map)
static <T> @NotNull Set<T>
nullToEmptyImmutable(@Nullable Set<T> set)
static <T> @Nullable List<T>
removeDuplicates(@Nullable List<T> input)
static <T extends Comparable<? super T>>
@Nullable List<T>removeDuplicatesAndSort(List<T> input)
static <T> @Nullable List<T>
removeDuplicatesAndSort(List<T> input, @NotNull Comparator<? super T> c)
static <K,V extends Comparable<? super V>>
List<Map.Entry<K,V>>sortByValue(Map<K,V> map)
Given a map returns the list of entries in the map sorted by Entry.getValue() in descending order.static @NotNull Set<String>
stringArrayToHashSet(@Nullable String[] values)
static @NotNull List<String>
stringArrayToList(@Nullable String[] s)
static @NotNull List<String>
stringToCollection(String s)
Converts a string with a given pattern into a Collection of strings.static <T> @NotNull List<T>
subtract(@NotNull Collection<T> a, @NotNull Collection<T> b)
Generic version of ListUtils.subtract
-
-
-
Method Detail
-
stringToCollection
@NotNull public static @NotNull List<String> stringToCollection(String s)
Converts a string with a given pattern into a Collection of strings.- Parameters:
s
- string to be analyzed- Returns:
- list of strings
-
stringArrayToList
@NotNull public static @NotNull List<String> stringArrayToList(@Nullable @Nullable String[] s)
-
stringArrayToHashSet
@NotNull public static @NotNull Set<String> stringArrayToHashSet(@Nullable @Nullable String[] values)
-
removeDuplicates
@Nullable public static <T> @Nullable List<T> removeDuplicates(@Nullable @Nullable List<T> input)
-
removeDuplicatesAndSort
@Nullable public static <T extends Comparable<? super T>> @Nullable List<T> removeDuplicatesAndSort(List<T> input)
-
removeDuplicatesAndSort
@Nullable public static <T> @Nullable List<T> removeDuplicatesAndSort(List<T> input, @NotNull @NotNull Comparator<? super T> c)
-
convertToList
@Nullable public static @Nullable List<String> convertToList(@Nullable @Nullable String s)
-
subtract
@NotNull public static <T> @NotNull List<T> subtract(@NotNull @NotNull Collection<T> a, @NotNull @NotNull Collection<T> b)
Generic version of ListUtils.subtract- Type Parameters:
T
- any type- Parameters:
a
- collection Ab
- collection B- Returns:
- List of (A - B)
-
sortByValue
public static <K,V extends Comparable<? super V>> List<Map.Entry<K,V>> sortByValue(Map<K,V> map)
Given a map returns the list of entries in the map sorted by Entry.getValue() in descending order.- Parameters:
map
-- Returns:
- sorted list of map's entries
-
addIgnoreNull
public static <E> boolean addIgnoreNull(@NotNull @NotNull Collection<? super E> collection, @Nullable E element)
Add element to the collection if it is not null. Generified version of Apache's CollectionUtils.addIgnoreNull.- Type Parameters:
E
- Element type- Parameters:
collection
- Collection where element will be added toelement
- Element to be added to the collection- Returns:
- true if the collection changed
-
get
@Nullable public static <E> E get(@NotNull @NotNull List<? extends E> list, int index)
Get Nth element from list or null if list hasn't got so many elements- Type Parameters:
E
- Type of the elements in the list- Parameters:
list
- List to get element fromindex
- Index of element to get- Returns:
- Element of given index or null
-
nullToEmptyImmutable
@NotNull public static <T> @NotNull List<T> nullToEmptyImmutable(@Nullable @Nullable List<T> list)
-
nullToEmptyImmutable
@NotNull public static <T> @NotNull Set<T> nullToEmptyImmutable(@Nullable @Nullable Set<T> set)
-
nullToEmptyImmutable
@NotNull public static <K,V> @NotNull Map<K,V> nullToEmptyImmutable(@Nullable @Nullable Map<K,V> map)
-
contains
public static <T> boolean contains(@Nullable @Nullable Collection<T> collection, Object object)
- Returns:
- true if collection is not null and contains object
-
newImmutableList
@NotNull public static <T> @NotNull com.google.common.collect.ImmutableList<T> newImmutableList(@Nullable @Nullable Collection<T> collection)
-
newImmutableSet
@NotNull public static <T> @NotNull com.google.common.collect.ImmutableSet<T> newImmutableSet(@Nullable @Nullable Iterable<T> set)
Creates a new immutable set from the supplied set. Returns empty set for null.
-
newHashSet
public static <T> HashSet<T> newHashSet(Collection<T> collection)
-
getLastElements
@NotNull public static <T> @NotNull Collection<T> getLastElements(@NotNull @NotNull Collection<T> collection, int numberOfElements)
Returns the last N elements of a collection.- Parameters:
collection
- collection of any elementsnumberOfElements
- number of last elements to return - must not be a negative number, must be no greater than the size of provided collection- Returns:
- last N elements from the collection
-
-