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

The following are Jave code examples for showing how to use set() 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: AgentWorkbench   File: TimeSeriesTableModel.java   View Source Code Vote up 7 votes
/**
 * Edits the data series by exchanging data.
 * @param series the series
 * @param targetDataSeriesIndex the target data series index
 */
public void editSeriesExchangeData(DataSeries series, int targetDataSeriesIndex) throws NoSuchSeriesException {

	if (targetDataSeriesIndex<=(this.getColumnCount()-1)) {
		
		int targetTbIndex = targetDataSeriesIndex+1;
		List valuePairs = parentDataModel.getValuePairsFromSeries(series);
		for (int i = 0; i < valuePairs.size(); i++) {
			// --- Find the key in the table ----------
			ValuePair vp = (ValuePair) valuePairs.get(i);
			Number key = parentDataModel.getXValueFromPair(vp);
			Number value = parentDataModel.getYValueFromValuePair(vp);

			Vector<Number> editRow = this.tableModelDataVector.getKeyRowVectorTreeMap().get(key);
			if (editRow!=null) {
				// --- Edit the row -------------------
				editRow.set(targetTbIndex, value);
			}
		}
		this.fireTableStructureChanged();
		
	} else {
		throw new NoSuchSeriesException();
	}
}
 
Example 2
Project: AgentWorkbench   File: TimeSeriesTableModel.java   View Source Code Vote up 7 votes
/**
 * Edits the data series by remove data.
 * @param series the series
 * @param targetDataSeriesIndex the target data series index
 */
public void editSeriesRemoveData(DataSeries series, int targetDataSeriesIndex) throws NoSuchSeriesException {

	if (targetDataSeriesIndex<=(this.getColumnCount()-1)) {
		
		int targetTbIndex = targetDataSeriesIndex+1;
		HashSet<Number> removeKeys = this.getKeyHashSetFromDataSeries(series);
		
		for (int i = 0; i < this.tableModelDataVector.size(); i++) {
			Vector<Number> rowVector = this.tableModelDataVector.get(i);
			Number keyValue = (Number) rowVector.get(0);
			if (removeKeys.contains(keyValue)) {
				// --- Delete Value ---------
				rowVector.set(targetTbIndex, null);
			}
		}
		this.removeEmptyRows();
		this.fireTableStructureChanged();
		
	} else {
		throw new NoSuchSeriesException();
	}
}
 
Example 3
Project: OpenJSharp   File: Template.java   View Source Code Vote up 7 votes
/**
 * When the parser realises that it is dealign with a simplified stylesheet
 * it will create an empty Stylesheet object with the root element of the
 * stylesheet (a LiteralElement object) as its only child. The Stylesheet
 * object will then create this Template object and invoke this method to
 * force some specific behaviour. What we need to do is:
 *  o) create a pattern matching on the root node
 *  o) add the LRE root node (the only child of the Stylesheet) as our
 *     only child node
 *  o) set the empty Stylesheet as our parent
 *  o) set this template as the Stylesheet's only child
 */
public void parseSimplified(Stylesheet stylesheet, Parser parser) {

    _stylesheet = stylesheet;
    setParent(stylesheet);

    _name = null;
    _mode = null;
    _priority = Double.NaN;
    _pattern = parser.parsePattern(this, "/");

    final Vector contents = _stylesheet.getContents();
    final SyntaxTreeNode root = (SyntaxTreeNode)contents.elementAt(0);

    if (root instanceof LiteralElement) {
        addElement(root);
        root.setParent(this);
        contents.set(0, this);
        parser.setTemplate(this);
        root.parseContents(parser);
        parser.setTemplate(null);
    }
}
 
Example 4
Project: openjdk-jdk10   File: Mode.java   View Source Code Vote up 6 votes
private int partition(Vector templates, int p, int r) {
    final Template x = (Template)templates.elementAt(p);
    int i = p - 1;
    int j = r + 1;
    while (true) {
        while (x.compareTo((Template)templates.elementAt(--j)) > 0);
        while (x.compareTo((Template)templates.elementAt(++i)) < 0);
        if (i < j) {
            templates.set(j, templates.set(i, templates.elementAt(j)));
        }
        else {
            return j;
        }
    }
}
 
Example 5
Project: openjdk-jdk10   File: XSDHandler.java   View Source Code Vote up 6 votes
/**
 * Namespace growth
 *
 * Go through the import list of a given grammar and for each imported
 * grammar, check to see if the grammar bucket has a newer version.
 * If a new instance is found, we update the import list with the
 * newer version.
 */
