LazyLib

org.lazywizard.lazylib
Class CollectionUtils

Object
  extended by CollectionUtils

public class CollectionUtils
extends Object

Contains methods for working with Collections.

Since:
1.0
Author:
LazyWizard

Nested Class Summary
static interface CollectionUtils.CollectionFilter<T>
          Used with filter(Collection, CollectionUtils.CollectionFilter) to filter out unwanted entries in a Collection.
static class CollectionUtils.SortEntitiesByDistance
          A Comparator that sorts CombatEntityAPIs by distance from the Vector2f passed into the constructor.
static class CollectionUtils.SortObjectivesByDistance
          Deprecated. Use CollectionUtils.SortEntitiesByDistance instead.
static class CollectionUtils.SortTokensByDistance
          A Comparator that sorts SectorEntityTokens by distance the Vector2f passed into the constructor.
 
Method Summary
static
<T> List<T>
filter(Collection<T> toFilter, CollectionUtils.CollectionFilter<T> filter)
          Filters a Collection and returns a List containing only the entries that the filter accepted.
static
<T> List<T>
filter(Collection<T> toFilter, List<CollectionUtils.CollectionFilter<T>> filters)
          Filters a Collection and returns a List containing only the entries that the filters accepted.
static String implode(Collection toImplode)
          Creates a comma-separated String from a Collection's entries.
static String implode(Collection toImplode, String separator)
          Combines and separates a Collection of Strings.
static
<T> T
weightedRandom(Map<T,Float> pickFrom)
          Deprecated. Use WeightedRandomPicker instead.
static
<T> List<T>
weightedRandom(Map<T,Float> pickFrom, int numToPick)
          Deprecated. Use WeightedRandomPicker instead (call pick() multiple times).
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

implode

public static String implode(Collection toImplode,
                             String separator)
Combines and separates a Collection of Strings. Useful for comma-separated lists.

Parameters:
toImplode - A Collection whose contents should be combined into one String.
separator - The separator character to split toImplode with.

Returns:
A single String consisting of toImplode's values separated with separator.

Since:
1.0

implode

public static String implode(Collection toImplode)
Creates a comma-separated String from a Collection's entries.

Parameters:
toImplode - A Collection to be combined (using each entry's toString method).

Returns:
A single String consisting of toImplode's values separated with commas.

Since:
1.0
See Also:
implode(java.util.Collection, java.lang.String)

filter

public static <T> List<T> filter(Collection<T> toFilter,
                                 CollectionUtils.CollectionFilter<T> filter)
Filters a Collection and returns a List containing only the entries that the filter accepted.

Parameters:
toFilter - The Collection to filter.
filter - A CollectionUtils.CollectionFilter that will be used to filter toFilter.

Returns:
A List containing only the entries of toFilter that passed filter's accept() method.

Since:
1.7

filter

public static <T> List<T> filter(Collection<T> toFilter,
                                 List<CollectionUtils.CollectionFilter<T>> filters)
Filters a Collection and returns a List containing only the entries that the filters accepted.

Parameters:
toFilter - The Collection to filter.
filters - A List of CollectionUtils.CollectionFilters that will be used to filter toFilter.

Returns:
A List containing only the entries of toFilter that passed filters' accept() method.

Since:
1.7
See Also:
filter(Collection, CollectionUtils.CollectionFilter)

weightedRandom

@Deprecated
public static <T> List<T> weightedRandom(Map<T,Float> pickFrom,
                                                    int numToPick)
Deprecated. Use WeightedRandomPicker instead (call pick() multiple times).

Since:
1.0

weightedRandom

@Deprecated
public static <T> T weightedRandom(Map<T,Float> pickFrom)
Deprecated. Use WeightedRandomPicker instead.

Since:
1.0

LazyLib