View GuiceJUnitRunner.java
import com.google.inject.AbstractModule; | |
import com.google.inject.Guice; | |
import com.google.inject.Injector; | |
import org.junit.runners.BlockJUnit4ClassRunner; | |
import org.junit.runners.model.InitializationError; | |
public class GuiceJUnitRunner extends BlockJUnit4ClassRunner { | |
public GuiceJUnitRunner(Class<?> klass) throws InitializationError { | |
super(klass); |
View Permutations.java
public class Permutations { | |
public static <T> Stream<Stream<T>> of(final List<T> items) { | |
return IntStream.range(0, factorial(items.size())).mapToObj(i -> permutation(i, items).stream()); | |
} | |
private static int factorial(final int num) { | |
return IntStream.rangeClosed(2, num).reduce(1, (x, y) -> x * y); | |
} |
View Pair.java
public class Pair<L, R> { | |
private L left; | |
private R right; | |
public Pair(L left, R right) { | |
if (left == null) { throw new RuntimeException("Left must not be null"); } | |
if (right == null) { throw new RuntimeException("Right must not be null"); } | |
this.left = left; | |
this.right = right; |
View Pairs.java
public class Pairs { | |
/** | |
* Create a list of pairs of the given items. | |
* e.g. ["A", "B", "C", "D"] will return ["A:B", "A:C", "A:D", "B:C", "B:D", "C:D"] | |
* @param items the items to create the pair | |
* @param <T> type of the items | |
* @return a list of pairs | |
*/ | |
public static <T> List<Pair<T, T>> of(final List<T> items) { |