diff options
author | Andy Clement <aclement@pivotal.io> | 2017-09-21 10:48:59 -0700 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2017-09-21 10:48:59 -0700 |
commit | 26712118bad08e60c66237e6aa2cfbd6f275cbbe (patch) | |
tree | 64531f485c94c9f6e7f1acb8506bf51cc8343cf1 /util | |
parent | 39b70af69b0b086f82da8ac032de5e5a5e0cdc45 (diff) | |
parent | 6d6738cfece6328027916681e67e54225531db38 (diff) | |
download | aspectj-26712118bad08e60c66237e6aa2cfbd6f275cbbe.tar.gz aspectj-26712118bad08e60c66237e6aa2cfbd6f275cbbe.zip |
Bring Java9 branch in line with 1.8.11 progress
Diffstat (limited to 'util')
-rw-r--r-- | util/src/org/aspectj/util/LangUtil.java | 4 | ||||
-rw-r--r-- | util/src/org/aspectj/util/PartialOrder.java | 42 | ||||
-rw-r--r-- | util/testsrc/org/aspectj/util/FileUtilTest.java | 28 |
3 files changed, 36 insertions, 38 deletions
diff --git a/util/src/org/aspectj/util/LangUtil.java b/util/src/org/aspectj/util/LangUtil.java index 3f913dc46..0f19124a9 100644 --- a/util/src/org/aspectj/util/LangUtil.java +++ b/util/src/org/aspectj/util/LangUtil.java @@ -940,11 +940,11 @@ public class LangUtil { * @param array the Object[] to convert (may be null) * @return the List corresponding to array (never null) */ - public static List<Object> arrayAsList(Object[] array) { + public static <T> List<T> arrayAsList(T[] array) { if ((null == array) || (1 > array.length)) { return Collections.emptyList(); } - ArrayList<Object> list = new ArrayList<Object>(); + ArrayList<T> list = new ArrayList<T>(); list.addAll(Arrays.asList(array)); return list; } diff --git a/util/src/org/aspectj/util/PartialOrder.java b/util/src/org/aspectj/util/PartialOrder.java index 5dd870205..8bb9f3b77 100644 --- a/util/src/org/aspectj/util/PartialOrder.java +++ b/util/src/org/aspectj/util/PartialOrder.java @@ -49,12 +49,12 @@ public class PartialOrder { public int fallbackCompareTo(Object other); } - private static class SortObject { - PartialComparable object; - List<SortObject> smallerObjects = new LinkedList<SortObject>(); - List<SortObject> biggerObjects = new LinkedList<SortObject>(); + private static class SortObject<T extends PartialComparable> { + T object; + List<SortObject<T>> smallerObjects = new LinkedList<SortObject<T>>(); + List<SortObject<T>> biggerObjects = new LinkedList<SortObject<T>>(); - public SortObject(PartialComparable o) { + public SortObject(T o) { object = o; } @@ -62,12 +62,12 @@ public class PartialOrder { return smallerObjects.size() == 0; } - boolean removeSmallerObject(SortObject o) { + boolean removeSmallerObject(SortObject<T> o) { smallerObjects.remove(o); return hasNoSmallerObjects(); } - void addDirectedLinks(SortObject other) { + void addDirectedLinks(SortObject<T> other) { int cmp = object.compareTo(other.object); if (cmp == 0) { return; @@ -86,18 +86,18 @@ public class PartialOrder { } } - private static void addNewPartialComparable(List<SortObject> graph, PartialComparable o) { - SortObject so = new SortObject(o); - for (Iterator<SortObject> i = graph.iterator(); i.hasNext();) { - SortObject other = i.next(); + private static <T extends PartialComparable> void addNewPartialComparable(List<SortObject<T>> graph, T o) { + SortObject<T> so = new SortObject<T>(o); + for (Iterator<SortObject<T>> i = graph.iterator(); i.hasNext();) { + SortObject<T> other = i.next(); so.addDirectedLinks(other); } graph.add(so); } - private static void removeFromGraph(List<SortObject> graph, SortObject o) { - for (Iterator<SortObject> i = graph.iterator(); i.hasNext();) { - SortObject other = i.next(); + private static <T extends PartialComparable> void removeFromGraph(List<SortObject<T>> graph, SortObject<T> o) { + for (Iterator<SortObject<T>> i = graph.iterator(); i.hasNext();) { + SortObject<T> other = i.next(); if (o == other) { i.remove(); @@ -114,7 +114,7 @@ public class PartialOrder { * @returns the same members as objects, but sorted according to their partial order. returns null if the objects are cyclical * */ - public static List sort(List objects) { + public static <T extends PartialComparable> List<T> sort(List<T> objects) { // lists of size 0 or 1 don't need any sorting if (objects.size() < 2) { return objects; @@ -124,9 +124,9 @@ public class PartialOrder { // ??? I don't like creating this data structure, but it does give good // ??? separation of concerns. - List<SortObject> sortList = new LinkedList<SortObject>(); // objects.size()); - for (Iterator i = objects.iterator(); i.hasNext();) { - addNewPartialComparable(sortList, (PartialComparable) i.next()); + List<SortObject<T>> sortList = new LinkedList<SortObject<T>>(); + for (Iterator<T> i = objects.iterator(); i.hasNext();) { + addNewPartialComparable(sortList, i.next()); } // System.out.println(sortList); @@ -140,11 +140,9 @@ public class PartialOrder { // System.out.println(sortList); // System.out.println("-->" + ret); - SortObject leastWithNoSmallers = null; + SortObject<T> leastWithNoSmallers = null; - for (Iterator i = sortList.iterator(); i.hasNext();) { - SortObject so = (SortObject) i.next(); - // System.out.println(so); + for (SortObject<T> so: sortList) { if (so.hasNoSmallerObjects()) { if (leastWithNoSmallers == null || so.object.fallbackCompareTo(leastWithNoSmallers.object) < 0) { leastWithNoSmallers = so; diff --git a/util/testsrc/org/aspectj/util/FileUtilTest.java b/util/testsrc/org/aspectj/util/FileUtilTest.java index 3f065278b..8ce18c700 100644 --- a/util/testsrc/org/aspectj/util/FileUtilTest.java +++ b/util/testsrc/org/aspectj/util/FileUtilTest.java @@ -62,7 +62,7 @@ public class FileUtilTest extends TestCase { * @throws AssertionFailedError if any names are not in dir */ public static String[] dirContains(File dir, final String[] filenames) { - final ArrayList sought = new ArrayList(LangUtil.arrayAsList(filenames)); + final ArrayList<String> sought = new ArrayList<>(LangUtil.arrayAsList(filenames)); FilenameFilter filter = new FilenameFilter() { public boolean accept(File d, String name) { return !sought.remove(name); @@ -129,11 +129,11 @@ public class FileUtilTest extends TestCase { * @return sorted String[] of all paths to all files under dir ending with one of the listed suffixes but not starting with "." */ public static String[] dirPaths(File dir, String[] suffixes) { - ArrayList result = new ArrayList(); + ArrayList<String> result = new ArrayList<String>(); doDirPaths(dir, result); // if suffixes required, remove those without suffixes if (!LangUtil.isEmpty(suffixes)) { - for (ListIterator iter = result.listIterator(); iter.hasNext();) { + for (ListIterator<String> iter = result.listIterator(); iter.hasNext();) { String path = iter.next().toString(); boolean hasSuffix = false; for (int i = 0; !hasSuffix && (i < suffixes.length); i++) { @@ -161,7 +161,7 @@ public class FileUtilTest extends TestCase { * @param dir the File to read - ignored if null, not a directory, or has "CVS" in its path * @param useSuffix if true, then use dir as suffix to path */ - private static void doDirPaths(File dir, ArrayList paths) { + private static void doDirPaths(File dir, ArrayList<String> paths) { if ((null == dir) || !dir.canRead() || (-1 != dir.getPath().indexOf("CVS"))) { return; } @@ -188,15 +188,15 @@ public class FileUtilTest extends TestCase { } /** List of File files or directories to delete when exiting */ - final ArrayList tempFiles; + final ArrayList<File> tempFiles; public FileUtilTest(String s) { super(s); - tempFiles = new ArrayList(); + tempFiles = new ArrayList<File>(); } public void tearDown() { - for (ListIterator iter = tempFiles.listIterator(); iter.hasNext();) { + for (ListIterator<File> iter = tempFiles.listIterator(); iter.hasNext();) { File dir = (File) iter.next(); log("removing " + dir); FileUtil.deleteContents(dir); @@ -236,7 +236,7 @@ public class FileUtilTest extends TestCase { public void testCopyFiles() { // bad input - Class iaxClass = IllegalArgumentException.class; + Class<?> iaxClass = IllegalArgumentException.class; checkCopyFiles(null, null, iaxClass, false); @@ -388,7 +388,7 @@ public class FileUtilTest extends TestCase { } public void testRandomFileString() { - ArrayList results = new ArrayList(); + ArrayList<String> results = new ArrayList<>(); for (int i = 0; i < 1000; i++) { String s = FileUtil.randomFileString(); if (results.contains(s)) { @@ -469,7 +469,7 @@ public class FileUtilTest extends TestCase { } }; for (int i = 0; i < 10; i++) { - List result = FileUtil.lineSeek("" + i, sourceList, true, errorSink); + List<String> result = FileUtil.lineSeek("" + i, sourceList, true, errorSink); assertEquals(2, result.size()); assertEquals(path + ":1:" + i, result.get(0)); assertEquals(path + ":2:" + i, result.get(1)); @@ -502,19 +502,19 @@ public class FileUtilTest extends TestCase { tempFiles.add(file); } // now test - final ArrayList errors = new ArrayList(); + final ArrayList<String> errors = new ArrayList<>(); final PrintStream errorSink = new PrintStream(System.err, true) { public void println(String error) { errors.add(error); } }; - List sourceList = new ArrayList(); + List<String> sourceList = new ArrayList<>(); sourceList.addAll(Arrays.asList(sources)); sourceList = Collections.unmodifiableList(sourceList); for (int k = 0; k < sources.length; k++) { - List result = FileUtil.lineSeek("" + k, sourceList, true, errorSink); + List<String> result = FileUtil.lineSeek("" + k, sourceList, true, errorSink); // number k found in every other line of every file at index k - Iterator iter = result.iterator(); + Iterator<String> iter = result.iterator(); for (int i = 0; i < MAX; i++) { // for each file for (int j = 1; j < (MAX + 1); j++) { // for every other line assertTrue(iter.hasNext()); |