当前位置: 首页>>代码示例>>Java>>正文


Java Vector.setSize方法代码示例

本文整理汇总了Java中java.util.Vector.setSize方法的典型用法代码示例。如果您正苦于以下问题:Java Vector.setSize方法的具体用法?Java Vector.setSize怎么用?Java Vector.setSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Vector的用法示例。


在下文中一共展示了Vector.setSize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import java.util.Vector; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:souhaib100,项目名称:MARF-for-Android,代码行数:35,代码来源:TransitionTable.java

示例2: testSetSize

import java.util.Vector; //导入方法依赖的package包/类
/**
 * 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));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:VectorTest.java

示例3: resizeVectorWithLongs

import java.util.Vector; //导入方法依赖的package包/类
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);
        }
    }
}
 
开发者ID:addertheblack,项目名称:myster,代码行数:12,代码来源:FileProgressWindow.java

示例4: addFeature

import java.util.Vector; //导入方法依赖的package包/类
/**
 * 
 * @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);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:71,代码来源:FeatureSet.java

示例5: getNext

import java.util.Vector; //导入方法依赖的package包/类
/**
 * 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;
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:57,代码来源:UniqueCombinationIterator.java

示例6: decision

import java.util.Vector; //导入方法依赖的package包/类
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);
}
 
开发者ID:codeekage,项目名称:java-chess,代码行数:58,代码来源:MinimaxAlphaBeta.java

示例7: generateExpl

import java.util.Vector; //导入方法依赖的package包/类
@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());
		}
	}
 
开发者ID:RJMillerLab,项目名称:ibench,代码行数:53,代码来源:SuperfluousMappingGen.java

示例8: newVector

import java.util.Vector; //导入方法依赖的package包/类
private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:DefaultTableModel.java

示例9: newVector

import java.util.Vector; //导入方法依赖的package包/类
private static <E> Vector<E> newVector(int size) {
    Vector<E> v = new Vector<>(size);
    v.setSize(size);
    return v;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:DefaultTableModel.java


注:本文中的java.util.Vector.setSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。