package com.levelup.java.exercises.beginner;

import java.util.Set;
import java.util.stream.Collectors;

import com.google.common.collect.Sets;

/**
 * Write a program that generate all combinations of a set returning only that satisfy a size of n.
 * 
 * @author Justin Musgrove
 * @see <a href='http://www.leveluplunch.com/java/exercises/combination-generator/'>Combination generator</a>
 */
public class CombinationGenerator {

	public static void main(String[] args) {

		Set<Integer> general = Sets.newHashSet(1, 2, 3, 4);

		Set<Integer> combinations = generateCombinations(general, 3);
		
		System.out.println(combinations);
	}

	/**
	 * Method will generate possible combinations of 
	 * elements based on parameters
	 * 
	 * @param from
	 * @param size
	 * 
	 * @return possible combinations
	 * 
	 */
	public static Set<Integer> generateCombinations(
			Set<Integer> from,
			int size) {

		Set<Set<Integer>> elements = Sets.powerSet(from);

		Set<Integer> possibleCombinations = elements.stream().filter(p -> p.size() == size)
				.collect(Collectors.toSet());

		return possibleCombinations;
	}

}

@@ -520,24 +520,28 @@
 , 3, 4);%0A%0A%09%09
+Set%3C
 Set%3CInteger%3E
@@ -540,16 +540,17 @@
 Integer%3E
+%3E
  combina
@@ -824,16 +824,20 @@
  static 
+Set%3C
 Set%3CInte
@@ -836,24 +836,25 @@
 Set%3CInteger%3E
+%3E
  generateCom
@@ -953,24 +953,28 @@
 t(from);%0A%0A%09%09
+Set%3C
 Set%3CInteger%3E
@@ -973,16 +973,17 @@
 Integer%3E
+%3E
  possibl

fix set of set