svn commit: r12700 - trunk/src_new/org/argouml/uml/diagram/static_structure/layout/ClassdiagramNode.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2007-05-27 23:02:34-0700
New Revision: 12700

Modified:
   trunk/src_new/org/argouml/uml/diagram/static_structure/layout/ClassdiagramNode.java

Log:
Update to Java 5 syntax.  Switch from Vector to List.

Modified: trunk/src_new/org/argouml/uml/diagram/static_structure/layout/ClassdiagramNode.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/diagram/static_structure/layout/ClassdiagramNode.java?view=diff&rev=12700&p1=trunk/src_new/org/argouml/uml/diagram/static_structure/layout/ClassdiagramNode.java&p2=trunk/src_new/org/argouml/uml/diagram/static_structure/layout/ClassdiagramNode.java&r1=12699&r2=12700
==============================================================================
--- trunk/src_new/org/argouml/uml/diagram/static_structure/layout/ClassdiagramNode.java	(original)
+++ trunk/src_new/org/argouml/uml/diagram/static_structure/layout/ClassdiagramNode.java	2007-05-27 23:02:34-0700
@@ -26,7 +26,9 @@
 
 import java.awt.Dimension;
 import java.awt.Point;
+import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Vector;
 
 import org.argouml.uml.diagram.layout.LayoutedNode;
@@ -79,7 +81,8 @@
      * Attribute downlinks represents the nodes that contain the figures, which
      * are sources of edges with the figure of this node as destination.
      */
-    private Vector downlinks = new Vector();
+    private List<ClassdiagramNode> downlinks = 
+        new ArrayList<ClassdiagramNode>();
 
     /**
      * Offset used for edges, which have this node as the "upper" node.
@@ -106,7 +109,7 @@
      * Attribute uplinks represents the nodes that contain the figures, which
      * are destinations of edges with the figure of this node as source.
      */
-    private Vector uplinks = new Vector();
+    private List<ClassdiagramNode> uplinks = new ArrayList<ClassdiagramNode>();
 
     /**
      * This attribute stores the 'weight' of this node. This is a computed
@@ -174,14 +177,11 @@
     public float calculateWeight() {
         weight = 0;
         float w = getSubtreeWeight();
-        if (!uplinks.isEmpty()) {
-            for (Iterator iter = uplinks.iterator(); iter.hasNext();) {
-                ClassdiagramNode node = (ClassdiagramNode) iter.next();
-                weight = Math.max(weight, node.getWeight()
-                        * UPLINK_FACTOR
-                        * (1 + 1 / Math
-                                .max(1, node.getColumn() + UPLINK_FACTOR)));
-            }
+        for (ClassdiagramNode node : uplinks) {
+            weight = Math.max(weight, node.getWeight()
+                    * UPLINK_FACTOR
+                    * (1 + 1 / Math
+                            .max(1, node.getColumn() + UPLINK_FACTOR)));
         }
         weight += w + 1 / Math.max(1, getColumn() + UPLINK_FACTOR);
         return weight;
@@ -204,14 +204,9 @@
     public int compareTo(Object arg0) {
         ClassdiagramNode node = (ClassdiagramNode) arg0;
         int result = 0;
-        if (this.isStandalone() && !node.isStandalone()) {
-            result = -1;
-        } else if (!this.isStandalone() && node.isStandalone()) {
-            result = 1;
-        } // else result = 0;
-        // Java 1.5:
-        // result = Boolean.valueOf(node.isStandalone()).compareTo(
-        // Boolean.valueOf(isStandalone()));
+        result =
+                Boolean.valueOf(node.isStandalone()).compareTo(
+                        Boolean.valueOf(isStandalone()));
         if (result == 0) {
             result = this.getTypeOrderNumer() - node.getTypeOrderNumer();
         }
@@ -219,14 +214,7 @@
             result = this.getRank() - node.getRank();
         }
         if (result == 0) {
-            float diff = node.getWeight() - this.getWeight();
-            if (diff < 0) {
-                result = -1;
-            } else if (diff > 0) {
-                result = 1;
-            } // else: result = 0
-            // Java 1.5:
-            // result = (int) Math.signum(node.getWeight() - this.getWeight());
+            result = (int) Math.signum(node.getWeight() - this.getWeight());
         }
         if (result == 0) {
             result = String.valueOf(this.getFigure().getOwner()).compareTo(
@@ -252,12 +240,22 @@
      * Get the downlinks of this node.
      * 
      * @return The downlinks of this node.
+     * @deprecated for 0.25.4 by tfmorris - use {@link #getDownNodes()}
      */
-    public Vector getDownlinks() {
-        return downlinks;
+    public Vector<ClassdiagramNode> getDownlinks() {
+        return new Vector<ClassdiagramNode>(downlinks);
     }
 
     /**
+     * Get the downlinks of this node.
+     * 
+     * @return The downlinks of this node.
+     */
+    public List<ClassdiagramNode> getDownNodes() {
+        return downlinks;
+    }
+    
+    /**
      * Get the offset which shall be used for edges with this node as parent.
      * 
      * @return The offset
@@ -282,10 +280,10 @@
      */
     public int getLevel() {
         int result = 0;
-        for (Iterator iter = uplinks.iterator(); iter.hasNext();) {
-            ClassdiagramNode node = (ClassdiagramNode) iter.next();
-            result = (node == this) ? result : Math.max(node.getLevel() + 1,
-                    result);
+        for (ClassdiagramNode node : uplinks) {
+            result =
+                    (node == this) ? result : Math.max(
+                            node.getLevel() + 1, result);
         }
         return result;
     }
@@ -336,9 +334,8 @@
     private float getSubtreeWeight() {
 
         float w = 1;
-        for (Iterator iter = downlinks.iterator(); iter.hasNext();) {
-            w += ((ClassdiagramNode) iter.next()).getSubtreeWeight()
-                    / UPLINK_FACTOR;
+        for (ClassdiagramNode node : downlinks) {
+            w += node.getSubtreeWeight() / UPLINK_FACTOR;
         }
         return w;
     }
@@ -363,12 +360,22 @@
      * Get the uplinks of this node.
      * 
      * @return The uplinks of this node.
+     * @deprecated for 0.25.4 by tfmorris - use {@link #getUpNodes()}
      */
-    public Vector getUplinks() {
-        return uplinks;
+    public Vector<ClassdiagramNode> getUplinks() {
+        return new Vector<ClassdiagramNode>(uplinks);
     }
 
     /**
+     * Get the uplinks of this node.
+     * 
+     * @return The uplinks of this node.
+     */
+    public List<ClassdiagramNode> getUpNodes() {
+        return uplinks;
+    }
+    
+    /**
      * Return the weight of this node, which is used for positioning in a row.
      * 
      * @return The weight of this node.
@@ -451,9 +458,9 @@
         getFigure().setLocation(newLocation);
         int xTrans = newLocation.x - oldLocation.x;
         int yTrans = newLocation.y - oldLocation.y;
-        for (Iterator iter = getFigure().getEnclosedFigs().iterator(); iter
-                .hasNext();) {
-            ((Fig) iter.next()).translate(xTrans, yTrans);
+        for (Iterator<Fig> iter = getFigure().getEnclosedFigs().iterator(); 
+                iter.hasNext();) {
+            iter.next().translate(xTrans, yTrans);
         }
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.