Java Code Examples for java.util.Vector#setSize()

The following examples show how to use java.util.Vector#setSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VectorTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * tests for setSize()
 */
public void testSetSize() {
    final Vector v = new Vector();
    for (int n : new int[] { 100, 5, 50 }) {
        v.setSize(n);
        assertEquals(n, v.size());
        assertNull(v.get(0));
        assertNull(v.get(n - 1));
        assertThrows(
                ArrayIndexOutOfBoundsException.class,
                new Runnable() { public void run() { v.setSize(-1); }});
        assertEquals(n, v.size());
        assertNull(v.get(0));
        assertNull(v.get(n - 1));
    }
}
 
Example 2
Source File: MessageLoader.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void storeValue(int errorCode, String value, Vector<String> facilityVector) {
    if (facilityVector == null) {
        log.warn("Invalid error code " + errorCode + ", no valid facility; skipping");
        return;
    }
    final int code = MessageLookup.getCode(errorCode);
    if (facilityVector.size() <= code) {
        facilityVector.setSize(code + 1);
    }
    facilityVector.set(code, value);
}
 
Example 3
Source File: ClassHolder.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
protected ClassHolder(int estimatedConstantPoolCount) {
	// Constant Pool Information
	// 100 is the estimate of the number of entries that will be generated
	cptEntries = new Vector(estimatedConstantPoolCount);
	cptHashTable = new Hashtable(estimatedConstantPoolCount, (float)0.75);

	// reserve the 0'th constant pool entry
	cptEntries.setSize(1);
}
 
Example 4
Source File: ClassHolder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected ClassHolder(int estimatedConstantPoolCount) {
	// Constant Pool Information
	// 100 is the estimate of the number of entries that will be generated
	cptEntries = new Vector(estimatedConstantPoolCount);
	cptHashTable = new Hashtable(estimatedConstantPoolCount, (float)0.75);

	// reserve the 0'th constant pool entry
	cptEntries.setSize(1);
}
 
Example 5
Source File: DelaunayUtil.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public static Object getAtPosition(Vector v, int index)
{
	if(index > v.size())
	{
		v.setSize(index+1);
	}
	try
	{
		return v.get(index);
	}
	catch(IndexOutOfBoundsException e)
	{
		return null;
	}
}
 
Example 6
Source File: EventQueue.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
/**
    * Terminate the task running the queue, but only if there is a queue.
    */
   synchronized void terminateQueue() {
if (q != null) {
    Vector<EventListener> dummyListeners = new Vector<>();
    dummyListeners.setSize(1); // need atleast one listener
    q.add(new QueueElement(new TerminatorEvent(), dummyListeners));
    q = null;
}
   }
 
Example 7
Source File: VerifyFrame.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
public Vector getFrame(int count) throws jasError
{
  if(count > locals.size())
      throw new jasError("Counter exceed range", true);
  Vector result = new Vector(locals);
  if(count != 0)  // else -- full copy
      result.setSize(count);
  return result;
}
 
Example 8
Source File: DefaultTableModel.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
}
 
Example 9
Source File: DefaultTableModel.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
}
 
Example 10
Source File: DefaultTableModel.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
}
 
Example 11
Source File: GenericEncodingStrategy.java    From Carbonado with Apache License 2.0 4 votes vote down vote up
/**
 * Generates code that decodes property states from
 * ((properties.length + 3) / 4) bytes.
 *
 * @param encodedVar references a byte array
 * @param offset offset into byte array
 * @return local variables with state values
 */
