< prev index next >

src/share/classes/javax/swing/tree/DefaultTreeSelectionModel.java

Print this page
rev 1527 : 6727662: Code improvement and warnings removing from swing packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: malenkov

@@ -59,11 +59,11 @@
  *
  * @see javax.swing.JTree
  *
  * @author Scott Violet
  */
-public class DefaultTreeSelectionModel extends Object implements Cloneable, Serializable, TreeSelectionModel
+public class DefaultTreeSelectionModel implements Cloneable, Serializable, TreeSelectionModel
 {
     /** Property name for selectionMode. */
     public static final String          SELECTION_MODE_PROPERTY = "selectionMode";
 
     /** Used to messaged registered listeners. */

@@ -96,12 +96,12 @@
     protected int                           leadRow;
 
     /** Used to make sure the paths are unique, will contain all the paths
      * in <code>selection</code>.
      */
-    private Hashtable                       uniquePaths;
-    private Hashtable                       lastPaths;
+    private Hashtable<TreePath, Boolean>    uniquePaths;
+    private Hashtable<TreePath, Boolean>    lastPaths;
     private TreePath[]                      tempPaths;
 
 
     /**
      * Creates a new instance of DefaultTreeSelectionModel that is

@@ -109,12 +109,12 @@
      */
     public DefaultTreeSelectionModel() {
         listSelectionModel = new DefaultListSelectionModel();
         selectionMode = DISCONTIGUOUS_TREE_SELECTION;
         leadIndex = leadRow = -1;
-        uniquePaths = new Hashtable();
-        lastPaths = new Hashtable();
+        uniquePaths = new Hashtable<TreePath, Boolean>();
+        lastPaths = new Hashtable<TreePath, Boolean>();
         tempPaths = new TreePath[1];
     }
 
     /**
      * Sets the RowMapper instance. This instance is used to determine

@@ -235,11 +235,11 @@
                 }
             }
 
             int              validCount = 0;
             TreePath         beginLeadPath = leadPath;
-            Vector           cPaths = new Vector(newCount + oldCount);
+            Vector<PathPlaceHolder> cPaths = new Vector<PathPlaceHolder>(newCount + oldCount);
 
             lastPaths.clear();
             leadPath = null;
             /* Find the paths that are new. */
             for(newCounter = 0; newCounter < newCount; newCounter++) {

@@ -284,11 +284,11 @@
                     cPaths.addElement(new PathPlaceHolder
                                       (selection[oldCounter], false));
 
             selection = newSelection;
 
-            Hashtable      tempHT = uniquePaths;
+            Hashtable<TreePath, Boolean>  tempHT = uniquePaths;
 
             uniquePaths = lastPaths;
             lastPaths = tempHT;
             lastPaths.clear();
 

@@ -357,11 +357,11 @@
             }
             else {
                 int               counter, validCount;
                 int               oldCount;
                 TreePath          beginLeadPath = leadPath;
-                Vector            cPaths = null;
+                Vector<PathPlaceHolder>  cPaths = null;
 
                 if(selection == null)
                     oldCount = 0;
                 else
                     oldCount = selection.length;

@@ -372,11 +372,11 @@
                     counter++) {
                     if(paths[counter] != null) {
                         if (uniquePaths.get(paths[counter]) == null) {
                             validCount++;
                             if(cPaths == null)
-                                cPaths = new Vector();
+                                cPaths = new Vector<PathPlaceHolder>();
                             cPaths.addElement(new PathPlaceHolder
                                               (paths[counter], true));
                             uniquePaths.put(paths[counter], Boolean.TRUE);
                             lastPaths.put(paths[counter], Boolean.TRUE);
                         }

@@ -397,16 +397,15 @@
                         System.arraycopy(selection, 0, newSelection, 0,
                                          oldCount);
                     if(validCount != paths.length) {
                         /* Some of the paths in paths are already in
                            the selection. */
-                        Enumeration   newPaths = lastPaths.keys();
+                        Enumeration<TreePath> newPaths = lastPaths.keys();
 
                         counter = oldCount;
                         while (newPaths.hasMoreElements()) {
-                            newSelection[counter++] = (TreePath)newPaths.
-                                                      nextElement();
+                            newSelection[counter++] = newPaths.nextElement();
                         }
                     }
                     else {
                         System.arraycopy(paths, 0, newSelection, oldCount,
                                          validCount);

@@ -457,19 +456,19 @@
             if(!canPathsBeRemoved(paths)) {
                 /* Could probably do something more interesting here! */
                 clearSelection();
             }
             else {
-                Vector      pathsToRemove = null;
+                Vector<PathPlaceHolder> pathsToRemove = null;
 
                 /* Find the paths that can be removed. */
                 for (int removeCounter = paths.length - 1; removeCounter >= 0;
                      removeCounter--) {
                     if(paths[removeCounter] != null) {
                         if (uniquePaths.get(paths[removeCounter]) != null) {
                             if(pathsToRemove == null)
-                                pathsToRemove = new Vector(paths.length);
+                                pathsToRemove = new Vector<PathPlaceHolder>(paths.length);
                             uniquePaths.remove(paths[removeCounter]);
                             pathsToRemove.addElement(new PathPlaceHolder
                                          (paths[removeCounter], false));
                         }
                     }

@@ -480,18 +479,17 @@
 
                     if(removeCount == selection.length) {
                         selection = null;
                     }
                     else {
-                        Enumeration          pEnum = uniquePaths.keys();
+                        Enumeration<TreePath> pEnum = uniquePaths.keys();
                         int                  validCount = 0;
 
                         selection = new TreePath[selection.length -
                                                 removeCount];
                         while (pEnum.hasMoreElements()) {
-                            selection[validCount++] = (TreePath)pEnum.
-                                                          nextElement();
+                            selection[validCount++] = pEnum.nextElement();
                         }
                     }
                     if (leadPath != null &&
                         uniquePaths.get(leadPath) == null) {
                         if (selection != null) {

@@ -620,12 +618,11 @@
      * @see #removeTreeSelectionListener
      *
      * @since 1.4
      */
     public TreeSelectionListener[] getTreeSelectionListeners() {
-        return (TreeSelectionListener[])listenerList.getListeners(
-                TreeSelectionListener.class);
+        return listenerList.getListeners(TreeSelectionListener.class);
     }
 
     /**
      * Notifies all listeners that are registered for
      * tree selection events on this object.

@@ -1082,11 +1079,11 @@
         boolean[]              newness = new boolean[cPathCount];
         TreePath[]            paths = new TreePath[cPathCount];
         PathPlaceHolder        placeholder;
 
         for(int counter = 0; counter < cPathCount; counter++) {
-            placeholder = (PathPlaceHolder)changedPaths.elementAt(counter);
+            placeholder = changedPaths.elementAt(counter);
             newness[counter] = placeholder.isNew;
             paths[counter] = placeholder.path;
         }
 
         TreeSelectionEvent     event = new TreeSelectionEvent

@@ -1178,12 +1175,12 @@
             System.arraycopy(selection, 0, clone.selection, 0, selLength);
         }
         clone.listenerList = new EventListenerList();
         clone.listSelectionModel = (DefaultListSelectionModel)
             listSelectionModel.clone();
-        clone.uniquePaths = new Hashtable();
-        clone.lastPaths = new Hashtable();
+        clone.uniquePaths = new Hashtable<TreePath, Boolean>();
+        clone.lastPaths = new Hashtable<TreePath, Boolean>();
         clone.tempPaths = new TreePath[1];
         return clone;
     }
 
     // Serialization support.
< prev index next >