Example usage for java.util Vector Vector

List of usage examples for java.util Vector Vector

Introduction

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

Prototype

public Vector(Collection<? extends E> c) 

Source Link

Document

Constructs a vector containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Usage

From source file:Main.java

/**
 * Splits a string into substrings. /*from  www  . j a  v a 2 s  .com*/
 * @param str The string which is to split.
 * @param delim The delimiter character, for example a space <code>' '</code>.
 * @param trailing The ending which is added as a substring though it wasn't 
 *                 in the <code>str</code>. This parameter is just for the 
 *                 <code>IRCParser</code> class which uses this method to 
 *                 split the <code>middle</code> part into the parameters. 
 *                 But as last parameter always the <code>trailing</code> is 
 *                 added. This is done here because it's the fastest way to 
 *                 do it here.<br />
 *                 If the <code>end</code> is <code>null</code> or 
 *                 <code>""</code>, nothing is appended.
 * @return An array with all substrings.
 * @see #split(String, int)
 */
public static String[] split(String str, int delim, String trailing) {
    Vector items = new Vector(15);
    int last = 0;
    int index = 0;
    int len = str.length();
    while (index < len) {
        if (str.charAt(index) == delim) {
            items.add(str.substring(last, index));
            last = index + 1;
        }
        index++;
    }
    if (last != len)
        items.add(str.substring(last));
    if (trailing != null && trailing.length() != 0)
        items.add(trailing);
    String[] result = new String[items.size()];
    items.copyInto(result);
    return result;
}

From source file:org.zywx.wbpalmstar.plugin.uexzxing.qrcode.decoder.DecodedBitStreamParser.java

static DecoderResult decode(byte[] bytes, Version version, ErrorCorrectionLevel ecLevel, Hashtable hints)
        throws FormatException {
    BitSource bits = new BitSource(bytes);
    StringBuffer result = new StringBuffer(50);
    CharacterSetECI currentCharacterSetECI = null;
    boolean fc1InEffect = false;
    Vector byteSegments = new Vector(1);
    Mode mode;//from   www.  j a  va  2  s. c o  m
    do {
        // While still another segment to read...
        if (bits.available() < 4) {
            // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
            mode = Mode.TERMINATOR;
        } else {
            try {
                mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
            } catch (IllegalArgumentException iae) {
                throw FormatException.getFormatInstance();
            }
        }
        if (!mode.equals(Mode.TERMINATOR)) {
            if (mode.equals(Mode.FNC1_FIRST_POSITION) || mode.equals(Mode.FNC1_SECOND_POSITION)) {
                // We do little with FNC1 except alter the parsed result a bit according to the spec
                fc1InEffect = true;
            } else if (mode.equals(Mode.STRUCTURED_APPEND)) {
                // not really supported; all we do is ignore it
                // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
                bits.readBits(16);
            } else if (mode.equals(Mode.ECI)) {
                // Count doesn't apply to ECI
                int value = parseECIValue(bits);
                currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
                if (currentCharacterSetECI == null) {
                    throw FormatException.getFormatInstance();
                }
            } else {
                // How many characters will follow, encoded in this mode?
                int count = bits.readBits(mode.getCharacterCountBits(version));
                if (mode.equals(Mode.NUMERIC)) {
                    decodeNumericSegment(bits, result, count);
                } else if (mode.equals(Mode.ALPHANUMERIC)) {
                    decodeAlphanumericSegment(bits, result, count, fc1InEffect);
                } else if (mode.equals(Mode.BYTE)) {
                    decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
                } else if (mode.equals(Mode.KANJI)) {
                    decodeKanjiSegment(bits, result, count);
                } else {
                    throw FormatException.getFormatInstance();
                }
            }
        }
    } while (!mode.equals(Mode.TERMINATOR));

    return new DecoderResult(bytes, result.toString(), byteSegments.isEmpty() ? null : byteSegments, ecLevel);
}

From source file:net.sf.jabref.exporter.layout.Layout.java

