src/jdk.compiler/share/classes/com/sun/tools/sjavac/Util.java

Print this page
rev 2819 : imported patch my-classpath-deps-00

@@ -28,13 +28,17 @@
 import java.io.File;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.nio.file.Path;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 import java.util.StringTokenizer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * Utilities.
  *
  *  <p><b>This is NOT part of any supported API.

@@ -181,16 +185,35 @@
         union.addAll(s1);
         union.addAll(s2);
         return union;
     }
 
+    public static <E> Set<E> subtract(Set<? extends E> orig,
+                                      Set<? extends E> toSubtract) {
+        Set<E> difference = new HashSet<>(orig);
+        difference.removeAll(toSubtract);
+        return difference;
+    }
+
     public static String getStackTrace(Throwable t) {
         StringWriter sw = new StringWriter();
         t.printStackTrace(new PrintWriter(sw));
         return sw.toString();
     }
 
     // TODO: Remove when refactoring from java.io.File to java.nio.file.Path.
     public static File pathToFile(Path path) {
         return path == null ? null : path.toFile();
     }
+
+    public static <E> Set<E> intersection(Collection<? extends E> c1,
+                                          Collection<? extends E> c2) {
+        Set<E> intersection = new HashSet<E>(c1);
+        intersection.retainAll(c2);
+        return intersection;
+    }
+
+    public static <I, T> Map<I, T> indexBy(Collection<? extends T> c,
+                                           Function<? super T, ? extends I> indexFunction) {
+        return c.stream().collect(Collectors.toMap(indexFunction, o -> o));
+    }
 }