Example usage for com.google.common.collect Collections2 orderedPermutations

List of usage examples for com.google.common.collect Collections2 orderedPermutations

Introduction

In this page you can find the example usage for com.google.common.collect Collections2 orderedPermutations.

Prototype

@Beta
public static <E extends Comparable<? super E>> Collection<List<E>> orderedPermutations(Iterable<E> elements) 

Source Link

Document

Returns a Collection of all the permutations of the specified Iterable .

Usage

From source file:org.cakeframework.test.container.tck.RunState.java

/**
 * Returns a parameterized combination of all run states.
 * /*from w ww.j  a va2s .  co m*/
 * @return
 */
public static Collection<Object[]> getAllStateCombinations() {
    // Test all combinations
    Collection<List<RunState>> subSets = Collections2.orderedPermutations(
            Arrays.asList(RunState.INITIALIZED, RunState.STARTING, RunState.RUNNING, RunState.SHUTDOWN));

    ArrayList<Object[]> l = new ArrayList<>();
    HashSet<Collection<RunState>> lhs = new HashSet<>();
    for (int i = 1; i <= 4; i++) {
        for (List<RunState> li : subSets) {
            Collection<RunState> c = new TreeSet<>(li.subList(0, i));
            if (lhs.add(c)) {
                l.add(new Object[] { c });
            }
        }
    }
    assertEquals(15, l.size());
    return l;
}