Author: tfmorris
Date: 2007-11-23 15:40:12-0800
New Revision: 13823
Modified:
trunk/src_new/org/argouml/uml/ui/UMLAddDialog.java
Log:
Document why Vector is still used here. Use Java 5 loops.
Modified: trunk/src_new/org/argouml/uml/ui/UMLAddDialog.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/ui/UMLAddDialog.java?view=diff&rev=13823&p1=trunk/src_new/org/argouml/uml/ui/UMLAddDialog.java&p2=trunk/src_new/org/argouml/uml/ui/UMLAddDialog.java&r1=13822&r2=13823
==============================================================================
--- trunk/src_new/org/argouml/uml/ui/UMLAddDialog.java (original)
+++ trunk/src_new/org/argouml/uml/ui/UMLAddDialog.java 2007-11-23 15:40:12-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
@@ -80,6 +80,10 @@
/**
* The selected choices.
+ * TODO: This should be switched to a List when {@link #getSelected()}
+ * is removed. It needs to remain a Vector for now to preserve the
+ * semantics of {@link #getSelected()} because it returns the Vector
+ * itself, not a copy.
*/
private Vector selected = null;
@@ -118,9 +122,9 @@
* represented with their names in the choices list and the selected list.
*
* @param theChoices
- * A vector with the choices a user has.
+ * A List containing the choices a user has.
* @param preselected
- * A vector with already preselected choices
+ * A List containing the preselected choices
* @param theTitle
* The title of the dialog
* @param multiselectAllowed
@@ -140,9 +144,9 @@
* Constructs a UMLAddDialog with a given UMLListCellRenderer.
*
* @param theChoices
- * A vector with the choices a user has.
+ * A List containing the choices a user has.
* @param preselected
- * A vector with already preselected choices
+ * A List containing the preselected choices
* @param theTitle
* The title of the dialog
* @param renderer
@@ -297,16 +301,16 @@
}
/**
- * Utility method to construct a DefaultListModel from a Vector
+ * Utility method to construct a DefaultListModel from a List
*
* @param vec
* the given list
* @return DefaultListModel
*/
- protected DefaultListModel constructListModel(List vec) {
+ protected DefaultListModel constructListModel(List list) {
DefaultListModel model = new DefaultListModel();
- for (int i = 0; i < vec.size(); i++) {
- model.addElement(vec.get(i));
+ for (Object o : list) {
+ model.addElement(o);
}
return model;
}
@@ -373,12 +377,12 @@
}
private void getChoicesListInternal(List result) {
- int[] indices = choicesList.getSelectedIndices();
- for (int i = 0; i < indices.length; i++) {
- result.add(choices.get(indices[i]));
+ for (int index : choicesList.getSelectedIndices()) {
+ result.add(choices.get(index));
}
}
+
/**
* Returns the selected elements in the selected list
*
@@ -392,7 +396,7 @@
/**
* Returns the selected elements in the selected list
- *
+ *
* @return Vector
* @deprecated for 0.25.4 by tfmorris. Use {@link #getSelectedChoicesList()}.
*/
@@ -404,13 +408,13 @@
private void getSelectedChoicesInternal(List result) {
if (selectedList != null && selected != null) {
- int[] indices = selectedList.getSelectedIndices();
- for (int i = 0; i < indices.length; i++) {
- result.add(selected.get(indices[i]));
+ for (int index : selectedList.getSelectedIndices()) {
+ result.add(selected.get(index));
}
}
}
+
/**
* Returns the by the user selected elements. This method should be called
* if the selected choices are to be known.
@@ -419,6 +423,9 @@
* @deprecated for 0.25.4 by tfmorris. Use {@link #getSelectedList()}.
*/
public Vector getSelected() {
+ // TODO: Because we return our internal data directly, we can't copy
+ // it from a List to a Vector and keep the same semantics
+ // return new Vector(selected);
return selected;
}
@@ -431,7 +438,7 @@
public List getSelectedList() {
return selected;
}
-
+
/**
* Adds the selected elements in the choices list to the selected list.
* Updates the GUI too.
@@ -486,7 +493,7 @@
* emptied.
*/
public void cancel() {
- selected.removeAllElements();
+ selected.clear();
if (preSelected != null) {
selected.addAll(preSelected);
}
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.