Example usage for java.util Vector set

List of usage examples for java.util Vector set

Introduction

In this page you can find the example usage for java.util Vector set.

Prototype

public synchronized E set(int index, E element) 

Source Link

Document

Replaces the element at the specified position in this Vector with the specified element.

Usage

From source file:tvbrowser.core.search.booleansearch.BooleanSearcher.java

private static IMatcher getMatcher(Vector<Object> part, boolean caseSensitive,
        Hashtable<String, Object> matcherTable) throws ParserException {
    boolean lastWasMatch = false;
    for (int i = 0; i < part.size(); i++) {
        Object o = part.get(i);/*from  w  w w .jav  a2 s  .  c o  m*/
        if (o instanceof String) {
            String s = (String) o;
            if (!isKeyWord(s)) {
                if (lastWasMatch) {
                    Object Otemp = part.get(i - 1);
                    if (Otemp instanceof StringMatcher) {
                        StringMatcherRegEx ME = new StringMatcherRegEx(((StringMatcher) Otemp).toString(), s,
                                caseSensitive, matcherTable);
                        part.set(i - 1, ME);
                    } else {
                        StringMatcherRegEx ME = (StringMatcherRegEx) Otemp;
                        ME.addPart(s);
                    }
                    part.remove(i);
                    i--;
                    continue;
                }
                StringMatcher m = new StringMatcher(s, caseSensitive, matcherTable);
                part.set(i, m);
                lastWasMatch = true;
                continue;
            }
        }
        if (o instanceof Vector) {
            if (lastWasMatch) {
                part.insertElementAt("AND", i);
                i = 0;
                continue;
            }
        }
        lastWasMatch = false;
    }

    for (int i = 0; i < part.size(); i++) {
        Object O = part.get(i);
        if (O instanceof Vector) {
            @SuppressWarnings("unchecked")
            Vector<Object> v = (Vector<Object>) O;
            part.set(i, getMatcher(v, caseSensitive, matcherTable));
        }
    }

    boolean found = true;
    while (found) {
        found = false;
        for (int i = 0; i < part.size(); i++) {
            Object O = part.get(i);
            if ((O instanceof String) && (O.toString().equals("NOT"))) {
                if (i + 1 >= part.size()) {
                    throw new ParserException(
                            mLocalizer.msg("unexpectedEndOfInput", "Unexpected end of input"));
                }
                Object O2 = expect(part, i + 1, IMatcher.class, mLocalizer.msg("expression", "expression"));
                NotMatcher n = new NotMatcher((IMatcher) O2);
                part.remove(i);
                part.remove(i);

                /*
                 * If the previous Element is not "AND" insert an "AND"-Element
                 */
                if ((i > 0) && !(part.get(i - 1) instanceof AndMatcher)
                        && !((part.get(i - 1) instanceof String) && ((String) part.get(i - 1)).equals("AND"))) {
                    part.insertElementAt("AND", i);
                    i++;
                }
                part.insertElementAt(n, i);
                found = true;
                break;
            }
        }
    }

    found = true;
    while (found) {
        found = false;
        for (int i = 0; i < part.size(); i++) {
            Object O = part.get(i);
            if ((O instanceof String) && ((O.toString().equals("AND")) || ((O.toString().equals("&&"))))) {

                if (i <= 0) {
                    throw new ParserException(
                            mLocalizer.msg("missingExprBeforeAND", "Missing expression before 'AND'"));
                }
                if (i + 1 >= part.size()) {
                    throw new ParserException(
                            mLocalizer.msg("unexpectedEndOfInput", "Unexpected end of input"));
                }
                IMatcher O2 = (IMatcher) expect(part, i - 1, IMatcher.class,
                        mLocalizer.msg("expression", "expression"));
                IMatcher O1 = (IMatcher) expect(part, i + 1, IMatcher.class,
                        mLocalizer.msg("expression", "expression"));
                AndMatcher a = new AndMatcher(O1, O2);
                part.remove(i - 1);
                part.remove(i - 1);
                part.remove(i - 1);
                part.insertElementAt(a, i - 1);
                found = true;
                break;
            }
        }
    }

    found = true;
    while (found) {
        found = false;
        for (int i = 0; i < part.size(); i++) {
            Object O = part.get(i);
            if ((O instanceof String) && ((O.toString().equals("OR")) || (O.toString().equals("||")))) {
                if (i <= 0) {
                    throw new ParserException("Missing expression before \"OR\"");
                }
                if (i + 1 >= part.size()) {
                    throw new ParserException("Unexpected end of input");
                }
                IMatcher O2 = (IMatcher) expect(part, i - 1, IMatcher.class,
                        mLocalizer.msg("expression", "expression"));
                IMatcher O1 = (IMatcher) expect(part, i + 1, IMatcher.class,
                        mLocalizer.msg("expression", "expression"));
                OrMatcher a = new OrMatcher(O1, O2);
                part.remove(i - 1);
                part.remove(i - 1);
                part.remove(i - 1);
                part.insertElementAt(a, i - 1);
                found = true;
                break;
            }
        }
    }
    return (IMatcher) part.get(0);
}

