Java Code Examples for java.util.Vector.setElementAt()

The following are Jave code examples for showing how to use setElementAt() of the java.util.Vector class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jmt   File: ConvexHull.java   View Source Code Vote up 7 votes
/**
 * Form a tetrahedron from vertex and the existing triangular hull.
 *
 * @param face - a triangular face of the tetrahedron
 * @param vertex - the fourth point of the tetrahedron
 * @param vol - indicates on which side of face vertex lies
 */
private void triToTet(Polygon face, Vertex vertex, int vol) {
	Vector<Vertex> v = face.getVertices();
	Vertex v1 = v.elementAt(0);
	Vertex v2 = v.elementAt(1);
	Vertex v3 = v.elementAt(2);

	// Store the vertices in CCW order
	if (vol < 0) {
		v.setElementAt(v3, 0);
		v.setElementAt(v1, 2);
		Vertex tv = v1;
		v1 = v3;
		v3 = tv;
	}
	addFace(new Triangle(v3, v2, vertex));
	addFace(new Triangle(v2, v1, vertex));
	addFace(new Triangle(v1, v3, vertex));
}
 
Example 2
Project: openjdk-jdk10   File: DefaultTableModel.java   View Source Code Vote up 7 votes
/**
 *  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();
}
 
Example 3
Project: QN-ACTR-Release   File: ConvexHull.java   View Source Code Vote up 7 votes
/**
 * Form a tetrahedron from vertex and the existing triangular hull.
 *
 * @param face - a triangular face of the tetrahedron
 * @param vertex - the fourth point of the tetrahedron
 * @param vol - indicates on which side of face vertex lies
 */
private void triToTet(Polygon face, Vertex vertex, int vol) {
	Vector<Vertex> v = face.getVertices();
	Vertex v1 = v.elementAt(0);
	Vertex v2 = v.elementAt(1);
	Vertex v3 = v.elementAt(2);

	// Store the vertices in CCW order
	if (vol < 0) {
		v.setElementAt(v3, 0);
		v.setElementAt(v1, 2);
		Vertex tv = v1;
		v1 = v3;
		v3 = tv;
	}
	addFace(new Triangle(v3, v2, vertex));
	addFace(new Triangle(v2, v1, vertex));
	addFace(new Triangle(v1, v3, vertex));
}
 
Example 4
Project: jdk8u-jdk   File: DefaultTableModel.java   View Source Code Vote up 7 votes
/**
 *  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();
}
 
Example 5
Project: OpenJSharp   File: Whitespace.java   View Source Code Vote up 7 votes
/**
 * 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;
        }
    }
}
 
Example 6
Project: jdk8u-jdk   File: PolicyTool.java   View Source Code Vote up 7 votes
/**
 * 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;
}
 
Example 7
Project: rapidminer   File: AttributeEditor.java   View Source Code Vote up 6 votes
private void setDatum(int row, int column, String value) {
	Vector<String> col = dataColumnVector.get(column);
	if (row >= col.size()) {
		col.addElement(value);
		if (row >= rowCount) {
			rowCount = row + 1;
		}
	} else {
		col.setElementAt(value, row);
	}
	dataControl.setMaxRows(Math.max(dataControl.getMaxRows(), col.size()));
	dataControl.setMaxColumns(Math.max(dataControl.getMaxColumns(), dataColumnVector.size()));
}
 
Example 8
Project: MARF-for-Android   File: TransitionTable.java   View Source Code Vote up 6 votes
/**
 * Sets the entry of a table.
 *
 * @param poNonTerminal the non-terminal as a row index
 * @param poTerminal    the terminal as a column index
 * @param poEntry       the entry to set
 * @throws ArrayIndexOutOfBoundsException if either index does not exist
 */