public Layout(Vector<StringInt> parsedEntries, String classPrefix) {
    Vector<LayoutEntry> tmpEntries = new Vector<>(parsedEntries.size());

    Vector<StringInt> blockEntries = null;
    LayoutEntry le;/*w w w. j a  v  a  2  s . c  o  m*/
    String blockStart = null;

    for (StringInt parsedEntry : parsedEntries) {
        // TODO: Rewrite using switch
        if ((parsedEntry.i == LayoutHelper.IS_LAYOUT_TEXT) || (parsedEntry.i == LayoutHelper.IS_SIMPLE_FIELD)) {
            // Do nothing
        } else if (parsedEntry.i == LayoutHelper.IS_FIELD_START) {
            blockEntries = new Vector<>();
            blockStart = parsedEntry.s;
        } else if (parsedEntry.i == LayoutHelper.IS_FIELD_END) {
            if ((blockStart != null) && (blockEntries != null)) {
                if (blockStart.equals(parsedEntry.s)) {
                    blockEntries.add(parsedEntry);
                    le = new LayoutEntry(blockEntries, classPrefix, LayoutHelper.IS_FIELD_START);
                    tmpEntries.add(le);
                    blockEntries = null;
                } else {
                    LOGGER.debug(blockStart + '\n' + parsedEntry.s);
                    LOGGER.warn("Nested field entries are not implemented!");
                    Thread.dumpStack();
                }
            }
        } else if (parsedEntry.i == LayoutHelper.IS_GROUP_START) {
            blockEntries = new Vector<>();
            blockStart = parsedEntry.s;
        } else if (parsedEntry.i == LayoutHelper.IS_GROUP_END) {
            if ((blockStart != null) && (blockEntries != null)) {
                if (blockStart.equals(parsedEntry.s)) {
                    blockEntries.add(parsedEntry);
                    le = new LayoutEntry(blockEntries, classPrefix, LayoutHelper.IS_GROUP_START);
                    tmpEntries.add(le);
                    blockEntries = null;
                } else {
                    LOGGER.warn("Nested field entries are not implemented!");
                    Thread.dumpStack();
                }
            }
        } else if (parsedEntry.i == LayoutHelper.IS_OPTION_FIELD) {
            // Do nothing
        }

        if (blockEntries == null) {
            tmpEntries.add(new LayoutEntry(parsedEntry, classPrefix));
        } else {
            blockEntries.add(parsedEntry);
        }
    }

    layoutEntries = new LayoutEntry[tmpEntries.size()];

    for (int i = 0; i < tmpEntries.size(); i++) {
        layoutEntries[i] = tmpEntries.get(i);
        // Note if one of the entries has an invalid formatter:
        if (layoutEntries[i].isInvalidFormatter()) {
            missingFormatters.addAll(layoutEntries[i].getInvalidFormatters());
        }
    }
}

From source file:techtonic.PlotGraphListener.java

@Override
public void actionPerformed(ActionEvent e) {

    Vector<String> v = new Vector<String>(Arrays.asList(trajectoryQuality));
    Techtonic.setEnablejcbX_Axis(true);/*w  w w .  java2s .  c o  m*/
    Techtonic.setEnablejcbY_Axis(true);
    Techtonic.setjcbX_Axis(v);
    Techtonic.setjcbY_Axis(v);
    List<WitsmlTrajectoryStation> stationsAsList = Arrays
            .asList(new WitsmlTrajectoryStation[trajectory.getStations().size()]);
    for (WitsmlTrajectoryStation s : trajectory.getStations()) {
        stationsAsList.set(s.getStationNo(), s);
    }
    Techtonic.setEnablejcbX_Axis(true);
    Techtonic.setPropertyBtn(true);
    Techtonic.setEnablejcbY_Axis(true);
    Techtonic.setjcbX_Axis(v);
    Techtonic.setjcbY_Axis(v);
    Techtonic.setEnableRenderBtn(true);
    XYSeries series = new XYSeries(trajectory.getName());
    String xu = "";
    String yu = "";
    // add data to Dataset (here assume data is in ArrayLists x and y
    int count = 1;
    for (WitsmlTrajectoryStation station : stationsAsList) {

        Value tvd = station.getTvd();

        if (tvd == null) {
            continue;
        }
        xu = tvd.getUnit();
        Value md = station.getNorth();

        if (md == null) {
            continue;
        }
        yu = md.getUnit();
        //  System.out.println(count + " : ===>> tvd : "+tvd.getValue()+ "; md "+md.getValue());
        series.add(md.getValue(), tvd.getValue());
        count++;
    }
    XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(series);
    Techtonic.setCurrentStations(stationsAsList);
    // create a chart using the createYLineChart method...
    JFreeChart chart = ChartFactory.createXYLineChart(trajectory.getName(), // chart title
            xu, yu, // x and y axis labels
            data);
    //            XYPlot plot = (XYPlot) chart.getPlot();
    //             XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    //        renderer.setSeriesLinesVisible(0, true);
    //        renderer.setSeriesShapesVisible(1, true);
    //        renderer.setSeriesLinesVisible(1, false);
    //        renderer.setSeriesShapesVisible(1, true);        
    //           plot.setRenderer(renderer);

    ChartPanel cp = new ChartPanel(chart);
    //            JFrame fr = new JFrame();
    //            fr.add(cp);
    //            fr.pack();
    //            fr.setVisible(true);
    //cp.setMouseZoomable(true, true);  
    //     Techtonic.setTrajName(trajectory.getName());
    Techtonic.setFreeChart(chart);
    Techtonic.setDisplayArea(cp);
    //            chartPanel.setLayout(new java.awt.BorderLayout());
    //            chartPanel.add(cp,BorderLayout.CENTER);
    //            chartPanel.validate();
    //            chartPanel.repaint();`
}