From source file:org.opentestsystem.airose.linear.Matrix.java

@SuppressWarnings("rawtypes")
public Vector getRowVector(int row) {
    Vector<Double> vector = new Vector<Double>();
    vector.setSize(columns());/*from  www .j  a  v  a  2  s.c o  m*/
    for (int i = 0; i < columns(); i++) {
        vector.set(i, _matrix.getEntry(row, i));
    }
    return vector;
}

From source file:hermes.browser.model.BeanTableModel.java

public void setValueAt(Object value, int y, int x) {
    Vector row = (Vector) rows.elementAt(y);
    String propertyName = (String) row.elementAt(0);

    row.set(x, value);
    changes.put(propertyName, value);//from   ww  w  .j av a2  s  .  co  m
}

From source file:org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.MultinomialPurchasingModelSampler.java

protected <T> List<T> shuffle(Collection<T> input) throws Exception {
    Vector<T> shuffled = new Vector<>(input);
    for (int i = 0; i < input.size() - 1; i++) {
        int swapIdx = new UniformIntSampler(i, input.size() - 1, seedFactory).sample();
        T tmp = shuffled.get(i);/*from w ww .j  ava2s .c  o m*/
        shuffled.set(i, shuffled.get(swapIdx));
        shuffled.set(swapIdx, tmp);
    }

    return shuffled;
}

From source file:net.java.sen.tools.DictionaryMaker.java

int getIdList(String csv[], Vector result, int parent) {
    result.setSize(ruleList.size());/*  w  w  w  . j  ava2 s . c  o  m*/

    for (int j = 0; j < ruleList.size(); j++)
        result.set(j, new Integer(j));
    //    System.out.println("in:ruleList.size()=" + ruleList.size());
    //    System.out.println("ruleList size="+ruleList.size());
    //    System.out.println("result size="+result.size());
    //    pass

    for (int j = 0; j < csv.length; j++) {
        int k = 0;
        for (int n = 0; n < result.size(); n++) {
            int i = ((Integer) result.get(n)).intValue();
            String rl_ij = ((String[]) ruleList.get(i))[j];
            if ((parent == 0 && csv[j].charAt(0) == '*') || (parent == 1 && rl_ij.charAt(0) == '*')
                    || rl_ij.equals(csv[j])) {

                result.set(k++, result.get(n));
            }
        }
        result.setSize(k);
    }
    return result.size();
}

From source file:azkaban.common.utils.Utils.java

/**
 * Parse lines in byteArray and store the last *lineCount* lines in
 * *lastNLines*/* ww w. j  a v a2s . c  o  m*/
 * 
 * @param byteArray         source byte array
 * @param offset                offset of the byte array
 * @param length                length of the byte array
 * @param lineCount             desired number of lines
 * @param lastNLines        vector of last N lines
 * @return true         indicates we get *lineCount* lines 
 *                false         otherwise
 */
