changeset 140:6378e05a5c34

7902204: Follow-up generification and misc, part 1 Reviewed-by: jjg
author dbessono
date Tue, 10 Jul 2018 20:50:35 +0100
parents d3caa1087194
children 3988a50a0d5d
files src/com/sun/interview/ChoiceArrayQuestion.java src/com/sun/interview/ChoiceQuestion.java src/com/sun/interview/FileQuestion.java src/com/sun/interview/Help.java src/com/sun/interview/Interview.java src/com/sun/interview/InterviewSet.java src/com/sun/interview/wizard/PathPanel.java src/com/sun/javatest/ExcludeList.java src/com/sun/javatest/finder/BinaryTestFinder.java
diffstat 9 files changed, 81 insertions(+), 120 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/sun/interview/ChoiceArrayQuestion.java	Mon Jul 09 17:03:35 2018 +0100
+++ b/src/com/sun/interview/ChoiceArrayQuestion.java	Tue Jul 10 20:50:35 2018 +0100
@@ -105,8 +105,8 @@
         if (choices == null)
             throw new NullPointerException();
 
-        for (int i = 0; i < choices.length; i++) {
-            if (choices[i] == null)
+        for (String choice : choices) {
+            if (choice == null)
                 throw new NullPointerException();
         }
 
--- a/src/com/sun/interview/ChoiceQuestion.java	Mon Jul 09 17:03:35 2018 +0100
+++ b/src/com/sun/interview/ChoiceQuestion.java	Tue Jul 10 20:50:35 2018 +0100
@@ -138,9 +138,9 @@
                 interview.updatePath(this);
                 interview.setEdited(true);
             } else {
-                for (int i = 0; i < choices.length; i++) {
-                    if (value.equals(choices[i])) {
-                        value = choices[i];
+                for (String choice : choices) {
+                    if (value.equals(choice)) {
+                        value = choice;
                         return;
                     }
                 }
@@ -304,9 +304,9 @@
         }
         else {
             // try and canonicalize newValue to one of the specified choices
-            for (int i = 0; i < choices.length; i++) {
-                if (newValue.equals(choices[i])) {
-                    newValue = choices[i];
+            for (String choice : choices) {
+                if (newValue.equals(choice)) {
+                    newValue = choice;
                     break;
                 }
             }
@@ -321,8 +321,8 @@
 
     public boolean isValueValid() {
         // value is valid if it matches one of the specified choices
-        for (int i = 0; i < choices.length; i++) {
-            if (value == null ? choices[i] == null : value.equals(choices[i]))
+        for (String choice : choices) {
+            if (value == null ? choice == null : value.equals(choice))
                 return true;
         }
         return false;
--- a/src/com/sun/interview/FileQuestion.java	Mon Jul 09 17:03:35 2018 +0100
+++ b/src/com/sun/interview/FileQuestion.java	Tue Jul 10 20:50:35 2018 +0100
@@ -67,8 +67,8 @@
      */
     public void setSuggestions(File[] newSuggestions) {
         if (newSuggestions != null) {
-            for (int i = 0; i < newSuggestions.length; i++) {
-                if (newSuggestions[i] == null)
+            for (File newSuggestion : newSuggestions) {
+                if (newSuggestion == null)
                     throw new IllegalArgumentException();
             }
         }
--- a/src/com/sun/interview/Help.java	Mon Jul 09 17:03:35 2018 +0100
+++ b/src/com/sun/interview/Help.java	Tue Jul 10 20:50:35 2018 +0100
@@ -98,7 +98,7 @@
 
         HelpSet hs = getHelpSet(i);
         if (hs != null) {
-            Map m = hs.getLocalMap();
+            Map<String, URL> m = hs.getLocalMap();
             if (m != null) {
                 helpId = HelpID.create(key, hs);
                 //System.err.println("Q: FOUND int:" + i.getTag() + " key:" + key + " helpId:" + helpId);
--- a/src/com/sun/interview/Interview.java	Mon Jul 09 17:03:35 2018 +0100
+++ b/src/com/sun/interview/Interview.java	Tue Jul 10 20:50:35 2018 +0100
@@ -535,7 +535,7 @@
         return null;
     }
 
-    Set getInterviews() {
+    Set<Interview> getInterviews() {
         Set<Interview> s = new HashSet<>();
         getInterviews0(s);
         return s;
@@ -1168,8 +1168,7 @@
             Question q = (Question) (iter.next());
             Checklist.Item[] items = q.getChecklistItems();
             if (items != null) {
-                for (int i = 0; i < items.length; i++)
-                    c.add(items[i]);
+                for (Checklist.Item item : items) c.add(item);
             }
         }
         return c;
@@ -1262,7 +1261,7 @@
         if (allMarkers == null)
             return;
 
-        Set markersForName = allMarkers.get(name);
+        Set<Question> markersForName = allMarkers.get(name);
         if (markersForName == null)
             return;
 
@@ -1335,15 +1334,14 @@
         if (allMarkers == null) // no markers at all
             return;
 
-        Set markersForName = allMarkers.get(name);
+        Set<Question> markersForName = allMarkers.get(name);
         if (markersForName == null) // no markers for this name
             return;
 
         updateEnabled = false;
         Question oldCurrentQuestion = getCurrentQuestion();
 
-        for (Iterator iter = markersForName.iterator(); iter.hasNext(); ) {
-            Question q = (Question) (iter.next());
+        for (Question q : markersForName) {
             q.clear();
         }
 
@@ -1410,15 +1408,13 @@
             return;
 
         int i = 0;
-        for (Iterator<Map.Entry<String, Set<Question>>> iter = allMarkers.entrySet().iterator(); iter.hasNext(); ) {
-            Map.Entry<String, Set<Question>> e = iter.next();
+        for (Map.Entry<String, Set<Question>> e : allMarkers.entrySet()) {
             String name = e.getKey();
             Set<Question> markersForName = e.getValue();
             if (name != null)
                 data.put(MARKERS_PREF + i + ".name", name);
             StringBuffer sb = new StringBuffer();
-            for (Iterator<Question> qIter = markersForName.iterator(); qIter.hasNext(); ) {
-                Question q = qIter.next();
+            for (Question q : markersForName) {
                 if (sb.length() > 0)
                     sb.append('\n');
                 sb.append(q.getTag());
@@ -1456,8 +1452,7 @@
      */
     public void clear() {
         updateEnabled = false;
-        for (Iterator<Question> iter = allQuestions.values().iterator(); iter.hasNext(); ) {
-            Question q = iter.next();
+        for (Question q : allQuestions.values()) {
             q.clear();
         }
 
@@ -1512,13 +1507,11 @@
 
         // clear all the answers in this interview before loading an
         // responses from the archive
-        for (Iterator<Question> iter = allQuestions.values().iterator(); iter.hasNext(); ) {
-            Question q = iter.next();
+        for (Question q : allQuestions.values()) {
             q.clear();
         }
 
-        for (Iterator<Question> iter = allQuestions.values().iterator(); iter.hasNext(); ) {
-            Question q = iter.next();
+        for (Question q : allQuestions.values()) {
             q.load(data);
         }
 
@@ -1568,27 +1561,21 @@
             writeLocale(data);
 
             if (extraValues != null && extraValues.size() > 0) {
-                Set keys = getPropertyKeys();
-                Iterator it = keys.iterator();
-                while (it.hasNext()) {
-                    Object key = it.next();
+                Set<String> keys = getPropertyKeys();
+                for (String key : keys) {
                     data.put(EXTERNAL_PREF + key, extraValues.get(key));
                 }   // while
             }
 
             if (templateValues != null && templateValues.size() > 0) {
-                Set keys = templateValues.keySet();
-                Iterator it = keys.iterator();
-                while (it.hasNext()) {
-                    String key = (String)it.next();
+                Set<String> keys = templateValues.keySet();
+                for (String key : keys) {
                     data.put(TEMPLATE_PREF + key, retrieveTemplateProperty(key));
                 }   // while
             }
 
         }
-
-        for (Iterator<Question> iter = allQuestions.values().iterator(); iter.hasNext(); ) {
-            Question q = iter.next();
+        for (Question q : allQuestions.values()) {
             try {
                 q.save(data);
             }
@@ -1598,8 +1585,7 @@
             }
         }
 
-        for (int i = 0; i < children.size(); i++) {
-            Interview child = children.elementAt(i);
+        for (Interview child : children) {
             child.save(data);
         }
 
@@ -1765,35 +1751,32 @@
             export0(data, hiddenPath, true);
     }
 
-    private void export0(Map<String, String> data, ArrayList<Question> path, boolean processHidden) {
-        for (int i = 0; i < path.size(); i++) {
+    private void export0(Map<String, String> data, ArrayList<Question> paths, boolean processHidden) {
+        for (Question path : paths) {
             try {
-                if (path.get(i) instanceof InterviewQuestion) {
+                if (path instanceof InterviewQuestion) {
                     if (!processHidden)
-                        ((InterviewQuestion)path.get(i)).getTargetInterview().export(data);
+                        ((InterviewQuestion) path).getTargetInterview().export(data);
                     else
                         continue;
+                } else {
+                    path.export(data);
                 }
-                else {
-                    path.get(i).export(data);
+            } catch (RuntimeException e) {
+                switch (exportIgnoreExceptionPolicy) {
+                    case EXPORT_IGNORE_ALL_EXCEPTIONS:
+                    case EXPORT_IGNORE_RUNTIME_EXCEPTIONS:
+                        break;
+                    case EXPORT_IGNORE_NO_EXCEPTIONS:
+                        throw e;
                 }
-            }
-            catch (RuntimeException e) {
+            } catch (Error e) {
                 switch (exportIgnoreExceptionPolicy) {
-                case EXPORT_IGNORE_ALL_EXCEPTIONS:
-                case EXPORT_IGNORE_RUNTIME_EXCEPTIONS:
-                    break;
-                case EXPORT_IGNORE_NO_EXCEPTIONS:
-                    throw e;
-                }
-            }
-            catch (Error e) {
-                switch (exportIgnoreExceptionPolicy) {
-                case EXPORT_IGNORE_ALL_EXCEPTIONS:
-                    break;
-                case EXPORT_IGNORE_RUNTIME_EXCEPTIONS:
-                case EXPORT_IGNORE_NO_EXCEPTIONS:
-                    throw e;
+                    case EXPORT_IGNORE_ALL_EXCEPTIONS:
+                        break;
+                    case EXPORT_IGNORE_RUNTIME_EXCEPTIONS:
+                    case EXPORT_IGNORE_NO_EXCEPTIONS:
+                        throw e;
                 }
             }
         }
@@ -1902,8 +1885,8 @@
         if (o == null)
             throw new NullPointerException();
 
-        for (int i = 0; i < observers.length; i++) {
-            if (observers[i] == o) {
+        for (Observer observer : observers) {
+            if (observer == o) {
                 return true;
             }
         }
@@ -1917,8 +1900,7 @@
     }
 
     private void notifyPathUpdated() {
-        for (int i = 0; i < observers.length; i++)
-            observers[i].pathUpdated();
+        for (Observer observer : observers) observer.pathUpdated();
     }
 
     private Observer[] observers = new Observer[0];
@@ -1953,16 +1935,14 @@
         // update the tags for the questions in the interview
         // and rebuild the tag map
         Map<String, Question> newAllQuestions = new LinkedHashMap<>();
-        for (Iterator<Question> iter = allQuestions.values().iterator(); iter.hasNext(); ) {
-            Question q = iter.next();
+        for (Question q : allQuestions.values()) {
             q.updateTag();
             newAllQuestions.put(q.getTag(), q);
         }
         allQuestions = newAllQuestions;
 
         // recursively update children
-        for (Iterator iter = children.iterator(); iter.hasNext(); ) {
-            Interview i = (Interview) (iter.next());
+        for (Interview i : children) {
             i.updateTags();
         }
     }
@@ -2182,7 +2162,7 @@
      * @see #storeProperty
      * @see #retrieveProperty
      */
-    public Set getPropertyKeys() {
+    public Set<String> getPropertyKeys() {
         if (getParent() != null)
             return parent.getPropertyKeys();
         else {
@@ -2216,14 +2196,12 @@
             extraValues.clear();
         }
 
-        Set keys = data.keySet();
-        Iterator it = keys.iterator();
+        Set<String> keys = data.keySet();
 
-        while (it.hasNext()) {
+        for (String key : keys) {
             // look for special external value keys
             // should consider removing it from data, is it safe to alter
             // that object?
-            String key = (String)(it.next());
             if (key.startsWith(EXTERNAL_PREF)) {
                 if (extraValues == null)
                     extraValues = new HashMap<>();
@@ -2242,11 +2220,8 @@
             templateValues.clear();
         }
 
-        Set keys = data.keySet();
-        Iterator it = keys.iterator();
-
-        while (it.hasNext()) {
-            String key = (String)(it.next());
+        Set<String> keys = data.keySet();
+        for (String key : keys) {
             if (key.startsWith(TEMPLATE_PREF)) {
                 ensureTemValuesInitialized();
                 String val = data.get(key);
@@ -2258,8 +2233,7 @@
 
     public void propagateTemplateForAll() {
         ensureTemValuesInitialized();
-        for (Iterator iter = getAllQuestions().values().iterator(); iter.hasNext(); ) {
-            Question q = (Question) (iter.next());
+        for (Question q : getAllQuestions().values()) {
                 q.load(templateValues);
         }
     }
@@ -2376,12 +2350,9 @@
     }
 
     private void verifyPredictPath(){
-        for (Object o : getInterviews()){
-            if (o instanceof Interview){
-                Interview i = (Interview) o;
-                if (i.path != null && i.currIndex >= i.path.size()){
-                    i.currIndex = i.path.size()-1;
-                }
+        for (Interview i : getInterviews()) {
+            if (i.path != null && i.currIndex >= i.path.size()) {
+                i.currIndex = i.path.size() - 1;
             }
         }
     }
--- a/src/com/sun/interview/InterviewSet.java	Mon Jul 09 17:03:35 2018 +0100
+++ b/src/com/sun/interview/InterviewSet.java	Tue Jul 10 20:50:35 2018 +0100
@@ -177,14 +177,12 @@
         List<Interview> list = new ArrayList<>();
         Set<Interview> cycleSet = new HashSet<>();
 
-        for (Iterator iter = children.iterator(); iter.hasNext(); ) {
-            Interview child = (Interview) (iter.next());
+        for (Interview child : children) {
             if (!list.contains(child))
                 addToList(list, child, cycleSet);
         }
 
-        for (Iterator iter = list.iterator(); iter.hasNext(); ) {
-            Interview i = (Interview) (iter.next());
+        for (Interview i : list) {
             System.err.println(i.getTag() + " " + i);
         }
 
--- a/src/com/sun/interview/wizard/PathPanel.java	Mon Jul 09 17:03:35 2018 +0100
+++ b/src/com/sun/interview/wizard/PathPanel.java	Tue Jul 10 20:50:35 2018 +0100
@@ -282,8 +282,7 @@
         //----- state support for menus -----------------------------
 
         boolean isQuestionVisible(Question q) {
-            for (int i = 0; i < currEntries.length; i++) {
-                Object e = currEntries[i];
+            for (Object e : currEntries) {
                 if (e instanceof Question && e == q)
                     return true;
                 else if (e instanceof List && ((List) e).contains(q))
--- a/src/com/sun/javatest/ExcludeList.java	Mon Jul 09 17:03:35 2018 +0100
+++ b/src/com/sun/javatest/ExcludeList.java	Tue Jul 10 20:50:35 2018 +0100
@@ -137,8 +137,8 @@
         throws FileNotFoundException, IOException, Fault
     {
         setStrictModeEnabled(strict);
-        for (int i = 0; i < files.length; i++) {
-            ExcludeList et = new ExcludeList(files[i], strict);
+        for (File file : files) {
+            ExcludeList et = new ExcludeList(file, strict);
             merge(et);
         }
     }
@@ -370,8 +370,7 @@
         }
         else {
             Entry[] entries = (Entry[])o;
-            for (int i = 0; i < entries.length; i++) {
-                Entry e = entries[i];
+            for (Entry e : entries) {
                 if (isInList(e.testCase, testCase))
                     return e;
             }
@@ -416,11 +415,10 @@
                     String[] bugIdStrings = otherEntry.bugIdStrings;
                     String[] platforms = otherEntry.platforms;
                     String synopsis = otherEntry.synopsis;
-                    Entry[] curr = (Entry[])o;
-                    for (int i = 0; i < curr.length; i++) {
-                        bugIdStrings = mergeBugIds(bugIdStrings, curr[i].bugIdStrings);
-                        platforms = mergePlatforms(platforms, curr[i].platforms);
-                        synopsis = mergeSynopsis(synopsis, curr[i].synopsis);
+                    for (Entry entry : (Entry[])o) {
+                        bugIdStrings = mergeBugIds(bugIdStrings, entry.bugIdStrings);
+                        platforms = mergePlatforms(platforms, entry.platforms);
+                        synopsis = mergeSynopsis(synopsis, entry.synopsis);
                     }
                     table.put(key, new Entry(otherEntry.relativeURL, null,
                                              bugIdStrings, platforms, synopsis));
@@ -512,10 +510,9 @@
     public int size() {
         // ouch, this is now expensive to compute
         int n = 0;
-        for (Iterator i = table.values().iterator(); i.hasNext(); ) {
-            Object o = i.next();
+        for (Object o : table.values()) {
             if (o instanceof Entry[])
-                n += ((Entry[])o).length;
+                n += ((Entry[]) o).length;
             else
                 n++;
         }
@@ -534,21 +531,18 @@
      * and @link(Entry)[], depending on the <code>group</code>
      * parameter.
      */
-    public Iterator getIterator(boolean group) {
+    public Iterator<Object> getIterator(boolean group) {
         if (group)
             return table.values().iterator();
         else {
             // flatten the enumeration into a vector, then
             // enumerate that
             Vector<Object> v = new Vector<>(table.size());
-            for (Iterator iter = table.values().iterator(); iter.hasNext(); ) {
-                Object o = iter.next();
+            for (Object o : table.values()) {
                 if (o instanceof Entry)
                     v.addElement(o);
                 else {
-                    Entry[] entries = (Entry[])o;
-                    for (int i = 0; i < entries.length; i++)
-                        v.addElement(entries[i]);
+                    for (Entry entry : (Entry[]) o) v.addElement(entry);
                 }
             }
             return v.iterator();
@@ -606,8 +600,7 @@
             out.write("### title " + title);
             out.newLine();
         }
-        for (Iterator iter = entries.iterator(); iter.hasNext(); ) {
-            Entry e = (Entry) (iter.next());
+        for (Entry e : entries) {
             if (e.testCase == null)
                 write(out, e.relativeURL, maxURLWidth + 2);
             else
--- a/src/com/sun/javatest/finder/BinaryTestFinder.java	Mon Jul 09 17:03:35 2018 +0100
+++ b/src/com/sun/javatest/finder/BinaryTestFinder.java	Tue Jul 10 20:50:35 2018 +0100
@@ -211,9 +211,9 @@
             // simulate files to be scanned for child nodes
             TestTree.Node[] children = node.children;
             if (children != null) {
-                for (int i = 0; i < children.length; i++) {
-                    File f = (relPath.length() == 0 ? new File(children[i].name) :
-                                            new File(relPath, children[i].name));
+                for (TestTree.Node child : children) {
+                    File f = (relPath.length() == 0 ? new File(child.name) :
+                            new File(relPath, child.name));
                     foundFile(f);
                 }
             }