private void updateImportListFor(SchemaGrammar grammar) {
    Vector importedGrammars = grammar.getImportedGrammars();
    if (importedGrammars != null) {
        for (int i=0; i<importedGrammars.size(); i++) {
            SchemaGrammar isg1 = (SchemaGrammar) importedGrammars.elementAt(i);
            SchemaGrammar isg2 = fGrammarBucket.getGrammar(isg1.getTargetNamespace());
            if (isg2 != null && isg1 != isg2) {
                importedGrammars.set(i, isg2);
            }
        }
    }
}
 
Example 6
Project: openjdk-jdk10   File: BuildConfig.java   View Source Code Vote up 6 votes
void extAttr(Vector receiver, String attr, String value) {
    int attr_pos=receiver.indexOf(attr) ;
    if ( attr_pos == -1) {
      // If attr IS NOT present in the Vector - add it
      receiver.add(attr); receiver.add(value);
    } else {
      // If attr IS present in the Vector - append value to it
      receiver.set(attr_pos+1,receiver.get(attr_pos+1)+value);
    }
}
 
Example 7
Project: alevin-svn2   File: DistributedNode.java   View Source Code Vote up 6 votes
private void sortPathes(Vector<DistanceEntry> pathList) {
	for (int i = 0; i < pathList.size(); i++) {
		for (int j = 0; j < pathList.size(); j++) {
			if (pathList.get(i).getDistance() > (pathList.get(j)
					.getDistance())) {
				DistanceEntry temp = pathList.get(i);
				pathList.set(i, pathList.get(j));
				pathList.set(j, temp);
			}
		}
	}
}
 
Example 8
Project: incubator-netbeans   File: KeyMapTest.java   View Source Code Vote up 6 votes
private void checkListContents(Vector<String> scList, String... expList) {
    assertEquals("List does not contains expected number of items", expList.length, scList.size());
    for (int i = 0; i < scList.size(); i++) {
        scList.set(i, scList.get(i).toLowerCase());
    }
    for (String string : expList) {
        assertTrue(scList.contains(string.toLowerCase()));
    }
}
 
Example 9
Project: AgentWorkbench   File: TableModelDataVector.java   View Source Code Vote up 6 votes
/**
 * Resets reminder maps.
 */
public void resetRowNumberAndReminderMaps() {
	keyRowVectorTreeMap.clear();
	keyIndexHashMap.clear();
	for (int i = 0; i < this.size(); i++) {
		Vector<Number> rowVector = this.get(i);
		if (this.isActivateRowNumber()==true) {
			rowVector.set(0, i+1);
		}
		Number key = rowVector.get(this.getKeyColumnIndex());
		this.keyRowVectorTreeMap.put(key, rowVector);
		this.keyIndexHashMap.put(key, i);
	}
}
 
Example 10
Project: rapidminer   File: BayBoostStream.java   View Source Code Vote up 6 votes
/**
 * This helper method takes as input the traing set and the set of models trained so far. It
 * re-estimates the model weights one by one, which means that it changes the contents of the
 * modelInfo container. Works with crisp base classifiers, only!
 *
 * @param exampleSet
 *            the training set to be used to tune the weights
 * @param modelInfo
 *            the <code>Vector</code> of <code>Model</code>s, each with its biasMatrix
 * @return <code>true</code> iff the <code>ExampleSet</code> contains at least one example that
 *         is not yet explained deterministically (otherwise: nothing left to learn)
 */
private boolean adjustBaseModelWeights(ExampleSet exampleSet, Vector<BayBoostBaseModelInfo> modelInfo)
		throws OperatorException {

	for (int j = 0; j < modelInfo.size(); j++) {
		BayBoostBaseModelInfo consideredModelInfo = modelInfo.get(j);
		Model consideredModel = consideredModelInfo.getModel();
		ContingencyMatrix cm = consideredModelInfo.getContingencyMatrix();
		// double[][] oldBiasMatrix = (double[][]) consideredModelInfo[1];

		BayBoostStream.createOrReplacePredictedLabelFor(exampleSet, consideredModel);
		exampleSet = consideredModel.apply(exampleSet);
		if (exampleSet.getAttributes().getPredictedLabel().isNominal() == false) {
			// Only the case of nominal base classifiers is supported!
			throw new UserError(this, 101, new Object[] { exampleSet.getAttributes().getLabel(),
			"BayBoostStream base learners" });
		}

		WeightedPerformanceMeasures wp = new WeightedPerformanceMeasures(exampleSet);
		ContingencyMatrix cmNew = wp.getContingencyMatrix();
		// double[][] newBiasMatrix = wp.createLiftRatioMatrix();
		if (isModelUseful(cm) == false) {
			modelInfo.remove(j);
			j--;
			log("Discard base model because of low advantage.");
		} else {
			consideredModelInfo = new BayBoostBaseModelInfo(consideredModel, cmNew);
			modelInfo.set(j, consideredModelInfo);

			boolean stillUncoveredExamples = WeightedPerformanceMeasures.reweightExamples(exampleSet, cmNew, false) > 0;
			if (stillUncoveredExamples == false) {
				return false;
			}
		}
	}
	return true;
}
 
