public class EntityCombinator extends Object
hasNext
always return false.
2. For a List of empty Lists, hasNext
always return false.
3. For a single List, the next
method returns various combination of
input elements. For example for a list of "1, 2, 3, 4" selecting 3 at
a time, the lists returned by next
is:
{1, 2, 3}, {1, 2, 4}, {1, 3, 4} and {2, 3, 4}
4. For more than one non-empty lists, the combinations returned are all
possible combinations, but elements restricted to each individual list. For
example with following two lists:
{1, 2, 3} and {4, 5, 6}
choosing 2 at a time from each list, following list will be returned:
{{1, 2}, {4, 5}}
{{1, 2}, {4, 6}}
{{1, 2}, {5, 6}}
{{1, 3}, {4, 5}}
{{1, 3}, {4, 6}}
{{1, 3}, {5, 6}}
{{2, 3}, {4, 5}}
{{2, 3}, {4, 6}}
{{2, 3}, {5, 6}}Constructor and Description |
---|
EntityCombinator() |
Modifier and Type | Method and Description |
---|---|
static <T> Iterable<List<T>> |
multiEntityListBalancedIterable(List<List<T>> entities,
int totalEntitiesToSelect)
The method picks totalEntitiesToSelect elements from entities and tries to keep the skew of
min/max number of elements from each list to 1.
|
static <T> Iterable<List<T>> |
multiEntityListIterable(LinkedHashMap<List<T>,Integer> entitiesWithCount)
Method to create an iterator over multiple list of entities.
|
static <T> Iterable<List<T>> |
singleEntityListIterable(List<T> entities,
int count)
Method to create an iterator that permutes all combination of elements in
a List.
|
public static <T> Iterable<List<T>> multiEntityListIterable(LinkedHashMap<List<T>,Integer> entitiesWithCount)
T
- Type of entity, for e.g. a Broker, Rack, Cell etc.public static <T> Iterable<List<T>> multiEntityListBalancedIterable(List<List<T>> entities, int totalEntitiesToSelect)
entities
- A list containing list of entities from which to pick totalEntitiesToSelect items.totalEntitiesToSelect
- Total number of items to select. The items selected from each list in
the entities
argument are evenly divided.next
will return one possible combination.public static <T> Iterable<List<T>> singleEntityListIterable(List<T> entities, int count)
SingleEntityListIterator
entities
- List of entities whose combinations need to be returned.count
- Number of elements to pick up from the list. It needs to be
greater than 0 and less than or equal to list size.