public void setEntryAt(final NonTerminal poNonTerminal, final Terminal poTerminal, Object poEntry) {
    try {
        Vector oRow = (Vector) this.oTT.elementAt(poNonTerminal.getID());
        oRow.setElementAt(poEntry, poTerminal.getID());
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException
                (
                        "TransitinTable::setEntryAt() - Out of boundaries.\n"
                                + "TerminalID=" + poTerminal.getID()
                                + ", NonTerminalID=" + poNonTerminal.getID()
                );
    }
}
 
Example 9
Project: OpenJSharp   File: DefaultTableModel.java   View Source Code Vote up 6 votes
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);
    }
}
 
Example 10
Project: jdk8u-jdk   File: DefaultTableModel.java   View Source Code Vote up 6 votes
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);
    }
}
 
Example 11
Project: openjdk-jdk10   File: DefaultTableModel.java   View Source Code Vote up 6 votes
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;
        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);
    }
}
 
Example 12
Project: VASSAL-src   File: Sort.java   View Source Code Vote up 5 votes
private static void swap(Vector<Object> v, int i, int j) {
    Object tmp = v.elementAt(i);
    v.setElementAt(v.elementAt(j), i);
    v.setElementAt(tmp, j);
}
 
Example 13
Project: dev-courses   File: TestDataStructures.java   View Source Code Vote up 5 votes
public void testSpeed() {

        randomGenerator = new Random(System.currentTimeMillis());

        int           TEST_RUNS     = 100000;
        int           LOOP_COUNT    = 1000;
        HsqlArrayList arrayList     = new HsqlArrayList(TEST_RUNS);
        ArrayList     utilArrayList = new ArrayList(TEST_RUNS);
        Vector        vector        = new Vector(TEST_RUNS);
        Integer       value         = new Integer(randomGenerator.nextInt());
        Integer       INT_0         = new Integer(0);
        StopWatch     sw            = new StopWatch();

        System.out.println(sw.currentElapsedTimeToMessage("time"));

        for (int i = 0; i < TEST_RUNS; i++) {
            arrayList.add(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                arrayList.set(i, INT_0);
            }
        }

        System.out.println(
            sw.currentElapsedTimeToMessage("time HsqlArrayLsit"));
        sw.zero();

        for (int i = 0; i < TEST_RUNS; i++) {
            utilArrayList.add(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                utilArrayList.set(i, INT_0);
            }
        }

        System.out.println(sw.currentElapsedTimeToMessage("time ArrayList"));
        sw.zero();

        for (int i = 0; i < TEST_RUNS; i++) {
            vector.addElement(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                vector.setElementAt(INT_0, i);
            }
        }

        System.out.println(sw.currentElapsedTimeToMessage("time Vector"));
    }
 
Example 14
Project: openjdk-jdk10   File: SetOfIntegerSyntax.java   View Source Code Vote up 5 votes
/**
 * Accumulate the given range (lb .. ub) into the canonical array form into
 * the given vector of int[] objects.
 */
private static void accumulate(Vector<int[]> 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 = ranges.elementAt (j);
            int lba = rangea[0];
            int uba = rangea[1];
            int[] rangeb = 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;
            }
        }
    }
}
 
Example 15
Project: parabuild-ci   File: TestDataStructures.java   View Source Code Vote up 5 votes
public void testSpeed() {

        randomGenerator = new Random(System.currentTimeMillis());

        int           TEST_RUNS     = 100000;
        int           LOOP_COUNT    = 1000;
        HsqlArrayList arrayList     = new HsqlArrayList(TEST_RUNS);
        ArrayList     utilArrayList = new ArrayList(TEST_RUNS);
        Vector        vector        = new Vector(TEST_RUNS);
        Integer       value         = new Integer(randomGenerator.nextInt());
        Integer       INT_0         = new Integer(0);
        StopWatch     sw            = new StopWatch();

        System.out.println(sw.currentElapsedTimeToMessage("time"));

        for (int i = 0; i < TEST_RUNS; i++) {
            arrayList.add(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                arrayList.set(i, INT_0);
            }
        }

        System.out.println(sw.currentElapsedTimeToMessage("time"));
        sw.zero();

        for (int i = 0; i < TEST_RUNS; i++) {
            utilArrayList.add(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                utilArrayList.set(i, INT_0);
            }
        }

        System.out.println(sw.currentElapsedTimeToMessage("time"));
        sw.zero();

        for (int i = 0; i < TEST_RUNS; i++) {
            vector.addElement(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                vector.setElementAt(INT_0, i);
            }
        }

        System.out.println(sw.currentElapsedTimeToMessage("time"));
    }
 