protected static boolean parseLinesFromLast(byte[] byteArray, int offset, int length, int lineCount,
        Vector<String> lastNLines) {

    if (lastNLines.size() > lineCount)
        return true;

    // convert byte array to string
    String lastNChars = new String(byteArray, offset, length);

    // reverse the string
    StringBuffer sb = new StringBuffer(lastNChars);
    lastNChars = sb.reverse().toString();

    // tokenize the string using "\n"
    String[] tokens = lastNChars.split("\n");

    // append lines to lastNLines
    for (int index = 0; index < tokens.length; index++) {
        StringBuffer sbLine = new StringBuffer(tokens[index]);
        String newline = sbLine.reverse().toString();

        if (index == 0 && !lastNLines.isEmpty()) { // first line might not be a complete line
            int lineNum = lastNLines.size();
            String halfLine = lastNLines.get(lineNum - 1);
            lastNLines.set(lineNum - 1, newline + halfLine);
        } else {
            lastNLines.add(newline);
        }

        if (lastNLines.size() > lineCount) {
            return true;
        }
    }

    return false;
}

From source file:edu.brown.utils.UniqueCombinationIterator.java

/**
 * Find the next unique combination/* w w w  . ja  v a 2 s  . c  om*/
 */
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;
    }
}

From source file:hermes.browser.model.PropertySetTableModel.java

@Override
public void setValueAt(Object value, int y, int x) {
    Vector row = (Vector) rows.elementAt(y);
    String propertyName;//from  ww w.  j a  va 2s.c  o m
    Object propertyValue;

    if (x == 0) {
        propertyName = (String) value;
        propertyValue = row.elementAt(1);

        if (isValidProperty(propertyName)) {
            row.set(0, value);
        } else {
            log.error(propertyName + " is not a valid property for " + bean.getClass().getName());
        }
    } else {
        propertyName = (String) row.elementAt(0);
        propertyValue = value;
        row.set(1, value);
    }

    log.debug("set (cached) " + propertyName + "=" + propertyValue.toString());

    fireTableCellUpdated(y, x);
}

From source file:uk.bl.wa.hadoop.mapreduce.ReservoirSamplingReducer.java

@Override
protected void reduce(Text key, Iterable<Text> values, Reducer<Text, Text, Text, Text>.Context context)
        throws IOException, InterruptedException {

    long numItemsSeen = 0;
    Vector<Text> reservoir = new Vector<Text>();
    RandomDataGenerator random = new RandomDataGenerator();
    // Fix the seed so reproducible by default:
    random.reSeed(defaultSeed);/*from   w  w w . ja v  a  2  s.  c o  m*/

    // Iterate through all values:
    for (Text item : values) {
        // Fill the reservoir:
        if (reservoir.size() < numSamples) {
            // reservoir not yet full, just append
            reservoir.add(item);
        } else {
            // find a sample to replace
            long rIndex = random.nextLong(0, numItemsSeen);
            if (rIndex < numSamples) {
                reservoir.set((int) rIndex, item);
            }
        }
        numItemsSeen++;
    }

    // Now output the sample:
    for (Text sto : reservoir) {
        context.write(key, sto);
    }
}

From source file:uk.bl.wa.hadoop.mapred.ReservoirSamplingReducer.java

@Override
public void reduce(Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter)
        throws IOException {

    Text item;/* w  ww. j a  v a 2  s.c  o  m*/
    long numItemsSeen = 0;
    Vector<Text> reservoir = new Vector<Text>();
    RandomDataGenerator random = new RandomDataGenerator();
    // Fix the seed so repoducible by default:
    random.reSeed(defaultSeed);

    // Iterate through all values:
    while (values.hasNext()) {
        item = values.next();

        if (reservoir.size() < numSamples) {
            // reservoir not yet full, just append
            reservoir.add(item);
        } else {
            // find a sample to replace
            long rIndex = random.nextLong(0, numItemsSeen);
            if (rIndex < numSamples) {
                reservoir.set((int) rIndex, item);
            }
        }
        numItemsSeen++;
    }

    // Choose the output:
    Text outKey = key;
    OutputCollector<Text, Text> collector;
    int pos = key.find("__");
    if (pos == -1) {
        collector = output;
    } else {
        String[] fp = key.toString().split("__");
        collector = getCollector(fp[0], fp[1], reporter);
        outKey = new Text(fp[1]);
    }

    // Now output the sample:
    for (Text sto : reservoir) {
        collector.collect(outKey, sto);
    }
}