From 64c97807a20105644f604fe9b5263acdb63bd41d Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Fri, 28 Oct 2016 09:04:08 -0700 Subject: Fixing generics warnings --- util/src/org/aspectj/util/LangUtil.java | 4 +-- util/src/org/aspectj/util/PartialOrder.java | 42 ++++++++++++------------- util/testsrc/org/aspectj/util/FileUtilTest.java | 28 ++++++++--------- 3 files changed, 36 insertions(+), 38 deletions(-) (limited to 'util') diff --git a/util/src/org/aspectj/util/LangUtil.java b/util/src/org/aspectj/util/LangUtil.java index cf929b7b5..b0bf14522 100644 --- a/util/src/org/aspectj/util/LangUtil.java +++ b/util/src/org/aspectj/util/LangUtil.java @@ -929,11 +929,11 @@ public class LangUtil { * @param array the Object[] to convert (may be null) * @return the List corresponding to array (never null) */ - public static List arrayAsList(Object[] array) { + public static List arrayAsList(T[] array) { if ((null == array) || (1 > array.length)) { return Collections.emptyList(); } - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList<>(); 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 smallerObjects = new LinkedList(); - List biggerObjects = new LinkedList(); + private static class SortObject { + T object; + List> smallerObjects = new LinkedList>(); + List> biggerObjects = new LinkedList>(); - 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 o) { smallerObjects.remove(o); return hasNoSmallerObjects(); } - void addDirectedLinks(SortObject other) { + void addDirectedLinks(SortObject other) { int cmp = object.compareTo(other.object); if (cmp == 0) { return; @@ -86,18 +86,18 @@ public class PartialOrder { } } - private static void addNewPartialComparable(List graph, PartialComparable o) { - SortObject so = new SortObject(o); - for (Iterator i = graph.iterator(); i.hasNext();) { - SortObject other = i.next(); + private static void addNewPartialComparable(List> graph, T o) { + SortObject so = new SortObject(o); + for (Iterator> i = graph.iterator(); i.hasNext();) { + SortObject other = i.next(); so.addDirectedLinks(other); } graph.add(so); } - private static void removeFromGraph(List graph, SortObject o) { - for (Iterator i = graph.iterator(); i.hasNext();) { - SortObject other = i.next(); + private static void removeFromGraph(List> graph, SortObject o) { + for (Iterator> i = graph.iterator(); i.hasNext();) { + SortObject 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 List sort(List 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 sortList = new LinkedList(); // objects.size()); - for (Iterator i = objects.iterator(); i.hasNext();) { - addNewPartialComparable(sortList, (PartialComparable) i.next()); + List> sortList = new LinkedList>(); + for (Iterator 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 leastWithNoSmallers = null; - for (Iterator i = sortList.iterator(); i.hasNext();) { - SortObject so = (SortObject) i.next(); - // System.out.println(so); + for (SortObject 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 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 result = new ArrayList(); doDirPaths(dir, result); // if suffixes required, remove those without suffixes if (!LangUtil.isEmpty(suffixes)) { - for (ListIterator iter = result.listIterator(); iter.hasNext();) { + for (ListIterator 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 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 tempFiles; public FileUtilTest(String s) { super(s); - tempFiles = new ArrayList(); + tempFiles = new ArrayList(); } public void tearDown() { - for (ListIterator iter = tempFiles.listIterator(); iter.hasNext();) { + for (ListIterator 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 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 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 errors = new ArrayList<>(); final PrintStream errorSink = new PrintStream(System.err, true) { public void println(String error) { errors.add(error); } }; - List sourceList = new ArrayList(); + List 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 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 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()); -- cgit v1.2.3