src/share/classes/javax/swing/table/DefaultTableModel.java
Print this page
@@ -68,14 +68,14 @@
/**
* The <code>Vector</code> of <code>Vectors</code> of
* <code>Object</code> values.
*/
- protected Vector dataVector;
+ protected Vector<Vector<Object>> dataVector;
/** The <code>Vector</code> of column identifiers. */
- protected Vector columnIdentifiers;
+ protected Vector<Object> columnIdentifiers;
//
// Constructors
//
@@ -85,12 +85,12 @@
*/
public DefaultTableModel() {
this(0, 0);
}
- private static Vector newVector(int size) {
- Vector v = new Vector(size);
+ private static <E> Vector<E> newVector(int size) {
+ Vector<E> v = new Vector<>(size);
v.setSize(size);
return v;
}
/**
@@ -119,11 +119,11 @@
* <code>null</code> then the model has no columns
* @param rowCount the number of rows the table holds
* @see #setDataVector
* @see #setValueAt
*/
- public DefaultTableModel(Vector columnNames, int rowCount) {
+ public DefaultTableModel(Vector<Object> columnNames, int rowCount) {
setDataVector(newVector(rowCount), columnNames);
}
/**
* Constructs a <code>DefaultTableModel</code> with as many
@@ -154,11 +154,11 @@
* @param columnNames <code>vector</code> containing the names
* of the new columns
* @see #getDataVector
* @see #setDataVector
*/
- public DefaultTableModel(Vector data, Vector columnNames) {
+ public DefaultTableModel(Vector<Vector<Object>> data, Vector<Object> columnNames) {
setDataVector(data, columnNames);
}
/**
* Constructs a <code>DefaultTableModel</code> and initializes the table
@@ -189,16 +189,16 @@
*
* @see #newDataAvailable
* @see #newRowsAdded
* @see #setDataVector
*/
- public Vector getDataVector() {
+ public Vector<Vector<Object>> getDataVector() {
return dataVector;
}
- private static Vector nonNullVector(Vector v) {
- return (v != null) ? v : new Vector();
+ private static <E> Vector<E> nonNullVector(Vector<E> v) {
+ return (v != null) ? v : new Vector<>();
}
/**
* Replaces the current <code>dataVector</code> instance variable
* with the new <code>Vector</code> of rows, <code>dataVector</code>.
@@ -217,11 +217,12 @@
*
* @param dataVector the new data vector
* @param columnIdentifiers the names of the columns
* @see #getDataVector
*/
- public void setDataVector(Vector dataVector, Vector columnIdentifiers) {
+ public void setDataVector(Vector<Vector<Object>> dataVector,
+ Vector<Object> columnIdentifiers) {
this.dataVector = nonNullVector(dataVector);
this.columnIdentifiers = nonNullVector(columnIdentifiers);
justifyRows(0, getRowCount());
fireTableStructureChanged();
}
@@ -262,11 +263,11 @@
// is overridden.
dataVector.setSize(getRowCount());
for (int i = from; i < to; i++) {
if (dataVector.elementAt(i) == null) {
- dataVector.setElementAt(new Vector(), i);
+ dataVector.setElementAt(new Vector<>(), i);
}
((Vector)dataVector.elementAt(i)).setSize(getColumnCount());
}
}
@@ -345,11 +346,11 @@
* <code>null</code> values unless <code>rowData</code> is specified.
* Notification of the row being added will be generated.
*
* @param rowData optional data of the row being added
*/
- public void addRow(Vector rowData) {
+ public void addRow(Vector<Object> rowData) {
insertRow(getRowCount(), rowData);
}
/**
* Adds a row to the end of the model. The new row will contain
@@ -369,11 +370,11 @@
*
* @param row the row index of the row to be inserted
* @param rowData optional data of the row being added
* @exception ArrayIndexOutOfBoundsException if the row was invalid
*/
- public void insertRow(int row, Vector rowData) {
+ public void insertRow(int row, Vector<Object> rowData) {
dataVector.insertElementAt(rowData, row);
justifyRows(row, row+1);
fireTableRowsInserted(row, row);
}
@@ -392,17 +393,17 @@
private static int gcd(int i, int j) {
return (j == 0) ? i : gcd(j, i%j);
}
- private static void rotate(Vector v, int a, int b, int shift) {
+ private static <E> void rotate(Vector<E> v, int a, int b, int shift) {
int size = b - a;
int r = size - shift;
int g = gcd(size, r);
for(int i = 0; i < g; i++) {
int to = i;
- Object tmp = v.elementAt(a + to);
+ E tmp = v.elementAt(a + to);
for(int from = (to + r) % size; from != i; from = (to + r) % size) {
v.setElementAt(v.elementAt(a + from), a + to);
to = from;
}
v.setElementAt(tmp, a + to);
@@ -479,11 +480,11 @@
* @param columnIdentifiers vector of column identifiers. If
* <code>null</code>, set the model
* to zero columns
* @see #setNumRows
*/
- public void setColumnIdentifiers(Vector columnIdentifiers) {
+ public void setColumnIdentifiers(Vector<Object> columnIdentifiers) {
setDataVector(dataVector, columnIdentifiers);
}
/**
* Replaces the column identifiers in the model. If the number of
@@ -529,11 +530,11 @@
* uses <code>null</code> as the data vector.
*
* @param columnName the identifier of the column being added
*/
public void addColumn(Object columnName) {
- addColumn(columnName, (Vector)null);
+ addColumn(columnName, (Vector<Object>)null);
}
/**
* Adds a column to the model. The new column will have the
* identifier <code>columnName</code>, which may be null.
@@ -545,21 +546,21 @@
* <code>tableChanged</code> notification message to all the listeners.
*
* @param columnName the identifier of the column being added
* @param columnData optional data of the column being added
*/
- public void addColumn(Object columnName, Vector columnData) {
+ public void addColumn(Object columnName, Vector<Object> columnData) {
columnIdentifiers.addElement(columnName);
if (columnData != null) {
int columnSize = columnData.size();
if (columnSize > getRowCount()) {
dataVector.setSize(columnSize);
}
justifyRows(0, getRowCount());
int newColumn = getColumnCount() - 1;
for(int i = 0; i < columnSize; i++) {
- Vector row = (Vector)dataVector.elementAt(i);
+ Vector<Object> row = dataVector.elementAt(i);
row.setElementAt(columnData.elementAt(i), newColumn);
}
}
else {
justifyRows(0, getRowCount());
@@ -644,11 +645,11 @@
* @return the value Object at the specified cell
* @exception ArrayIndexOutOfBoundsException if an invalid row or
* column was given
*/
public Object getValueAt(int row, int column) {
- Vector rowVector = (Vector)dataVector.elementAt(row);
+ Vector<Object> rowVector = dataVector.elementAt(row);
return rowVector.elementAt(column);
}
/**
* Sets the object value for the cell at <code>column</code> and
@@ -660,11 +661,11 @@
* @param column the column whose value is to be changed
* @exception ArrayIndexOutOfBoundsException if an invalid row or
* column was given
*/
public void setValueAt(Object aValue, int row, int column) {
- Vector rowVector = (Vector)dataVector.elementAt(row);
+ Vector<Object> rowVector = dataVector.elementAt(row);
rowVector.setElementAt(aValue, column);
fireTableCellUpdated(row, column);
}
//
@@ -675,15 +676,15 @@
* Returns a vector that contains the same objects as the array.
* @param anArray the array to be converted
* @return the new vector; if <code>anArray</code> is <code>null</code>,
* returns <code>null</code>
*/
- protected static Vector convertToVector(Object[] anArray) {
+ protected static Vector<Object> convertToVector(Object[] anArray) {
if (anArray == null) {
return null;
}
- Vector<Object> v = new Vector<Object>(anArray.length);
+ Vector<Object> v = new Vector<>(anArray.length);
for (Object o : anArray) {
v.addElement(o);
}
return v;
}
@@ -692,15 +693,15 @@
* Returns a vector of vectors that contains the same objects as the array.
* @param anArray the double array to be converted
* @return the new vector of vectors; if <code>anArray</code> is
* <code>null</code>, returns <code>null</code>
*/
- protected static Vector convertToVector(Object[][] anArray) {
+ protected static Vector<Vector<Object>> convertToVector(Object[][] anArray) {
if (anArray == null) {
return null;
}
- Vector<Vector> v = new Vector<Vector>(anArray.length);
+ Vector<Vector<Object>> v = new Vector<>(anArray.length);
for (Object[] o : anArray) {
v.addElement(convertToVector(o));
}
return v;
}