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

The following are Jave code examples for showing how to use setSize() 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: MARF-for-Android   File: TransitionTable.java   View Source Code Vote up 7 votes
/**
 * This is a standard attempt to initilaize.
 * Must be called only by <code>GrammarCompiler</code> or when
 * dimensions of the table are well known.
 *
 * @param piRows rows number in the table
 * @param piCols columns number in the table
 * @return <code>true</code> if initialization was successful
 * @see marf.nlp.Parsing.GrammarCompiler.GrammarCompiler
 */
public boolean init(int piRows, int piCols) {
    if (this.oTT == null) {
        this.oTT = new Vector(piRows);
        this.oTT.setSize(piRows);

        int r = -1;

        try {
            for (r = 0; r < piRows; r++) {
                Vector oHorizontalVector = new Vector(piCols);
                oHorizontalVector.setSize(piCols);
                this.oTT.setElementAt(oHorizontalVector, r);
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            System.err.println("TransitionTable::init() - index out of bounds");
            System.err.println("piRows=" + piRows + ", piCols=" + piCols + ", r=" + r);
            return false;
        }

        return true;
    }

    return false;
}
 
Example 2
Project: openjdk-jdk10   File: VectorTest.java   View Source Code Vote up 7 votes
/**
 * 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 3
Project: myster   File: FileProgressWindow.java   View Source Code Vote up 6 votes
private static void resizeVectorWithLongs(Vector vector, int newSize) {
    int oldSize = vector.size();

    vector.setSize(newSize);

    if (newSize > oldSize) {
        for (int i = oldSize; i < newSize; i++) {
            vector.setElementAt(new Long(0), i);
        }
    }
}
 
Example 4
Project: sstore-soft   File: FeatureSet.java   View Source Code Vote up 5 votes
/**
 * 
 * @param txn
 * @param key
 * @param val
 * @param type
 */
public synchronized void addFeature(TransactionTrace txn, String key, Object val, Type type) {
    long txn_id = txn.getTransactionId();
    
    // Add the attribute if it's new
    if (!this.attributes.containsKey(key)) {
        // Figure out what type it is
        if (type == null) {
            Class<?> valClass = val.getClass();
            if (valClass.equals(Boolean.class) || valClass.equals(boolean.class)) {
                type = Type.BOOLEAN;
            } else if (ClassUtil.getSuperClasses(valClass).contains(Number.class)) {
                type = Type.NUMERIC;
            } else if (val instanceof String) {
                type = Type.STRING;
            } else {
                type = Type.RANGE;
            }
        }
        if (debug.val) LOG.debug("Adding new attribute " + key + " [" + type + "]");
        this.attributes.put(key, type);
        this.attribute_histograms.put(key, new ObjectHistogram());
        this.attribute_types.put(key, VoltType.NULL);
    }
    // HACK
    if (val != null && (val.getClass().equals(int.class) || val.getClass().equals(Integer.class))) {
        val = new Long((Integer)val);
    }
    
    // Always store the values in a histogram so we can normalize them later on
    try {
        this.attribute_histograms.get(key).put(val);
    } catch (Exception ex) {
        LOG.error("\n" + this.attribute_histograms.get(key));
        LOG.error("Invalid value '" + val + "' for attribute '" + key + "'", ex);
        System.exit(1);
    }

    // Now add the values into this txn's feature vector
    int idx = this.attributes.indexOf(key);
    int num_attributes = this.attributes.size();
    Vector<Object> values = this.txn_values.get(txn_id); 
    if (values == null) {
        if (trace.val) LOG.trace("Creating new feature vector for " + txn_id);
        values = new Vector<Object>(num_attributes);
        values.setSize(num_attributes);
        this.txn_values.put(txn_id, values);
    }
    if (num_attributes != this.last_num_attributes) {
        assert(num_attributes > this.last_num_attributes);
        for (Vector<Object> v : this.txn_values.values()) {
            v.setSize(num_attributes);
        } // FOR
        this.last_num_attributes = num_attributes;
        if (trace.val) LOG.trace("Increased FeatureSet size to " + this.last_num_attributes + " attributes");
    }
    this.txn_values.get(txn_id).set(idx, val);
    
    if (val != null && this.attribute_types.get(key) == VoltType.NULL) {
        this.attribute_types.put(key, VoltType.typeFromClass(val.getClass()));
    }
    
    if (trace.val) LOG.trace(txn_id + ": " + key + " => " + val);
}
 
Example 5
Project: sstore-soft   File: UniqueCombinationIterator.java   View Source Code Vote up 5 votes
/**
 * Find the next unique combination
 */
private void getNext() {
    assert (this.next == null);
    final boolean trace = LOG.isTraceEnabled();
    final boolean debug = LOG.isDebugEnabled();

    if (debug)
        LOG.debug("Finding next combination [call=" + (this.attempt_ctr++) + "]");

    boolean valid = false;
    Vector<Integer> buffer = null;
    for (int i = this.last.get(0); i < this.num_elements; i++) {
        if (trace)
            LOG.trace("\n" + this);

        buffer = new Vector<Integer>();
        buffer.setSize(this.combo_size);
        buffer.set(0, i);

        // We have a new combination!
        if (this.calculateCombinations(buffer, 1)) {
            if (trace)
                LOG.trace("Found new combination: " + buffer);
            valid = true;
            break;
        }
        if (trace)
            LOG.trace("No combination found that starts with index #" + i);
        buffer = null;
        this.initializeLast(i + 1);
    } // FOR

    if (trace)
        LOG.trace("VALID = " + valid);
    if (valid) {
        assert (this.combo_size == buffer.size());
        this.next = new ListOrderedSet<E>();
        for (int i = 0; i < this.combo_size; i++) {
            this.next.add(this.data.get(buffer.get(i)));
        } // FOR
        if (trace)
            LOG.trace("NEXT = " + this.next);

        // Increase the last position's counter so that it is different next
        // time
        this.last.set(this.combo_size - 1, this.last.lastElement() + 1);
        if (trace)
            LOG.trace("NEW LAST = " + this.last);

        this.finished = false;
    } else {
        this.finished = true;
    }
}
 
Example 6
Project: java-chess   File: MinimaxAlphaBeta.java   View Source Code Vote up 5 votes
public Move decision(final Board b) {
	// get maximum move
	
	final ArrayList<Move> moves = b.getMoves(color);
	if(moves.size() == 0)
		return null;
		
	Vector<Future<Float>> costs = new Vector<Future<Float>>(moves.size());
	costs.setSize(moves.size());
	
		ExecutorService exec = Executors.newFixedThreadPool(moves.size());
		try {
		    for (int i = 0; i < moves.size(); i++) {
		    	final Move move = moves.get(i);
		        Future<Float> result = exec.submit(new Callable<Float>() {

		            @Override
		            public Float call() {
		            	ArrayList<Move> state = new ArrayList<Move>();
		            	state.add(move);
		            	
		            	float tmp = minValue(b, state, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 1);
		            	return tmp;
		            }
		        });
		        costs.set(i, result);
		    }
		} finally {
		    exec.shutdown();
		}

		// max
		int maxi = -1;
	float max = Float.NEGATIVE_INFINITY;
		for(int i = 0; i < moves.size(); i++) {
			float cost;
		try {
			cost = costs.get(i).get();
		} catch (Exception e) {
			try {
				Thread.sleep(300);
			} catch (InterruptedException e1) {
			}
			continue;
		}
			if(cost >= max) {
				if(Math.abs(cost-max) < 0.1) // add a little random element
					if(rand.nextBoolean())
						continue;

				max = cost;
				maxi = i;
			}
		}
		
		return moves.get(maxi);
}
 
Example 7
Project: ibench   File: SuperfluousMappingGen.java   View Source Code Vote up 5 votes
@Override
	public void generateExpl(MappingScenario scenario, Connection dbCon,
			ExplanationAndErrorsDocument eDoc, Configuration conf)
			throws Exception {
		super.generateExpl(scenario, dbCon, eDoc, conf);

		Vector<String> mappings = scenario.getDoc().getMapIds();
//		SuperflousMappingError err;

		Collections.shuffle(mappings);
		mappings.setSize(numExpl);
		
		for (String mapping : mappings) {

			MappingType mapType = scenario.getDoc().getMapping(mapping);
//			Set<String> mappingSet = CollectionUtils.makeSet(mapping);
//			TransformationType[] transForMap = scenario.getDoc().getTransForMap(
//					mapType);
			
//			for (TransformationType t : transForMap) {
//				String targetName = t.getCreates();
//				String cmd = "SELECT tid FROM (SELECT MAPPROV * FROM "
//						+ targetName + ") x " + "WHERE trans_prov LIKE '%"
//						+ mapping + "%' limit 1";
//				try {
//					ResultSet rs = ConnectionManager.getInstance().execQuery(
//							cmd);
//					String tid = null;
//					if (rs.next()) {
//						tid = rs.getString("tid");
//					}
//					if (tid != null) {
//						ISingleMarker errorMarker = MarkerFactory
//								.newAttrMarker(targetName, tid, 0);
//						err = new SuperflousMappingError(
//								(IAttributeValueMarker) errorMarker);
//						gen.setExpl(err);
//						gen.getExpl().addMapSE(mapType);
//						gen.getExpl().setTransSE(
//								CollectionUtils.makeList(transForMap));
//						break;
//					}
//				} catch (Exception e) {
//					LoggerUtil.logException(e, log);
//				}
//			}
//			for (TransformationType t: transForMap)
//				gen.computeSideEffects(t.getCreates(), mappingSet);
//			
//			e.addExplanation(gen.getExpl());
		}
	}
 
Example 8
Project: s-store   File: FeatureSet.java   View Source Code Vote up 5 votes
/**
 * 
 * @param txn
 * @param key
 * @param val
 * @param type
 */
public synchronized void addFeature(TransactionTrace txn, String key, Object val, Type type) {
    long txn_id = txn.getTransactionId();
    
    // Add the attribute if it's new
    if (!this.attributes.containsKey(key)) {
        // Figure out what type it is
        if (type == null) {
            Class<?> valClass = val.getClass();
            if (valClass.equals(Boolean.class) || valClass.equals(boolean.class)) {
                type = Type.BOOLEAN;
            } else if (ClassUtil.getSuperClasses(valClass).contains(Number.class)) {
                type = Type.NUMERIC;
            } else if (val instanceof String) {
                type = Type.STRING;
            } else {
                type = Type.RANGE;
            }
        }
        if (debug.val) LOG.debug("Adding new attribute " + key + " [" + type + "]");
        this.attributes.put(key, type);
        this.attribute_histograms.put(key, new ObjectHistogram());
        this.attribute_types.put(key, VoltType.NULL);
    }
    // HACK
    if (val != null && (val.getClass().equals(int.class) || val.getClass().equals(Integer.class))) {
        val = new Long((Integer)val);
    }
    
    // Always store the values in a histogram so we can normalize them later on
    try {
        this.attribute_histograms.get(key).put(val);
    } catch (Exception ex) {
        LOG.error("\n" + this.attribute_histograms.get(key));
        LOG.error("Invalid value '" + val + "' for attribute '" + key + "'", ex);
        System.exit(1);
    }

    // Now add the values into this txn's feature vector
    int idx = this.attributes.indexOf(key);
    int num_attributes = this.attributes.size();
    Vector<Object> values = this.txn_values.get(txn_id); 
    if (values == null) {
        if (trace.val) LOG.trace("Creating new feature vector for " + txn_id);
        values = new Vector<Object>(num_attributes);
        values.setSize(num_attributes);
        this.txn_values.put(txn_id, values);
    }
    if (num_attributes != this.last_num_attributes) {
        assert(num_attributes > this.last_num_attributes);
        for (Vector<Object> v : this.txn_values.values()) {
            v.setSize(num_attributes);
        } // FOR
        this.last_num_attributes = num_attributes;
        if (trace.val) LOG.trace("Increased FeatureSet size to " + this.last_num_attributes + " attributes");
    }
    this.txn_values.get(txn_id).set(idx, val);
    
    if (val != null && this.attribute_types.get(key) == VoltType.NULL) {
        this.attribute_types.put(key, VoltType.typeFromClass(val.getClass()));
    }
    
    if (trace.val) LOG.trace(txn_id + ": " + key + " => " + val);
}
 
Example 9
Project: s-store   File: UniqueCombinationIterator.java   View Source Code Vote up 5 votes
/**
 * Find the next unique combination
 */
private void getNext() {
    assert (this.next == null);
    final boolean trace = LOG.isTraceEnabled();
    final boolean debug = LOG.isDebugEnabled();

    if (debug)
        LOG.debug("Finding next combination [call=" + (this.attempt_ctr++) + "]");

    boolean valid = false;
    Vector<Integer> buffer = null;
    for (int i = this.last.get(0); i < this.num_elements; i++) {
        if (trace)
            LOG.trace("\n" + this);

        buffer = new Vector<Integer>();
        buffer.setSize(this.combo_size);
        buffer.set(0, i);

        // We have a new combination!
        if (this.calculateCombinations(buffer, 1)) {
            if (trace)
                LOG.trace("Found new combination: " + buffer);
            valid = true;
            break;
        }
        if (trace)
            LOG.trace("No combination found that starts with index #" + i);
        buffer = null;
        this.initializeLast(i + 1);
    } // FOR

    if (trace)
        LOG.trace("VALID = " + valid);
    if (valid) {
        assert (this.combo_size == buffer.size());
        this.next = new ListOrderedSet<E>();
        for (int i = 0; i < this.combo_size; i++) {
            this.next.add(this.data.get(buffer.get(i)));
        } // FOR
        if (trace)
            LOG.trace("NEXT = " + this.next);

        // Increase the last position's counter so that it is different next
        // time
        this.last.set(this.combo_size - 1, this.last.lastElement() + 1);
        if (trace)
            LOG.trace("NEW LAST = " + this.last);

        this.finished = false;
    } else {
        this.finished = true;
    }
}
 
Example 10
Project: OpenJSharp   File: DefaultTableModel.java   View Source Code Vote up 5 votes
private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
}
 
Example 11
Project: jdk8u-jdk   File: DefaultTableModel.java   View Source Code Vote up 5 votes
private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
}
 
Example 12
Project: openjdk-jdk10   File: DefaultTableModel.java   View Source Code Vote up 5 votes
private static <E> Vector<E> newVector(int size) {
    Vector<E> v = new Vector<>(size);
    v.setSize(size);
    return v;
}