Example 16
Project: parabuild-ci   File: TestDataStructures.java   View Source Code Vote up 5 votes
public void testSpeed() {

        randomGenerator = new Random(System.currentTimeMillis());

        int           TEST_RUNS     = 100000;
        int           LOOP_COUNT    = 1000;
        HsqlArrayList arrayList     = new HsqlArrayList(TEST_RUNS);
        ArrayList     utilArrayList = new ArrayList(TEST_RUNS);
        Vector        vector        = new Vector(TEST_RUNS);
        Integer       value         = new Integer(randomGenerator.nextInt());
        Integer       INT_0         = new Integer(0);
        StopWatch     sw            = new StopWatch();

        System.out.println(sw.currentElapsedTimeToMessage("time"));

        for (int i = 0; i < TEST_RUNS; i++) {
            arrayList.add(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                arrayList.set(i, INT_0);
            }
        }

        System.out.println(sw.currentElapsedTimeToMessage("time"));
        sw.zero();

        for (int i = 0; i < TEST_RUNS; i++) {
            utilArrayList.add(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                utilArrayList.set(i, INT_0);
            }
        }

        System.out.println(sw.currentElapsedTimeToMessage("time"));
        sw.zero();

        for (int i = 0; i < TEST_RUNS; i++) {
            vector.addElement(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                vector.setElementAt(INT_0, i);
            }
        }

        System.out.println(sw.currentElapsedTimeToMessage("time"));
    }
 
Example 17
Project: parabuild-ci   File: TestDataStructures.java   View Source Code Vote up 5 votes
public void testSpeed() {

        randomGenerator = new Random(System.currentTimeMillis());

        int           TEST_RUNS     = 100000;
        int           LOOP_COUNT    = 1000;
        HsqlArrayList arrayList     = new HsqlArrayList(TEST_RUNS);
        ArrayList     utilArrayList = new ArrayList(TEST_RUNS);
        Vector        vector        = new Vector(TEST_RUNS);
        Integer       value         = new Integer(randomGenerator.nextInt());
        Integer       INT_0         = new Integer(0);
        StopWatch     sw            = new StopWatch();

        System.out.println(sw.currentElapsedTimeToMessage("time"));

        for (int i = 0; i < TEST_RUNS; i++) {
            arrayList.add(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                arrayList.set(i, INT_0);
            }
        }

        System.out.println(sw.currentElapsedTimeToMessage("time"));
        sw.zero();

        for (int i = 0; i < TEST_RUNS; i++) {
            utilArrayList.add(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                utilArrayList.set(i, INT_0);
            }
        }

        System.out.println(sw.currentElapsedTimeToMessage("time"));
        sw.zero();

        for (int i = 0; i < TEST_RUNS; i++) {
            vector.addElement(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                vector.setElementAt(INT_0, i);
            }
        }

        System.out.println(sw.currentElapsedTimeToMessage("time"));
    }
 
Example 18
Project: jdk8u-jdk   File: SetOfIntegerSyntax.java   View Source Code Vote up 5 votes
/**
 * 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;
            }
        }
    }
}
 
Example 19
Project: openjdk-jdk10   File: DefaultTableModel.java   View Source Code Vote up 4 votes
/**
 * 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) {
    @SuppressWarnings("unchecked")
    Vector<Object> rowVector = dataVector.elementAt(row);
    rowVector.setElementAt(aValue, column);
    fireTableCellUpdated(row, column);
}
 
Example 20
Project: jdk8u-jdk   File: DefaultTableModel.java   View Source Code Vote up 3 votes
/**
 * 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);
}