diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-04-13 18:40:41 -0400 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-04-13 18:40:41 -0400 |
| commit | d4ca769e542b2489b1e23cfcbdc3a0b7275b87cd (patch) | |
| tree | 1653a7399f97fb0c63ce62e3f60fd830d5c37f70 /base/src/main/java/bjc/utils/funcutils/SetUtils.java | |
| parent | 2ac2e31a56ae59ee582e43a90c3495f86dd9ee7a (diff) | |
Cleanup pass
Cleanup pass to uniformize things
Diffstat (limited to 'base/src/main/java/bjc/utils/funcutils/SetUtils.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/funcutils/SetUtils.java | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/base/src/main/java/bjc/utils/funcutils/SetUtils.java b/base/src/main/java/bjc/utils/funcutils/SetUtils.java index d57ac00..83c191b 100644 --- a/base/src/main/java/bjc/utils/funcutils/SetUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/SetUtils.java @@ -7,17 +7,20 @@ import java.util.Set; /** * Various utility functions dealing with sets. + * * @author bjculkin * */ public class SetUtils { /** * Create a power-set (set of all subsets) of a given set. - * @param originalSet The set to create a power-set of. + * + * @param originalSet + * The set to create a power-set of. * @return The power-set of the set. */ public static <T> Set<Set<T>> powerSet(Set<T> originalSet) { - Set<Set<T>> sets = new HashSet<Set<T>>(); + Set<Set<T>> sets = new HashSet<>(); // Special-case empty input if (originalSet.isEmpty()) { @@ -25,18 +28,18 @@ public class SetUtils { return sets; } - List<T> list = new ArrayList<T>(originalSet); + List<T> list = new ArrayList<>(originalSet); // Add original set to list. T head = list.get(0); // Trim leading element from set. - Set<T> rest = new HashSet<T>(list.subList(1, list.size())); + Set<T> rest = new HashSet<>(list.subList(1, list.size())); Set<Set<T>> remSets = powerSet(rest); - + for (Set<T> set : remSets) { - Set<T> newSet = new HashSet<T>(); + Set<T> newSet = new HashSet<>(); // Create a new set with the removed element. newSet.add(head); @@ -51,14 +54,16 @@ public class SetUtils { /** * Utility method for set construction. - * @param elms The elements to stick in the set. + * + * @param elms + * The elements to stick in the set. * @return A set containing the specified elements. */ @SafeVarargs public static <T> Set<T> toSet(T... elms) { Set<T> set = new HashSet<>(); - for(T elm : elms) { + for (T elm : elms) { set.add(elm); } |