Example 11
Project: Simulator_Casio_fx-82MS   File: Calculator.java   View Source Code Vote up 6 votes
private Vector<Operator> combineFactors(Vector<Operator> operations, int i, Operator oper, double result) {
    // Change the factor 2 of previous operation
    if(i>0){
        Operator oper_previous=(Operator)operations.get(i-1);
        if (oper.getOperation()==ListOperations.SUBTRACTION){
            result=-result;
        }
        oper_previous.setFactor2(result);
        operations.set(i-1, oper_previous);
    }
    // Change the factor 1 of next operation
    if(i<operations.size()-1){
        Operator oper_next=(Operator)operations.get(i+1);
        oper_next.setFactor1(result);
        operations.set(i+1, oper_next);
    }

    // Delete the current object from the vector
    if (operations.size()>1) {
        operations.remove(i);
    }
    else{
        Operator oper_final=(Operator)operations.get(i);
        oper_final.setResult(result);
        operations.set(i, oper_final);
    }

    // Return the combined vector
    return operations;
}
 
Example 12
Project: MaxSim   File: BuildConfig.java   View Source Code Vote up 6 votes
void extAttr(Vector receiver, String attr, String value) {
    int attr_pos=receiver.indexOf(attr) ;
    if ( attr_pos == -1) {
      // If attr IS NOT present in the Vector - add it
      receiver.add(attr); receiver.add(value);
    } else {
      // If attr IS present in the Vector - append value to it
      receiver.set(attr_pos+1,receiver.get(attr_pos+1)+value);
    }
}
 
Example 13
Project: Cybernet-VPN   File: ConfigParser.java   View Source Code Vote up 6 votes
public void parseConfig(Reader reader) throws IOException, ConfigParseError {
    HashMap<String, String> optionAliases = new HashMap<>();
    optionAliases.put("server-poll-timeout", "timeout-connect");
    BufferedReader br = new BufferedReader(reader);
    int lineno = 0;
    try {
        while (true) {
            String line = br.readLine();
            lineno++;
            if (line == null) break;
            if (lineno == 1) {
                if ((line.startsWith("PK\003\004") || (line.startsWith("PK\007\008")))) {
                    throw new ConfigParseError("Input looks like a ZIP Archive. Import is only possible for OpenVPN config files (.ovpn/.conf)");
                }
                if (line.startsWith("\uFEFF")) {
                    line = line.substring(1);
                }
            }
            // Check for OpenVPN Access Server Meta information
            if (line.startsWith("# OVPN_ACCESS_SERVER_")) {
                Vector<String> metaarg = parsemeta(line);
                meta.put(metaarg.get(0), metaarg);
                continue;
            }
            Vector<String> args = parseline(line);
            if (args.size() == 0) continue;
            if (args.get(0).startsWith("--")) args.set(0, args.get(0).substring(2));
            checkinlinefile(args, br);
            String optionname = args.get(0);
            if (optionAliases.get(optionname) != null) optionname = optionAliases.get(optionname);
            if (!options.containsKey(optionname)) {
                options.put(optionname, new Vector<Vector<String>>());
            }
            options.get(optionname).add(args);
        }
    } catch (OutOfMemoryError memoryError) {
        throw new ConfigParseError("File too large to parse: " + memoryError.getLocalizedMessage());
    }
}
 
Example 14
Project: OpenJSharp   File: Mode.java   View Source Code Vote up 6 votes
private int partition(Vector templates, int p, int r) {
    final Template x = (Template)templates.elementAt(p);
    int i = p - 1;
    int j = r + 1;
    while (true) {
        while (x.compareTo((Template)templates.elementAt(--j)) > 0);
        while (x.compareTo((Template)templates.elementAt(++i)) < 0);
        if (i < j) {
            templates.set(j, templates.set(i, templates.elementAt(j)));
        }
        else {
            return j;
        }
    }
}
 
Example 15
Project: AgentWorkbench   File: TimeSeriesTableModel.java   View Source Code Vote up 5 votes
/**
 * Edits the data series by adding or exchanging data.
 * @param series the series
 * @param targetDataSeriesIndex the target data series index
 */
