This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |