@SuppressWarnings("unchecked") @Test public void testPowerSet() { powerSet(null); powerSet(Collections.EMPTY_SET); Set<Integer> set = new HashSet<>(); set.add(1); set.add(2); set.add(3); powerSet(set); }
public static void powerSet(Set<Integer> set) { if (set == null) { LOGGER.info("Null input."); return; } LOGGER.info("{}.", set.toString()); LOGGER.info("{" + "Ø" + "}"); final Integer[] elements = set.toArray(new Integer[] {}); final int numElements = elements.length; final StringBuilder identitySet = new StringBuilder(); for (int currentIdx = 0; currentIdx < numElements; currentIdx++) { int currentElement = elements[currentIdx]; identitySet.append(currentElement); if (currentIdx != numElements - 1) { identitySet.append(", "); } for (int lookAheadIdx = currentIdx + 1; lookAheadIdx < numElements; lookAheadIdx++) { int lookAheadElement = elements[lookAheadIdx]; LOGGER.info("{" + "{}, {}" + "}.", currentElement, lookAheadElement); } } LOGGER.info("{" + "{}" + "}.", identitySet.toString()); }
PracticeQuestionsCh5 { public static void powerSet(Set<Integer> set) { if (set == null) { LOGGER.info("Null input."); return; } LOGGER.info("{}.", set.toString()); LOGGER.info("{" + "Ø" + "}"); final Integer[] elements = set.toArray(new Integer[] {}); final int numElements = elements.length; final StringBuilder identitySet = new StringBuilder(); for (int currentIdx = 0; currentIdx < numElements; currentIdx++) { int currentElement = elements[currentIdx]; identitySet.append(currentElement); if (currentIdx != numElements - 1) { identitySet.append(", "); } for (int lookAheadIdx = currentIdx + 1; lookAheadIdx < numElements; lookAheadIdx++) { int lookAheadElement = elements[lookAheadIdx]; LOGGER.info("{" + "{}, {}" + "}.", currentElement, lookAheadElement); } } LOGGER.info("{" + "{}" + "}.", identitySet.toString()); } }
PracticeQuestionsCh5 { public static void powerSet(Set<Integer> set) { if (set == null) { LOGGER.info("Null input."); return; } LOGGER.info("{}.", set.toString()); LOGGER.info("{" + "Ø" + "}"); final Integer[] elements = set.toArray(new Integer[] {}); final int numElements = elements.length; final StringBuilder identitySet = new StringBuilder(); for (int currentIdx = 0; currentIdx < numElements; currentIdx++) { int currentElement = elements[currentIdx]; identitySet.append(currentElement); if (currentIdx != numElements - 1) { identitySet.append(", "); } for (int lookAheadIdx = currentIdx + 1; lookAheadIdx < numElements; lookAheadIdx++) { int lookAheadElement = elements[lookAheadIdx]; LOGGER.info("{" + "{}, {}" + "}.", currentElement, lookAheadElement); } } LOGGER.info("{" + "{}" + "}.", identitySet.toString()); }  }
PracticeQuestionsCh5 { public static void powerSet(Set<Integer> set) { if (set == null) { LOGGER.info("Null input."); return; } LOGGER.info("{}.", set.toString()); LOGGER.info("{" + "Ø" + "}"); final Integer[] elements = set.toArray(new Integer[] {}); final int numElements = elements.length; final StringBuilder identitySet = new StringBuilder(); for (int currentIdx = 0; currentIdx < numElements; currentIdx++) { int currentElement = elements[currentIdx]; identitySet.append(currentElement); if (currentIdx != numElements - 1) { identitySet.append(", "); } for (int lookAheadIdx = currentIdx + 1; lookAheadIdx < numElements; lookAheadIdx++) { int lookAheadElement = elements[lookAheadIdx]; LOGGER.info("{" + "{}, {}" + "}.", currentElement, lookAheadElement); } } LOGGER.info("{" + "{}" + "}.", identitySet.toString()); }  static long[] computeParities(final long[] input); static long swapBits(final long x, final int i, final int j); static void powerSet(Set<Integer> set); static int stringToInt(String s); static String changeBase(String s, int b1, int b2); }
PracticeQuestionsCh5 { public static void powerSet(Set<Integer> set) { if (set == null) { LOGGER.info("Null input."); return; } LOGGER.info("{}.", set.toString()); LOGGER.info("{" + "Ø" + "}"); final Integer[] elements = set.toArray(new Integer[] {}); final int numElements = elements.length; final StringBuilder identitySet = new StringBuilder(); for (int currentIdx = 0; currentIdx < numElements; currentIdx++) { int currentElement = elements[currentIdx]; identitySet.append(currentElement); if (currentIdx != numElements - 1) { identitySet.append(", "); } for (int lookAheadIdx = currentIdx + 1; lookAheadIdx < numElements; lookAheadIdx++) { int lookAheadElement = elements[lookAheadIdx]; LOGGER.info("{" + "{}, {}" + "}.", currentElement, lookAheadElement); } } LOGGER.info("{" + "{}" + "}.", identitySet.toString()); }  static long[] computeParities(final long[] input); static long swapBits(final long x, final int i, final int j); static void powerSet(Set<Integer> set); static int stringToInt(String s); static String changeBase(String s, int b1, int b2); static final Logger LOGGER; }