changeset 142:05dd6e13d1f1

7902215: Follow-up generification and misc, part 3 Reviewed-by: jjg
author dbessono
date Thu, 12 Jul 2018 23:54:08 +0100
parents 3988a50a0d5d
children 46705078a032
files src/com/sun/interview/Interview.java src/com/sun/javatest/InterviewPropagator.java src/com/sun/javatest/TestDescription.java src/com/sun/javatest/TestEnvironment.java src/com/sun/javatest/util/Properties.java
diffstat 5 files changed, 48 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/sun/interview/Interview.java	Wed Jul 11 20:44:47 2018 +0100
+++ b/src/com/sun/interview/Interview.java	Thu Jul 12 23:54:08 2018 +0100
@@ -280,7 +280,7 @@
     {
         // name is not null
         if (!name.equals(bundleName)) {
-            Class c = getClass();
+            Class<?> c = getClass();
             final ClassLoader cl = c.getClassLoader();
             final String rn;
             if (name.startsWith("/"))
@@ -429,7 +429,7 @@
      */
     private static HelpSetFactory createHelpFactory() {
         try {
-            Class factoryClass = Class.forName("com.sun.interview.JavaHelpFactory");
+            Class<?> factoryClass = Class.forName("com.sun.interview.JavaHelpFactory");
             return (HelpSetFactory) factoryClass.newInstance();
         } catch (ClassNotFoundException e) {
             return HelpSetFactory.DEFAULT;
@@ -1000,7 +1000,7 @@
      * @return an Iterator for the questions on the current path
      * @see #iteratePathToCurrent
      */
-    public Iterator iteratePath(boolean flattenNestedInterviews) {
+    public Iterator<Question> iteratePath(boolean flattenNestedInterviews) {
         Vector<Question> v = new Vector<>();
         iteratePath0(v, flattenNestedInterviews, true, true);
         return v.iterator();
@@ -1017,7 +1017,7 @@
      * up to and including the current question
      * @see #iteratePath
      */
-    public Iterator iteratePathToCurrent(boolean flattenNestedInterviews) {
+    public Iterator<Question> iteratePathToCurrent(boolean flattenNestedInterviews) {
         Vector<Question> v = new Vector<>();
         iteratePath0(v, flattenNestedInterviews, false, true);
         return v.iterator();
@@ -1103,7 +1103,7 @@
      * recursively, in all child interviews.
      * @return a set of all questions in this and every child interview.
      */
-    public Set getQuestions() {
+    public Set<Question> getQuestions() {
         Set<Question> s = new HashSet<>();
         getQuestions0(s);
         return s;
@@ -1145,8 +1145,8 @@
      * items, and false otherwise.
      */
     public boolean isChecklistEmpty() {
-        for (Iterator iter = iteratePath(true); iter.hasNext(); ) {
-            Question q = (Question) (iter.next());
+        for (Iterator<Question> iter = iteratePath(true); iter.hasNext(); ) {
+            Question q = iter.next();
             Checklist.Item[] items = q.getChecklistItems();
             if (items != null && items.length > 0)
                 return false;
@@ -1164,8 +1164,8 @@
      */
     public Checklist createChecklist() {
         Checklist c = new Checklist();
-        for (Iterator iter = iteratePath(true); iter.hasNext(); ) {
-            Question q = (Question) (iter.next());
+        for (Iterator<Question> iter = iteratePath(true); iter.hasNext(); ) {
+            Question q = iter.next();
             Checklist.Item[] items = q.getChecklistItems();
             if (items != null) {
                 for (Checklist.Item item : items) c.add(item);
@@ -1353,8 +1353,8 @@
             notifyCurrentQuestionChanged(newCurrentQuestion);
     }
 
-    private void loadMarkers(Map data) {
-        String s = (String) (data.get(MARKERS));
+    private void loadMarkers(Map<String, String> data) {
+        String s = data.get(MARKERS);
         int count = 0;
         if (s != null) {
             try {
@@ -1368,8 +1368,8 @@
         allMarkers = null;
 
         for (int i = 0; i < count; i++) {
-            String name = (String) (data.get(MARKERS_PREF + i + ".name"));
-            String tags = (String) (data.get(MARKERS_PREF + i));
+            String name = data.get(MARKERS_PREF + i + ".name");
+            String tags = data.get(MARKERS_PREF + i);
             if (tags != null)
                 loadMarkers(name, tags);
         }
@@ -1542,7 +1542,7 @@
      * @deprecated As of version 4.4.1, checksums are no longer
      *    calculated or checked.  True is always returned.
      */
-    public static boolean isChecksumValid(Map data, boolean okIfOmitted) {
+    public static boolean isChecksumValid(Map<String, String> data, boolean okIfOmitted) {
         return true;
     }
 
@@ -1616,7 +1616,7 @@
      * @see #LOCALE
      * @see #writeLocale(Map)
      */
-    protected static Locale readLocale(Map data) {
+    protected static Locale readLocale(Map<?, ?> data) {
         Locale result = null;
         Object o = data.get(LOCALE);
         if (o != null) {
@@ -2143,7 +2143,7 @@
         }
     }
 
-    public Set retrieveTemplateKeys() {
+    public Set<String> retrieveTemplateKeys() {
         if (getParent() != null)
             return getParent().retrieveTemplateKeys();
         else {
--- a/src/com/sun/javatest/InterviewPropagator.java	Wed Jul 11 20:44:47 2018 +0100
+++ b/src/com/sun/javatest/InterviewPropagator.java	Thu Jul 12 23:54:08 2018 +0100
@@ -170,8 +170,7 @@
 
     private boolean processNotUpdatableKeys(Map<String, String> templateData, InterviewParameters interview) {
         boolean wasUpdate = false;
-        for (Object key : templateData.keySet()) {
-            String templateKey = (String) key;
+        for (String templateKey : templateData.keySet()) {
             if (!isSystemIgnorableTemplateProperty(templateKey) && !this.interview.isUpdatableKey(templateKey)) {
                 String newTV = templateData.get(templateKey);
                 String oldTV = interview.retrieveTemplateProperty(templateKey);
@@ -185,11 +184,11 @@
         return wasUpdate;
     }
 
-    private boolean processPartialQuestions(Map<String, String> templateData, Map<String, Question> allQuestionMap, Map actual) throws IOException {
-        Iterator keys = templateData.keySet().iterator();
+    private boolean processPartialQuestions(Map<String, String> templateData, Map<String, Question> allQuestionMap, Map<String, String> actual) throws IOException {
+        Iterator<String> keys = templateData.keySet().iterator();
         boolean updated = false;
         while (keys.hasNext()) {
-            String questionKey = (String) keys.next();
+            String questionKey = keys.next();
             if (!interview.isUpdatableKey(questionKey)) {
                 continue;
             }
@@ -198,7 +197,7 @@
                 String templateValue = templateData.get(questionKey);
                 Properties2 templateProps = InterviewPropagator.stringToProperties2(templateValue);
                 // create actual map
-                String actualValue = (String) actual.get(questionKey);
+                String actualValue = actual.get(questionKey);
                 Properties2 actualProps = InterviewPropagator.stringToProperties2(actualValue);
                 String oldTVal = interview.retrieveTemplateProperty(questionKey);
                 Properties2 oldTemplateProps = null;
@@ -207,11 +206,11 @@
                 }
 
 
-                Iterator itt = templateProps.keySet().iterator();
+                Iterator<String> itt = templateProps.keySet().iterator();
                 boolean currentQuestionUpdated = false;
                 Properties2 oldValuesMap = new Properties2();
                 while (itt.hasNext()) {
-                    String subKey = (String) itt.next();
+                    String subKey = itt.next();
                     if (interview.isAutoUpdatableKey(questionKey, subKey) ||
                             !actualProps.containsKey(subKey)) {
                         String templateSubValue = templateProps.getProperty(subKey);
@@ -255,10 +254,8 @@
         return updated;
     }
 
-    private void processQuestionFromSet(Map<String, String> templateData, Map<String, Question> allQ, Set keySet, Map<String, String> actual) {
-        Iterator keys = keySet.iterator();
-        while (keys.hasNext()) {
-            String questionKey = (String) keys.next();
+    private void processQuestionFromSet(Map<String, String> templateData, Map<String, Question> allQ, Set<String> keySet, Map<String, String> actual) {
+        for (String questionKey : keySet) {
             if (!isIgnorableTemplateProperty(questionKey)) {
                 String templateV = templateData.get(questionKey);
                 String oldTemplateV = interview.retrieveTemplateProperty(questionKey);
@@ -383,18 +380,14 @@
 
 
     private void acceptTemplateDatafromMap(final Map<String, String[]> map, boolean templateOnly) {
-        Iterator<String> it = map.keySet().iterator();
-        while (it.hasNext()) {
-            String key = it.next();
+        for (String key : map.keySet()) {
             String[] vals = map.get(key);
             interview.storeTemplateProperty(key, vals[NEW_TEMPLATE].toString());
         }
         if (!templateOnly) {
             Map<String, String> actual = new HashMap<>();
             interview.save(actual);
-            it = map.keySet().iterator();
-            while (it.hasNext()) {
-                String key = it.next();
+            for (String key : map.keySet()) {
                 String[] vals = map.get(key);
                 actual.put(key, vals[NEW_TEMPLATE]);
             }
--- a/src/com/sun/javatest/TestDescription.java	Wed Jul 11 20:44:47 2018 +0100
+++ b/src/com/sun/javatest/TestDescription.java	Thu Jul 12 23:54:08 2018 +0100
@@ -60,7 +60,7 @@
      * filename and does not begin with the root filename.
      *
      */
-    public TestDescription(File root, File file, Map<String, String> params)
+    public TestDescription(File root, File file, Map<?, ?> params)
                 throws IllegalArgumentException {
 
         synchronized (this.getClass()) {
@@ -91,10 +91,8 @@
         rootRelativePath = rootRelativeFile.replace(File.separatorChar, '/');
 
         Vector<String> v = new Vector<>(0, params.size() * 2);
-        for (Iterator<String> i = params.keySet().iterator(); i.hasNext(); ) {
-            String key = i.next();
-            String value = params.get(key);
-            insert(v, key, value);
+        for (Map.Entry entry : params.entrySet()) {
+            insert(v, (String) entry.getKey(), (String) entry.getValue());
         }
         fields = new String[v.size()];
         v.copyInto(fields);
--- a/src/com/sun/javatest/TestEnvironment.java	Wed Jul 11 20:44:47 2018 +0100
+++ b/src/com/sun/javatest/TestEnvironment.java	Thu Jul 12 23:54:08 2018 +0100
@@ -36,6 +36,7 @@
 
 import com.sun.javatest.util.DynamicArray;
 import com.sun.javatest.util.I18NResourceBundle;
+import com.sun.javatest.util.Properties;
 import com.sun.javatest.util.StringArray;
 
 /**
@@ -75,7 +76,7 @@
 
     /**
      * Add a default set of properties to be included when environments are
-     * created.
+     * created. Properties are passed in as a {@code Map<String, String>} instance.
      * @param name a name for this collection or properties, so that the
      * source of the properties can be identified when browing an environment
      * @param propTable a table of properties to be included when environments
@@ -93,6 +94,20 @@
     }
 
     /**
+     * Add a default set of properties to be included when environments are
+     * created. Properties are passed in as a {@code java.util.Properties} instance.
+     * @param name a name for this collection or properties, so that the
+     * source of the properties can be identified when browing an environment
+     * @param propTable a table of properties to be included when environments
+     * are created
+     * @see #clearDefaultPropTables
+     * @throws NullPointerException if either name or propTable is null.
+     */
+    public static synchronized void addDefaultPropTable(String name, java.util.Properties propTable) {
+        addDefaultPropTable(name, Properties.convertToStringProps(propTable));
+    }
+
+    /**
      * Remove all previously registered default property tables.
      * @see #addDefaultPropTable
      */
--- a/src/com/sun/javatest/util/Properties.java	Wed Jul 11 20:44:47 2018 +0100
+++ b/src/com/sun/javatest/util/Properties.java	Thu Jul 12 23:54:08 2018 +0100
@@ -113,7 +113,8 @@
     }
 
     /**
-     * Saves string keys and values of the given properties list into the given {@code Map<String, String>} and returns it.
+     * Converts the given properties to {@code Map<String, String>} instance
+     * picking only string properties from the given {@code java.util.Properties} instance.
      */
     public static Map<String, String> convertToStringProps(java.util.Properties properties) {
         return extractStringPropsTo(new HashMap<String, String>(), properties);