Author: tfmorris
Date: 2007-11-23 15:54:26-0800
New Revision: 13829
Modified:
trunk/src_new/org/argouml/ui/PerspectiveSupport.java
trunk/src_new/org/argouml/ui/TreeModelComposite.java
Log:
Change Vector to List and deprecate old Vector based APIs
Modified: trunk/src_new/org/argouml/ui/PerspectiveSupport.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/ui/PerspectiveSupport.java?view=diff&rev=13829&p1=trunk/src_new/org/argouml/ui/PerspectiveSupport.java&p2=trunk/src_new/org/argouml/ui/PerspectiveSupport.java&r1=13828&r2=13829
==============================================================================
--- trunk/src_new/org/argouml/ui/PerspectiveSupport.java (original)
+++ trunk/src_new/org/argouml/ui/PerspectiveSupport.java 2007-11-23 15:54:26-0800
@@ -1,5 +1,5 @@
// $Id$
-// Copyright (c) 1996-2006 The Regents of the University of California. All
+// Copyright (c) 1996-2007 The Regents of the University of California. All
// Rights Reserved. Permission to use, copy, modify, and distribute this
// software and its documentation without fee, and without a written
// agreement is hereby granted, provided that the above copyright notice
@@ -24,9 +24,12 @@
package org.argouml.ui;
-import javax.swing.tree.TreeModel;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Vector;
+import javax.swing.tree.TreeModel;
+
import org.argouml.i18n.Translator;
@@ -42,15 +45,16 @@
/**
* The go rules that this Tree model uses to build child nodes.
*/
- private Vector goRules;
+ private List<TreeModel> goRules;
/** name */
private String name;
/** list of all possible rules in the collection Todolist specific */
- private static Vector rules = new Vector();
+ private static List<TreeModel> rules = new ArrayList<TreeModel>();
- private PerspectiveSupport() { }
+ private PerspectiveSupport() {
+ }
/**
* Creates a new instance of PerspectiveSupport
@@ -59,7 +63,7 @@
*/
public PerspectiveSupport(String n) {
name = Translator.localize(n);
- goRules = new Vector();
+ goRules = new ArrayList<TreeModel>();
}
/**
@@ -70,7 +74,7 @@
* @param n the name to be localized
* @param subs the go rules
*/
- public PerspectiveSupport(String n, Vector subs) {
+ public PerspectiveSupport(String n, List<TreeModel> subs) {
this(n);
goRules = subs;
}
@@ -84,8 +88,10 @@
* @param tm the tree model to be added
*/
public void addSubTreeModel(TreeModel tm) {
- if (goRules.contains(tm)) return;
- goRules.addElement(tm);
+ if (goRules.contains(tm)) {
+ return;
+ }
+ goRules.add(tm);
}
/**
@@ -95,18 +101,29 @@
* @param tm the treemodel to be removed
*/
public void removeSubTreeModel(TreeModel tm) {
- goRules.removeElement(tm);
+ goRules.remove(tm);
}
/**
* Get the rules that together form the perspective.
- *
+ *
* @return the rules that form the perspecive
+ * @deprecated for 0.25.4 by tfmorris. Use {@link #getSubTreeModelList()}.
*/
- public Vector getSubTreeModels() {
- return goRules;
+ @Deprecated
+ public Vector<TreeModel> getSubTreeModels() {
+ return new Vector<TreeModel>(goRules);
}
+ /**
+ * Get the rules that together form the perspective.
+ *
+ * @return the rules that form the perspective
+ */
+ public List<TreeModel> getSubTreeModelList() {
+ return goRules;
+ }
+
// ----------- name -------------------------
/**
@@ -124,6 +141,7 @@
/*
* @see java.lang.Object#toString()
*/
+ @Override
public String toString() {
if (getName() != null) return getName();
else return super.toString();
@@ -136,14 +154,22 @@
* @param rule the rule to be added
*/
public static void registerRule(TreeModel rule) {
- rules.addElement(rule);
+ rules.add(rule);
}
/**
* @return Returns the _goRules.
+ * @deprecated for 0.25.4 by tfmorris. Use {@link #getGoRuleList()}.
*/
- protected Vector getGoRules() {
- return goRules;
+ @Deprecated
+ protected Vector<TreeModel> getGoRules() {
+ return new Vector<TreeModel>(goRules);
}
+ /**
+ * @return Returns the _goRules.
+ */
+ protected List<TreeModel> getGoRuleList() {
+ return goRules;
+ }
}
Modified: trunk/src_new/org/argouml/ui/TreeModelComposite.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/ui/TreeModelComposite.java?view=diff&rev=13829&p1=trunk/src_new/org/argouml/ui/TreeModelComposite.java&p2=trunk/src_new/org/argouml/ui/TreeModelComposite.java&r1=13828&r2=13829
==============================================================================
--- trunk/src_new/org/argouml/ui/TreeModelComposite.java (original)
+++ trunk/src_new/org/argouml/ui/TreeModelComposite.java 2007-11-23 15:54:26-0800
@@ -44,9 +44,6 @@
/** The root of the model. */
private Object root;
- ////////////////////////////////////////////////////////////////
- // contructors
-
/**
* The constructor.
*
@@ -56,8 +53,6 @@
super(name);
}
- ////////////////////////////////////////////////////////////////
- // TreeModel implementation
/*
* @see javax.swing.tree.TreeModel#getRoot()
@@ -70,10 +65,7 @@
* @see javax.swing.tree.TreeModel#getChild(java.lang.Object, int)
*/
public Object getChild(Object parent, int index) {
-
- int nSubs = getGoRules().size();
- for (int i = 0; i < nSubs; i++) {
- TreeModel tm = (TreeModel) getGoRules().elementAt(i);
+ for (TreeModel tm : getGoRuleList()) {
int childCount = tm.getChildCount(parent);
if (index < childCount) {
return tm.getChild(parent, index);
@@ -87,11 +79,8 @@
* @see javax.swing.tree.TreeModel#getChildCount(java.lang.Object)
*/
public int getChildCount(Object parent) {
-
int childCount = 0;
- int nSubs = getGoRules().size();
- for (int i = 0; i < nSubs; i++) {
- TreeModel tm = (TreeModel) getGoRules().elementAt(i);
+ for (TreeModel tm : getGoRuleList()) {
childCount += tm.getChildCount(parent);
}
return childCount;
@@ -102,11 +91,8 @@
* java.lang.Object)
*/
public int getIndexOfChild(Object parent, Object child) {
-
int childCount = 0;
- int nSubs = getGoRules().size();
- for (int i = 0; i < nSubs; i++) {
- TreeModel tm = (TreeModel) getGoRules().elementAt(i);
+ for (TreeModel tm : getGoRuleList()) {
int childIndex = tm.getIndexOfChild(parent, child);
if (childIndex != -1) {
return childIndex + childCount;
@@ -123,11 +109,10 @@
* @see javax.swing.tree.TreeModel#isLeaf(java.lang.Object)
*/
public boolean isLeaf(Object node) {
- int nSubs = getGoRules().size();
- for (int i = 0; i < nSubs; i++) {
- TreeModel tm = (TreeModel) getGoRules().elementAt(i);
- if (!tm.isLeaf(node))
+ for (TreeModel tm : getGoRuleList()) {
+ if (!tm.isLeaf(node)) {
return false;
+ }
}
return true;
}
@@ -140,9 +125,7 @@
// Empty implementation - not used.
}
- ////////////////////////////////////////////////////////////////
- // other methods
-
+
/**
* @param r the root of the model
*/
@@ -150,4 +133,4 @@
root = r;
}
-} /* end class TreeModelComposite */
+}
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.