< prev index next >

src/share/classes/javax/swing/SpringLayout.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

@@ -183,15 +183,15 @@
  * @author      Scott Violet
  * @author      Joe Winchester
  * @since       1.4
  */
 public class SpringLayout implements LayoutManager2 {
-    private Map componentConstraints = new HashMap();
+    private Map<Component, Constraints> componentConstraints = new HashMap<Component, Constraints>();
 
     private Spring cyclicReference = Spring.constant(Spring.UNSET);
-    private Set cyclicSprings;
-    private Set acyclicSprings;
+    private Set<Spring> cyclicSprings;
+    private Set<Spring> acyclicSprings;
 
 
     /**
      * Specifies the top edge of a component's bounding rectangle.
      */

@@ -413,12 +413,11 @@
             if (value != null) {
                 history.add(name);
             }
             if (!valid) {
                 String[] all = horizontal ? ALL_HORIZONTAL : ALL_VERTICAL;
-                for (int i = 0; i < all.length; i++) {
-                    String s = all[i];
+                for (String s : all) {
                     if (!history.contains(s)) {
                         setConstraint(s, null);
                     }
                 }
             }

@@ -820,12 +819,11 @@
        }
 
        /*pp*/ void reset() {
            Spring[] allSprings = {x, y, width, height, east, south,
                horizontalCenter, verticalCenter, baseline};
-           for (int i = 0; i < allSprings.length; i++) {
-               Spring s = allSprings[i];
+           for (Spring s : allSprings) {
                if (s != null) {
                    s.setValue(Spring.UNSET);
                }
            }
        }

@@ -879,12 +877,12 @@
      * Constructs a new <code>SpringLayout</code>.
      */
     public SpringLayout() {}
 
     private void resetCyclicStatuses() {
-        cyclicSprings = new HashSet();
-        acyclicSprings = new HashSet();
+        cyclicSprings = new HashSet<Spring>();
+        acyclicSprings = new HashSet<Spring>();
     }
 
     private void setParent(Container p) {
         resetCyclicStatuses();
         Constraints pc = getConstraints(p);

@@ -1143,11 +1141,11 @@
      * @param       c the component whose constraints will be returned
      *
      * @return      the constraints for the specified component
      */
     public Constraints getConstraints(Component c) {
-       Constraints result = (Constraints)componentConstraints.get(c);
+       Constraints result = componentConstraints.get(c);
        if (result == null) {
            if (c instanceof javax.swing.JComponent) {
                 Object cp = ((javax.swing.JComponent)c).getClientProperty(SpringLayout.class);
                 if (cp instanceof Constraints) {
                     return applyDefaults(c, (Constraints)cp);
< prev index next >