public void editSeriesAddOrExchangeData(DataSeries series, int targetDataSeriesIndex) throws NoSuchSeriesException {

	if (targetDataSeriesIndex<=(this.getColumnCount()-1)) {
		
		boolean dataWereAdded = false;
		int targetTbIndex = targetDataSeriesIndex+1;
		TreeMap<Number, Vector<Number>> tableDataTreeMap = new TreeMap<Number, Vector<Number>>(this.tableModelDataVector.getKeyRowVectorTreeMap()); 
		
		List valuePairs = parentDataModel.getValuePairsFromSeries(series);
		for (int i = 0; i < valuePairs.size(); i++) {
			// --- Find the key in the table ----------
			ValuePair vp = (ValuePair) valuePairs.get(i);
			Number key = parentDataModel.getXValueFromPair(vp);
			Number value = parentDataModel.getYValueFromValuePair(vp);

			Vector<Number> editRow = tableDataTreeMap.get(key);
			if (editRow==null) {
				// --- Add a new row ------------------
				editRow = new Vector<Number>();
				while(editRow.size() < this.getColumnCount()){
					editRow.add(null);
				}
				editRow.set(0, key);
				editRow.set(targetTbIndex, value);
				tableDataTreeMap.put(key, editRow);
				dataWereAdded = true;
				
			} else {
				// --- Finally edit the row -----------
				editRow.set(targetTbIndex, value);
			}
		}
		
		// --- Finally update the table, if necessary -
		if (dataWereAdded==true) {
			// --- Rebuild the table ------------------
			Number[] keyArray = new Number[tableDataTreeMap.size()]; 
			tableDataTreeMap.keySet().toArray(keyArray);
			for (int i=0; i<keyArray.length; i++) {
				Number keyTreeMap = keyArray[i];
				if ((valuePairs.size()-1)<i) {
					// --- Just add new data ----------
					this.tableModelDataVector.add(i, tableDataTreeMap.get(keyTreeMap));
				} else {
					Number keyValuePair = parentDataModel.getXValueFromPair((ValuePair) valuePairs.get(i));
					if (keyTreeMap.equals(keyValuePair)==false) {
						// --- New data was found -----
						this.tableModelDataVector.add(i, tableDataTreeMap.get(keyTreeMap));
					}	
				}
			}	
		}
		this.fireTableStructureChanged();
		
	} else {
		throw new NoSuchSeriesException();
	}
}
 
Example 16
Project: AgentWorkbench   File: XyChartModel.java   View Source Code Vote up 5 votes
@Override
public void exchangeSeries(int seriesIndex, DataSeries series) throws NoSuchSeriesException {
	
	if(seriesIndex < this.getSeriesCount()){

		XyDataSeries xyDataSeries = (XyDataSeries) series;
		XYSeries editSeries = this.getSeries(seriesIndex);
		// --- Are there configuration changes ? -------------------------- 
		if (xyDataSeries.getAutoSort()==editSeries.getAutoSort() && xyDataSeries.getAvoidDuplicateXValues()==(!editSeries.getAllowDuplicateXValues())) {
			// --- No configuration changes -------------------------------
			editSeries.clear();
			if (series.getLabel()!=null) {
				editSeries.setKey(series.getLabel());
			}
			
			List valuePairs = xyDataSeries.getXyValuePairs();
			for (int i = 0; i < valuePairs.size(); i++) {
				XyValuePair valuePair = (XyValuePair) valuePairs.get(i);
				editSeries.add(valuePair.getXValue().getFloatValue(), valuePair.getYValue().getFloatValue());	
			}
			
		} else {
			// --- Configuration has changed ------------------------------
			XYSeries newSeries = (XYSeries) this.getXYSeriesFromXyDataSeries(xyDataSeries);
			// --- Replace the edit series with the new series ------------
			Vector<XYSeries> currSerieses = new Vector<XYSeries>();
			for (int i=0; i < this.getSeriesCount(); i++) {
				currSerieses.add(this.getSeries(i));
			}
			currSerieses.set(seriesIndex, newSeries);

			this.getXySeriesCollection().removeAllSeries();
			for (int i = 0; i < currSerieses.size(); i++) {
				this.getXySeriesCollection().addSeries(currSerieses.get(i));
			}
		}
		
	}else{
		throw new NoSuchSeriesException();
	}
	
	this.setChanged();
	this.notifyObservers(ChartModel.EventType.SERIES_ADDED);
}
 
Example 17
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 18
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 19
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 20
Project: Mzip-Android   File: RarVM.java   View Source Code Vote up 5 votes
public void setLowEndianValue(Vector<Byte> mem, int offset, int value) {
    mem.set(offset + 0, Byte.valueOf((byte) (value & 0xff)));
    mem.set(offset + 1, Byte.valueOf((byte) ((value >>> 8) & 0xff)));
    mem.set(offset + 2, Byte.valueOf((byte) ((value >>> 16) & 0xff)));
    mem.set(offset + 3, Byte.valueOf((byte) ((value >>> 24) & 0xff)));
}