com.atlassian.bamboo.util
Class BambooCollectionUtils

java.lang.Object
  extended by com.atlassian.bamboo.util.BambooCollectionUtils

public class BambooCollectionUtils
extends Object


Method Summary
static
<E> boolean
addIgnoreNull(Collection<? super E> collection, E element)
          Add element to the collection if it is not null.
static
<T> boolean
contains(Collection<T> collection, Object object)
           
static List<String> convertToList(String s)
           
static
<E> E
get(List<? extends E> list, int index)
          Get Nth element from list or null if list hasn't got so many elements
static
<T> HashSet<T>
newHashSet(Collection<T> collection)
           
static
<T> com.google.common.collect.ImmutableList<T>
newImmutableList(Collection<T> collection)
           
static
<T> List<T>
nullToEmptyImmutable(List<T> list)
           
static
<K,V> Map<K,V>
nullToEmptyImmutable(Map<K,V> map)
           
static
<T> Set<T>
nullToEmptyImmutable(Set<T> set)
           
static
<T> List<T>
removeDuplicates(List<T> input)
           
static
<T extends Comparable<? super T>>
List<T>
removeDuplicatesAndSort(List<T> input)
           
static
<T> List<T>
removeDuplicatesAndSort(List<T> input, 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 Set<String> stringArrayToHashSet(String[] values)
           
static List<String> stringArrayToList(String[] s)
           
static List<String> stringToCollection(String s)
          Converts a string with a given pattern into a Collection of strings.
static
<T> List<T>
subtract(Collection<T> a, Collection<T> b)
          Generic version of ListUtils.subtract
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

stringToCollection

@NotNull
public static 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 List<String> stringArrayToList(@Nullable
                                                     String[] s)

stringArrayToHashSet

@NotNull
public static Set<String> stringArrayToHashSet(@Nullable
                                                       String[] values)

removeDuplicates

@Nullable
public static <T> List<T> removeDuplicates(@Nullable
                                                    List<T> input)

removeDuplicatesAndSort

@Nullable
public static <T extends Comparable<? super T>> List<T> removeDuplicatesAndSort(List<T> input)

removeDuplicatesAndSort

@Nullable
public static <T> List<T> removeDuplicatesAndSort(List<T> input,
                                                           @NotNull
                                                           Comparator<? super T> c)

convertToList

@Nullable
public static List<String> convertToList(@Nullable
                                                  String s)

subtract

@NotNull
public static <T> List<T> subtract(@NotNull
                                           Collection<T> a,
                                           @NotNull
                                           Collection<T> b)
Generic version of ListUtils.subtract

Type Parameters:
T - any type
Parameters:
a - collection A
b - 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
                                        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 to
element - Element to be added to the collection
Returns:
true if the collection changed

get

@Nullable
public 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 elements

Type Parameters:
E - Type of the elements in the list
Parameters:
list - List to get element from
index - Index of element to get
Returns:
Element of given index or null

nullToEmptyImmutable

@NotNull
public static <T> List<T> nullToEmptyImmutable(@Nullable
                                                       List<T> list)

nullToEmptyImmutable

@NotNull
public static <T> Set<T> nullToEmptyImmutable(@Nullable
                                                      Set<T> set)

nullToEmptyImmutable

@NotNull
public static <K,V> Map<K,V> nullToEmptyImmutable(@Nullable
                                                          Map<K,V> map)

contains

public static <T> boolean contains(@Nullable
                                   Collection<T> collection,
                                   Object object)
Returns:
true if collection is not null and contains object

newImmutableList

@NotNull
public static <T> com.google.common.collect.ImmutableList<T> newImmutableList(@Nullable
                                                                                      Collection<T> collection)

newHashSet

public static <T> HashSet<T> newHashSet(Collection<T> collection)


Copyright © 2015 Atlassian Software Systems Pty Ltd. All rights reserved.