LazyLib

org.lazywizard.lazylib
Class CollectionUtils

java.lang.Object
  extended by org.lazywizard.lazylib.CollectionUtils

public class CollectionUtils
extends java.lang.Object

Contains methods for working with Collections.

Since:
1.0
Author:
LazyWizard

Nested Class Summary
static class CollectionUtils.SortEntitiesByDistance
          A Comparator that sorts CombatEntityAPIs by distance from a Vector2f.
static class CollectionUtils.SortObjectivesByDistance
          A Comparator that sorts BattleObjectiveAPIs by distance from a Vector2f.
static class CollectionUtils.SortTokensByDistance
          A Comparator that sorts SectorEntityTokens by distance from a Vector2f.
 
Method Summary
static java.lang.String implode(java.util.Collection<java.lang.String> toImplode)
          Creates a comma-separated String from a Collection of Strings.
static java.lang.String implode(java.util.Collection<java.lang.String> toImplode, java.lang.String separator)
          Combines and separates a Collection of Strings.
static
<T> T
weightedRandom(java.util.Map<T,java.lang.Float> pickFrom)
          Returns a single item chosen via a weighted random from a Map.
static
<T> java.util.List<T>
weightedRandom(java.util.Map<T,java.lang.Float> pickFrom, int numToPick)
          Returns a List of items chosen via a weighted random from a Map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

weightedRandom

public static <T> java.util.List<T> weightedRandom(java.util.Map<T,java.lang.Float> pickFrom,
                                                   int numToPick)
Returns a List of items chosen via a weighted random from a Map.

Parameters:
pickFrom - A Map of items to choose from. The value is the weight, in float form, of that item being chosen.
numToPick - How many items to choose from pickFrom's keys.
Returns:
A List containing the subset of pickFrom chosen.
Since:
1.0

weightedRandom

public static <T> T weightedRandom(java.util.Map<T,java.lang.Float> pickFrom)
Returns a single item chosen via a weighted random from a Map.

Parameters:
pickFrom - A Map of items to choose from. The value is the weight, in float form, of that item being chosen.
Returns:
A single item chosen from pickFrom's keys.
Since:
1.0

implode

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

Parameters:
toImplode - A Collection of Strings to be combined.
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 java.lang.String implode(java.util.Collection<java.lang.String> toImplode)
Creates a comma-separated String from a Collection of Strings.

Parameters:
toImplode - A Collection of Strings to be combined.
Returns:
A single String consisting of toImplode's values separated with commas.
Since:
1.0
See Also:
implode(java.util.Collection, java.lang.String)

LazyLib