下面列出了java.util.Vector#setSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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));
}
}
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);
}
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;
}
/**
* 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;
}
}
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;
}
}
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);
}
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);
}
private static Vector newVector(int size) {
Vector v = new Vector(size);
v.setSize(size);
return v;
}
private static Vector newVector(int size) {
Vector v = new Vector(size);
v.setSize(size);
return v;
}
private static Vector newVector(int size) {
Vector v = new Vector(size);
v.setSize(size);
return v;
}
private static Vector newVector(int size) {
Vector v = new Vector(size);
v.setSize(size);
return v;
}
private static Vector newVector(int size) {
Vector v = new Vector(size);
v.setSize(size);
return v;
}
/**
* 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;
}
private static <E> Vector<E> newVector(int size) {
Vector<E> v = new Vector<>(size);
v.setSize(size);
return v;
}
private static Vector newVector(int size) {
Vector v = new Vector(size);
v.setSize(size);
return v;
}
private static Vector newVector(int size) {
Vector v = new Vector(size);
v.setSize(size);
return v;
}
private static Vector newVector(int size) {
Vector v = new Vector(size);
v.setSize(size);
return v;
}
/**
* 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);
}
}
private static Vector newVector(int size) {
Vector v = new Vector(size);
v.setSize(size);
return v;
}
private static Vector newVector(int size) {
Vector v = new Vector(size);
v.setSize(size);
return v;
}