private List<LocalVariable> decodePropertyStates(CodeAssembler a, LocalVariable encodedVar,
                                                 int offset, StorableProperty<S>[] properties)
{
    Vector<LocalVariable> stateVars = new Vector<LocalVariable>();
    LocalVariable accumVar = a.createLocalVariable(null, TypeDesc.INT);
    int accumShift = 8;

    for (int i=0; i<properties.length; i++) {
        StorableProperty<S> property = properties[i];

        int stateVarOrdinal = property.getNumber() >> 4;
        stateVars.setSize(Math.max(stateVars.size(), stateVarOrdinal + 1));

        if (stateVars.get(stateVarOrdinal) == null) {
            stateVars.set(stateVarOrdinal, a.createLocalVariable(null, TypeDesc.INT));
            a.loadThis();
            a.loadField(PROPERTY_STATE_FIELD_NAME + stateVarOrdinal, TypeDesc.INT);
            a.storeLocal(stateVars.get(stateVarOrdinal));
        }

        if (accumShift >= 8) {
            // Load accumulator byte.
            a.loadLocal(encodedVar);
            a.loadConstant(offset++);
            a.loadFromArray(TypeDesc.BYTE);
            a.loadConstant(0xff);
            a.math(Opcode.IAND);
            a.storeLocal(accumVar);
            accumShift = 0;
        }

        int stateShift = (property.getNumber() & 0xf) * 2;

        int accumPack = 2;
        int mask = PROPERTY_STATE_MASK << stateShift;

        // Try to pack more state properties into one operation.
        while ((accumShift + accumPack) < 8) {
            if (i + 1 >= properties.length) {
                // No more properties to encode.
                break;
            }
            StorableProperty<S> nextProperty = properties[i + 1];
            if (property.getNumber() + 1 != nextProperty.getNumber()) {
                // Properties are not consecutive.
                break;
            }
            if (stateVarOrdinal != (nextProperty.getNumber() >> 4)) {
                // Property states are stored in different fields.
                break;
            }
            accumPack += 2;
            mask |= PROPERTY_STATE_MASK << ((nextProperty.getNumber() & 0xf) * 2);
            property = nextProperty;
            i++;
        }

        a.loadLocal(accumVar);

        if (stateShift < accumShift) {
            a.loadConstant(accumShift - stateShift);
            a.math(Opcode.IUSHR);
        } else if (stateShift > accumShift) {
            a.loadConstant(stateShift - accumShift);
            a.math(Opcode.ISHL);
        }

        a.loadConstant(mask);
        a.math(Opcode.IAND);
        a.loadLocal(stateVars.get(stateVarOrdinal));
        a.loadConstant(~mask);
        a.math(Opcode.IAND);
        a.math(Opcode.IOR);
        a.storeLocal(stateVars.get(stateVarOrdinal));

        accumShift += accumPack;
    }

    return stateVars;
}
 
Example 12
Source File: DefaultTableModel.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static <E> Vector<E> newVector(int size) {
    Vector<E> v = new Vector<>(size);
    v.setSize(size);
    return v;
}
 
Example 13
Source File: DefaultTableModel.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
}
 
Example 14
Source File: DefaultTableModel.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
}
 
Example 15
Source File: DefaultTableModel.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
}
 
Example 16
Source File: DefaultTableModel.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
}
 
Example 17
Source File: DefaultTableModel.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
}
 
Example 18
Source File: Biom1ExportTaxonomy.java    From megan-ce with GNU General Public License v3.0 4 votes vote down vote up
/**
 * recursively visit all the selected leaves
 *
 * @param viewer
 * @param v
 * @param selected
 * @param path
 * @param rowList
 * @param dataList
 */
private static void visitSelectedLeavesRec(MainViewer viewer, Node v, NodeSet selected, Vector<String> path,
                                           LinkedList<Map> rowList, LinkedList<float[]> dataList, boolean officialRanksOnly, ProgressListener progressListener) throws CanceledException {

    if (v.getOutDegree() > 0 || selected.contains(v)) {
        final Integer taxId = (Integer) v.getInfo();
        String taxName = v == viewer.getTree().getRoot() ? "Root" : TaxonomyData.getName2IdMap().get(taxId);
        {
            int a = taxName.indexOf("<");
            int b = taxName.lastIndexOf(">");
            if (0 < a && a < b && b == taxName.length() - 1)
                taxName = taxName.substring(0, a).trim(); // remove trailing anything in < > brackets
        }
        final int rank = TaxonomyData.getTaxonomicRank(taxId);
        boolean addedPathElement = false;

        if (!officialRanksOnly || TaxonomicLevels.isMajorRank(rank)) {
            if (officialRanksOnly) {
                char letter = Character.toLowerCase(TaxonomicLevels.getName(rank).charAt(0));
                path.addElement(String.format("%c__%s", letter, taxName));
            } else
                path.addElement(taxName);
            addedPathElement = true;

            if (selected.contains(v)) {
                NodeData nodeData = viewer.getNodeData(v);
                if (nodeData != null) {
                    float[] values;
                    if (v.getOutDegree() == 0)
                        values = nodeData.getSummarized();
                    else
                        values = nodeData.getAssigned();
                    final Map<String, Object> rowItem = new StringMap<>();
                    rowItem.put("id", "" + taxId);
                    final Map<String, Object> metadata = new StringMap<>();
                    final ArrayList<String> classification = new ArrayList<>(path.size());
                    classification.addAll(path);
                    metadata.put("taxonomy", classification);
                    rowItem.put("metadata", metadata);
                    rowList.add(rowItem);
                    dataList.add(values);
                }
            }
        }
        progressListener.incrementProgress();

        for (Edge e = v.getFirstOutEdge(); e != null; e = v.getNextOutEdge(e)) {
            visitSelectedLeavesRec(viewer, e.getTarget(), selected, path, rowList, dataList, officialRanksOnly, progressListener);
        }
        if (addedPathElement)
            path.setSize(path.size() - 1);
    }
}
 
Example 19
Source File: DefaultTableModel.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
}
 
Example 20
Source File: DefaultTableModel.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
}