src/share/classes/javax/swing/table/DefaultTableModel.java
Print this page
@@ -68,14 +68,22 @@
/**
* The <code>Vector</code> of <code>Vectors</code> of
* <code>Object</code> values.
*/
- protected Vector<Vector<Object>> dataVector;
+ @SuppressWarnings("rawtypes")
+ protected Vector<Vector> dataVector;
/** The <code>Vector</code> of column identifiers. */
- protected Vector<Object> columnIdentifiers;
+ @SuppressWarnings("rawtypes")
+ protected Vector columnIdentifiers;
+ // Unfortunately, for greater source compatibility the inner-most
+ // Vector in the two fields above is being left raw. The Vector is
+ // read as well as written so using Vector<?> is not suitable and
+ // using Vector<Object> (without adding copying of input Vectors),
+ // would disallow existing code that used, say, a Vector<String>
+ // as an input parameter.
//
// Constructors
//
@@ -119,11 +127,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<Object> columnNames, int rowCount) {
+ public DefaultTableModel(Vector<?> columnNames, int rowCount) {
setDataVector(newVector(rowCount), columnNames);
}
/**
* Constructs a <code>DefaultTableModel</code> with as many
@@ -154,11 +162,11 @@
* @param columnNames <code>vector</code> containing the names
* of the new columns
* @see #getDataVector
* @see #setDataVector
*/
- public DefaultTableModel(Vector<Vector<Object>> data, Vector<Object> columnNames) {
+ public DefaultTableModel(Vector<Vector<?>> data, Vector<?> columnNames) {
setDataVector(data, columnNames);
}
/**
* Constructs a <code>DefaultTableModel</code> and initializes the table
@@ -189,11 +197,12 @@
*
* @see #newDataAvailable
* @see #newRowsAdded
* @see #setDataVector
*/
- public Vector<Vector<Object>> getDataVector() {
+ @SuppressWarnings("rawtypes")
+ public Vector<Vector> getDataVector() {
return dataVector;
}
private static <E> Vector<E> nonNullVector(Vector<E> v) {
return (v != null) ? v : new Vector<>();
@@ -217,13 +226,14 @@
*
* @param dataVector the new data vector
* @param columnIdentifiers the names of the columns
* @see #getDataVector
*/
- public void setDataVector(Vector<Vector<Object>> dataVector,
- Vector<Object> columnIdentifiers) {
- this.dataVector = nonNullVector(dataVector);
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public void setDataVector(Vector<Vector<?>> dataVector,
+ Vector<?> columnIdentifiers) {
+ this.dataVector = nonNullVector((Vector<Vector>)((Vector)dataVector));
this.columnIdentifiers = nonNullVector(columnIdentifiers);
justifyRows(0, getRowCount());
fireTableStructureChanged();
}
@@ -265,11 +275,11 @@
for (int i = from; i < to; i++) {
if (dataVector.elementAt(i) == null) {
dataVector.setElementAt(new Vector<>(), i);
}
- ((Vector)dataVector.elementAt(i)).setSize(getColumnCount());
+ dataVector.elementAt(i).setSize(getColumnCount());
}
}
/**
* Ensures that the new rows have the correct number of columns.
@@ -372,11 +382,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<Object> rowData) {
+ public void insertRow(int row, Vector<?> rowData) {
dataVector.insertElementAt(rowData, row);
justifyRows(row, row+1);
fireTableRowsInserted(row, row);
}
@@ -482,12 +492,12 @@
* @param columnIdentifiers vector of column identifiers. If
* <code>null</code>, set the model
* to zero columns
* @see #setNumRows
*/
- public void setColumnIdentifiers(Vector<Object> columnIdentifiers) {
- setDataVector(dataVector, columnIdentifiers);
+ public void setColumnIdentifiers(Vector<?> columnIdentifiers) {
+ setDataVector((Vector<Vector<?>>)dataVector, columnIdentifiers);
}
/**
* Replaces the column identifiers in the model. If the number of
* <code>newIdentifier</code>s is greater than the current number
@@ -548,10 +558,11 @@
* <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
*/
+ @SuppressWarnings("unchecked") // Adding element to raw columnIdentifiers
public void addColumn(Object columnName, Vector<Object> columnData) {
columnIdentifiers.addElement(columnName);
if (columnData != null) {
int columnSize = columnData.size();
if (columnSize > getRowCount()) {
@@ -650,12 +661,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<Object> rowVector = dataVector.elementAt(row);
- return rowVector.elementAt(column);
+ return dataVector.elementAt(row).elementAt(column);
}
/**
* Sets the object value for the cell at <code>column</code> and
* <code>row</code>. <code>aValue</code> is the new value. This method
@@ -665,13 +675,13 @@
* @param row the row whose value is to be changed
* @param column the column whose value is to be changed
* @exception ArrayIndexOutOfBoundsException if an invalid row or
* column was given
*/
+ @SuppressWarnings("unchecked")
public void setValueAt(Object aValue, int row, int column) {
- Vector<Object> rowVector = dataVector.elementAt(row);
- rowVector.setElementAt(aValue, column);
+ dataVector.elementAt(row).setElementAt(aValue, column);
fireTableCellUpdated(row, column);
}
//
// Protected Methods
@@ -698,15 +708,17 @@
* 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>
*/
+ @SuppressWarnings("rawtypes")
protected static Vector<Vector<Object>> convertToVector(Object[][] anArray) {
if (anArray == null) {
return null;
}
- Vector<Vector<Object>> v = new Vector<>(anArray.length);
+ @SuppressWarnings("rawtypes")
+ Vector<Vector> v = new Vector<>(anArray.length);
for (Object[] o : anArray) {
v.addElement(convertToVector(o));
}
return v;
}