下面列出了java.util.Vector#setElementAt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Adds a column to the model. The new column will have the
* identifier <code>columnName</code>, which may be null.
* <code>columnData</code> is the
* optional vector of data for the column. If it is <code>null</code>
* the column is filled with <code>null</code> values. Otherwise,
* the new data will be added to model starting with the first
* element going to row 0, etc. This method will send a
* <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) {
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);
row.setElementAt(columnData.elementAt(i), newColumn);
}
}
else {
justifyRows(0, getRowCount());
}
fireTableStructureChanged();
}
/**
* Adds a column to the model. The new column will have the
* identifier <code>columnName</code>, which may be null.
* <code>columnData</code> is the
* optional vector of data for the column. If it is <code>null</code>
* the column is filled with <code>null</code> values. Otherwise,
* the new data will be added to model starting with the first
* element going to row 0, etc. This method will send a
* <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) {
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);
row.setElementAt(columnData.elementAt(i), newColumn);
}
}
else {
justifyRows(0, getRowCount());
}
fireTableStructureChanged();
}
/**
* Used with quicksort method above
*/
private static int partition(Vector rules, int p, int r) {
final WhitespaceRule x = (WhitespaceRule)rules.elementAt((p+r) >>> 1);
int i = p - 1, j = r + 1;
while (true) {
while (x.compareTo((WhitespaceRule)rules.elementAt(--j)) < 0) {
}
while (x.compareTo((WhitespaceRule)rules.elementAt(++i)) > 0) {
}
if (i < j) {
final WhitespaceRule tmp = (WhitespaceRule)rules.elementAt(i);
rules.setElementAt(rules.elementAt(j), i);
rules.setElementAt(tmp, j);
}
else {
return j;
}
}
}
/**
* Adds a column to the model. The new column will have the
* identifier <code>columnName</code>, which may be null.
* <code>columnData</code> is the
* optional vector of data for the column. If it is <code>null</code>
* the column is filled with <code>null</code> values. Otherwise,
* the new data will be added to model starting with the first
* element going to row 0, etc. This method will send a
* <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) {
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);
row.setElementAt(columnData.elementAt(i), newColumn);
}
}
else {
justifyRows(0, getRowCount());
}
fireTableStructureChanged();
}
/**
* Adds a column to the model. The new column will have the
* identifier <code>columnName</code>, which may be null.
* <code>columnData</code> is the
* optional vector of data for the column. If it is <code>null</code>
* the column is filled with <code>null</code> values. Otherwise,
* the new data will be added to model starting with the first
* element going to row 0, etc. This method will send a
* <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<?> 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<Object> row = dataVector.elementAt(i);
row.setElementAt(columnData.elementAt(i), newColumn);
}
}
else {
justifyRows(0, getRowCount());
}
fireTableStructureChanged();
}
/**
* Used with quicksort method above
*/
private static int partition(Vector rules, int p, int r) {
final WhitespaceRule x = (WhitespaceRule)rules.elementAt((p+r) >>> 1);
int i = p - 1, j = r + 1;
while (true) {
while (x.compareTo((WhitespaceRule)rules.elementAt(--j)) < 0) {
}
while (x.compareTo((WhitespaceRule)rules.elementAt(++i)) > 0) {
}
if (i < j) {
final WhitespaceRule tmp = (WhitespaceRule)rules.elementAt(i);
rules.setElementAt(rules.elementAt(j), i);
rules.setElementAt(tmp, j);
}
else {
return j;
}
}
}
/**
* Add a Permission entry to an existing PolicyEntry at the specified index.
* A Permission entry consists of a permission, name, and actions.
*
* If the permission already exists, it is not added again.
*/
boolean addPermEntry(PolicyEntry pe,
PolicyParser.PermissionEntry newPerm,
int index) {
// first add the permission to the Policy Parser Vector
PolicyParser.GrantEntry grantEntry = pe.getGrantEntry();
if (grantEntry.contains(newPerm) == true)
return false;
Vector<PolicyParser.PermissionEntry> permList =
grantEntry.permissionEntries;
if (index != -1)
permList.setElementAt(newPerm, index);
else
permList.addElement(newPerm);
modified = true;
return true;
}
/**
* Adds a column to the model. The new column will have the
* identifier <code>columnName</code>, which may be null.
* <code>columnData</code> is the
* optional vector of data for the column. If it is <code>null</code>
* the column is filled with <code>null</code> values. Otherwise,
* the new data will be added to model starting with the first
* element going to row 0, etc. This method will send a
* <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) {
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);
row.setElementAt(columnData.elementAt(i), newColumn);
}
}
else {
justifyRows(0, getRowCount());
}
fireTableStructureChanged();
}
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
final Vector contents = getContents();
final int n = contents.size();
for (int i = 0; i < n; i++) {
final Expression exp = (Expression)contents.elementAt(i);
if (!exp.typeCheck(stable).identicalTo(Type.String)) {
contents.setElementAt(new CastExpr(exp, Type.String), i);
}
}
return _type = Type.String;
}
private static void rotate(Vector 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);
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);
}
}
private static void rotate(Vector 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);
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);
}
}
private static void rotate(Vector 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);
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);
}
}
protected void buildEnumeration(final Vector vect) {
for (int i = 0; i < vect.size(); i++) {
final NameNode node = (NameNode) vect.elementAt(i);
final String className = node.getBinding().getClass().getName();
vect.setElementAt(new Binding(node.getAtomicName(), className, node.getBinding()), i);
}
myEnum = vect.elements();
}
/**
* Accumulate the given range (lb .. ub) into the canonical array form
* into the given vector of int[] objects.
*/
private static void accumulate(Vector ranges, int lb,int ub) {
// Make sure range is non-null.
if (lb <= ub) {
// Stick range at the back of the vector.
ranges.add(new int[] {lb, ub});
// Work towards the front of the vector to integrate the new range
// with the existing ranges.
for (int j = ranges.size()-2; j >= 0; -- j) {
// Get lower and upper bounds of the two ranges being compared.
int[] rangea = (int[]) ranges.elementAt (j);
int lba = rangea[0];
int uba = rangea[1];
int[] rangeb = (int[]) ranges.elementAt (j+1);
int lbb = rangeb[0];
int ubb = rangeb[1];
/* If the two ranges overlap or are adjacent, coalesce them.
* The two ranges overlap if the larger lower bound is less
* than or equal to the smaller upper bound. The two ranges
* are adjacent if the larger lower bound is one greater
* than the smaller upper bound.
*/
if (Math.max(lba, lbb) - Math.min(uba, ubb) <= 1) {
// The coalesced range is from the smaller lower bound to
// the larger upper bound.
ranges.setElementAt(new int[]
{Math.min(lba, lbb),
Math.max(uba, ubb)}, j);
ranges.remove (j+1);
} else if (lba > lbb) {
/* If the two ranges don't overlap and aren't adjacent but
* are out of order, swap them.
*/
ranges.setElementAt (rangeb, j);
ranges.setElementAt (rangea, j+1);
} else {
/* If the two ranges don't overlap and aren't adjacent and
* aren't out of order, we're done early.
*/
break;
}
}
}
}
public void setValueAt(Object aValue, int aRow, int aCol) {
Vector dataRow = (Vector) allRows.elementAt(aRow);
dataRow.setElementAt(aValue, aCol);
fireTableCellUpdated(aRow, aCol);
}
/**
* Accumulate the given range (lb .. ub) into the canonical array form
* into the given vector of int[] objects.
*/
private static void accumulate(Vector ranges, int lb,int ub) {
// Make sure range is non-null.
if (lb <= ub) {
// Stick range at the back of the vector.
ranges.add(new int[] {lb, ub});
// Work towards the front of the vector to integrate the new range
// with the existing ranges.
for (int j = ranges.size()-2; j >= 0; -- j) {
// Get lower and upper bounds of the two ranges being compared.
int[] rangea = (int[]) ranges.elementAt (j);
int lba = rangea[0];
int uba = rangea[1];
int[] rangeb = (int[]) ranges.elementAt (j+1);
int lbb = rangeb[0];
int ubb = rangeb[1];
/* If the two ranges overlap or are adjacent, coalesce them.
* The two ranges overlap if the larger lower bound is less
* than or equal to the smaller upper bound. The two ranges
* are adjacent if the larger lower bound is one greater
* than the smaller upper bound.
*/
if (Math.max(lba, lbb) - Math.min(uba, ubb) <= 1) {
// The coalesced range is from the smaller lower bound to
// the larger upper bound.
ranges.setElementAt(new int[]
{Math.min(lba, lbb),
Math.max(uba, ubb)}, j);
ranges.remove (j+1);
} else if (lba > lbb) {
/* If the two ranges don't overlap and aren't adjacent but
* are out of order, swap them.
*/
ranges.setElementAt (rangeb, j);
ranges.setElementAt (rangea, j+1);
} else {
/* If the two ranges don't overlap and aren't adjacent and
* aren't out of order, we're done early.
*/
break;
}
}
}
}
private static void swap(Vector a, int i, int j) {
Object T = a.elementAt(i);
a.setElementAt(a.elementAt(j), i);
a.setElementAt(T, j);
}
/**
* Sets the object value for the cell at <code>column</code> and
* <code>row</code>. <code>aValue</code> is the new value. This method
* will generate a <code>tableChanged</code> notification.
*
* @param aValue the new value; this can be null
* @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
*/
public void setValueAt(Object aValue, int row, int column) {
Vector rowVector = (Vector)dataVector.elementAt(row);
rowVector.setElementAt(aValue, column);
fireTableCellUpdated(row, 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
* will generate a <code>tableChanged</code> notification.
*
* @param aValue the new value; this can be null
* @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
*/
public void setValueAt(Object aValue, int row, int column) {
Vector rowVector = (Vector)dataVector.elementAt(row);
rowVector.setElementAt(aValue, column);
fireTableCellUpdated(row, 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
* will generate a <code>tableChanged</code> notification.
*
* @param aValue the new value; this can be null
* @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
*/
public void setValueAt(Object aValue, int row, int column) {
Vector rowVector = (Vector)dataVector.elementAt(row);
rowVector.setElementAt(aValue, column);
fireTableCellUpdated(row, column);
}