From source file:ListOfNumbers.java

public ListOfNumbers() {
    victor = new Vector<Integer>(SIZE);
    for (int i = 0; i < SIZE; i++)
        victor.addElement(new Integer(i));
}

From source file:ListOfNumbers2.java

public ListOfNumbers2() {
    victor = new Vector<Integer>(SIZE);
    for (int i = 0; i < SIZE; i++)
        victor.addElement(new Integer(i));

    this.readList("infile.txt");
    this.writeList();
}

From source file:edu.umd.cs.psl.reasoner.admm.LinearLossTermTest.java

private void testProblem(double[] z, double[] y, double[] coeffs, double weight, final double stepSize,
        double[] expected) {
    config.setProperty("admmreasoner.stepsize", stepSize);
    ADMMReasoner reasoner = new ADMMReasoner(config);
    reasoner.z = new Vector<Double>(z.length);
    for (int i = 0; i < z.length; i++)
        reasoner.z.add(z[i]);// w w w  .  j a  v a2s .c  o  m

    int[] zIndices = new int[z.length];
    for (int i = 0; i < z.length; i++)
        zIndices[i] = i;
    LinearLossTerm term = new LinearLossTerm(reasoner, zIndices, coeffs, weight);
    for (int i = 0; i < z.length; i++)
        term.y[i] = y[i];
    term.minimize();

    for (int i = 0; i < z.length; i++)
        assertEquals(expected[i], term.x[i], 5e-5);
}

From source file:Matrix.java

/**
 * Init the matrix with number of dimensions and size.
 * //from w w  w. j av  a2  s .  c o m
 * @param dim
 *            dimension.
 * @param size
 *            size.
 */
public void init(int dim, int size) {
    v = new Vector[dim];
    for (int i = 0; i < dim; i++) {
        v[i] = new Vector<Integer>(size);
    }
}

From source file:ar.com.zauber.garfio.services.impl.FlexibleSvnLogParser.java

/** @see LogParser#parse(String) */
public final Results doParse(final String log) {
    final List<Action> ret = new ArrayList<Action>();

    final Context ctx = new Context();
    ctx.session = session;/*from  w  w w  .ja  v  a 2s  .c o m*/
    ctx.uid = uid;

    try {
        List<String> lines = new Vector<String>(Arrays.asList(log.split("\n")));
        for (String line : lines) {
            String cleanLine = line.replaceAll("\r", "");
            if (parseIssueId(ctx, cleanLine)) {
                lines.remove(line);
                break;
            }
        }

        if (ctx.issue != null) {
            for (String line : lines) {
                line = line.replaceAll("\r", "");
                final Matcher m = ACTION_PATT.matcher(line);
                if (m.matches()) {
                    createAction(m, ctx, ret);
                } else {
                    if (!StringUtils.isBlank(line) || ctx.note.length() > 0) {
                        ctx.note.append(line + "\n");
                    }
                }
            }
            if (!StringUtils.isBlank(ctx.note.toString())) {
                ret.add(0,
                        session.getActionFactory().createAddNoteAction(ctx.issue, ctx.note.toString().trim()));
            }
        }
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }

    return new Results(ret, ctx.errors);
}

From source file:org.jdal.swing.action.ComboLinker.java

/**
 * {@inheritDoc}/*from  w  ww.  j a v  a2s .c o m*/
 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 */

@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent e) {
    Object selected = primary.getSelectedItem();
    if (selected != null) {
        BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(selected);
        Collection<Object> collection = (Collection<Object>) wrapper.getPropertyValue(propertyName);
        DefaultComboBoxModel model = new DefaultComboBoxModel(new Vector<Object>(collection));
        dependent.setModel(model);
    }
}