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() 

Source Link

Document

Constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero.

Usage

From source file:BoxSample.java

public static void main(String args[]) {
    JButton button;//from w w  w.  j  a  va  2 s.  co  m
    Vector buttons = new Vector();
    Dimension dim;
    JFrame frame = new JFrame("Box Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS));
    JPanel topLeft = new JPanel();
    topLeft.setLayout(new BoxLayout(topLeft, BoxLayout.X_AXIS));
    topLeft.add(button = new JButton("One"));
    buttons.add(button);
    changeBoth(button);
    topLeft.add(button = new JButton("Two"));
    buttons.add(button);
    changeBoth(button);
    changeWidth(topLeft);
    JPanel bottomLeft = new JPanel();
    bottomLeft.setLayout(new BoxLayout(bottomLeft, BoxLayout.X_AXIS));
    bottomLeft.add(button = new JButton("Six"));
    buttons.add(button);
    changeBoth(button);
    bottomLeft.add(button = new JButton("Seven"));
    buttons.add(button);
    changeBoth(button);
    changeWidth(bottomLeft);
    JPanel left = new JPanel();
    left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS));
    left.add(topLeft);
    left.add(button = new JButton("Four"));
    buttons.add(button);
    changeBoth(button);
    left.add(bottomLeft);
    changeBoth(left);

    JPanel right = new JPanel();
    right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS));
    right.add(button = new JButton("Three"));
    buttons.add(button);
    changeWidth(button);
    right.add(button = new JButton("Five"));
    buttons.add(button);
    changeBoth(button);
    changeBoth(right);
    contentPane.add(left);
    contentPane.add(right);
    tweak(buttons);
    frame.pack();
    frame.setVisible(true);
}

From source file:InputStreamEnumerator.java

public static void main(String args[]) throws IOException {

    int c;//from   w  w w . j  a  va 2s . com
    Vector<String> files = new Vector<String>();

    files.addElement("c:\\autoexec.bat");
    files.addElement("c:\\config.sys");
    InputStreamEnumerator e = new InputStreamEnumerator(files);
    InputStream input = new SequenceInputStream(e);

    while ((c = input.read()) != -1) {
        System.out.print((char) c);
    }

    input.close();
}

From source file:examples.mail.java

public final static void main(String[] args) {
    String sender, recipient, subject, filename, server, cc;
    Vector ccList = new Vector();
    BufferedReader stdin;/* w w w .  ja  v a 2s  .c om*/
    FileReader fileReader = null;
    Writer writer;
    SimpleSMTPHeader header;
    SMTPClient client;
    Enumeration en;

    if (args.length < 1) {
        System.err.println("Usage: mail smtpserver");
        System.exit(1);
    }

    server = args[0];

    stdin = new BufferedReader(new InputStreamReader(System.in));

    try {
        System.out.print("From: ");
        System.out.flush();

        sender = stdin.readLine();

        System.out.print("To: ");
        System.out.flush();

        recipient = stdin.readLine();

        System.out.print("Subject: ");
        System.out.flush();

        subject = stdin.readLine();

        header = new SimpleSMTPHeader(sender, recipient, subject);

        while (true) {
            System.out.print("CC <enter one address per line, hit enter to end>: ");
            System.out.flush();

            // Of course you don't want to do this because readLine() may be null
            cc = stdin.readLine().trim();

            if (cc.length() == 0)
                break;

            header.addCC(cc);
            ccList.addElement(cc);
        }

        System.out.print("Filename: ");
        System.out.flush();

        filename = stdin.readLine();

        try {
            fileReader = new FileReader(filename);
        } catch (FileNotFoundException e) {
            System.err.println("File not found. " + e.getMessage());
        }

        client = new SMTPClient();
        client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

        client.connect(server);

        if (!SMTPReply.isPositiveCompletion(client.getReplyCode())) {
            client.disconnect();
            System.err.println("SMTP server refused connection.");
            System.exit(1);
        }

        client.login();

        client.setSender(sender);
        client.addRecipient(recipient);

        en = ccList.elements();

        while (en.hasMoreElements())
            client.addRecipient((String) en.nextElement());

        writer = client.sendMessageData();

        if (writer != null) {
            writer.write(header.toString());
            Util.copyReader(fileReader, writer);
            writer.close();
            client.completePendingCommand();
        }

        fileReader.close();

        client.logout();

        client.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:edu.jhu.pha.vospace.node.NodePath.java

public static final void main(String[] s) {

    try {//from  w  w w  .  j a  v a2  s .  c  o m
        NodePath sres1 = new NodePath("/a/");
        System.out.println(sres1.getParentRelativePath(new NodePath("/a/b/c")));
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    System.exit(1);
    Vector<String> strs = new Vector<String>();
    strs.add("");
    strs.add("/");
    strs.add("cont1");
    strs.add("/cont1");
    strs.add("/cont1/");
    strs.add("/cont1/file1");
    strs.add("cont1/file1");
    strs.add("cont1/dir1/");
    strs.add("cont1/dir1/file1");
    strs.add("cont1/dir1/dir2/file1");
    strs.add("cont1/dir1/dir2/dir3/");

    for (String sss : strs) {
        try {
            NodePath sres1 = new NodePath(sss);
            System.out.println(sss + ": (" + sres1.getContainerName() + "|" + sres1.getNodeStoragePath() + "|"
                    + sres1.getNodeOuterPath() + ");");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

From source file:Snippet154.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Composite composite = new Composite(shell, SWT.NO_BACKGROUND | SWT.EMBEDDED);

    /*/*from   ww  w.  jav  a 2 s.  co  m*/
     * Set a Windows specific AWT property that prevents heavyweight
     * components from erasing their background. Note that this is a global
     * property and cannot be scoped. It might not be suitable for your
     * application.
     */
    try {
        System.setProperty("sun.awt.noerasebackground", "true");
    } catch (NoSuchMethodError error) {
    }

    /* Create and setting up frame */
    Frame frame = SWT_AWT.new_Frame(composite);
    Panel panel = new Panel(new BorderLayout()) {
        public void update(java.awt.Graphics g) {
            /* Do not erase the background */
            paint(g);
        }
    };
    frame.add(panel);
    JRootPane root = new JRootPane();
    panel.add(root);
    java.awt.Container contentPane = root.getContentPane();

    /* Creating components */
    int nrows = 1000, ncolumns = 10;
    Vector rows = new Vector();
    for (int i = 0; i < nrows; i++) {
        Vector row = new Vector();
        for (int j = 0; j < ncolumns; j++) {
            row.addElement("Item " + i + "-" + j);
        }
        rows.addElement(row);
    }
    Vector columns = new Vector();
    for (int i = 0; i < ncolumns; i++) {
        columns.addElement("Column " + i);
    }
    JTable table = new JTable(rows, columns);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.createDefaultColumnsFromModel();
    JScrollPane scrollPane = new JScrollPane(table);
    contentPane.setLayout(new BorderLayout());
    contentPane.add(scrollPane);

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Utilities.java

public static void main(String[] args) {
    List list = Arrays.asList("one Two three Four five six one".split(" "));
    System.out.println(list);/*from  w  ww.ja v a 2 s. com*/
    System.out.println("max: " + Collections.max(list));
    System.out.println("min: " + Collections.min(list));
    AlphabeticComparator comp = new AlphabeticComparator();
    System.out.println("max w/ comparator: " + Collections.max(list, comp));
    System.out.println("min w/ comparator: " + Collections.min(list, comp));
    List sublist = Arrays.asList("Four five six".split(" "));
    System.out.println("indexOfSubList: " + Collections.indexOfSubList(list, sublist));
    System.out.println("lastIndexOfSubList: " + Collections.lastIndexOfSubList(list, sublist));
    Collections.replaceAll(list, "one", "Yo");
    System.out.println("replaceAll: " + list);
    Collections.reverse(list);
    System.out.println("reverse: " + list);
    Collections.rotate(list, 3);
    System.out.println("rotate: " + list);
    List source = Arrays.asList("in the matrix".split(" "));
    Collections.copy(list, source);
    System.out.println("copy: " + list);
    Collections.swap(list, 0, list.size() - 1);
    System.out.println("swap: " + list);
    Collections.fill(list, "pop");
    System.out.println("fill: " + list);
    List dups = Collections.nCopies(3, "snap");
    System.out.println("dups: " + dups);
    // Getting an old-style Enumeration:
    Enumeration e = Collections.enumeration(dups);
    Vector v = new Vector();
    while (e.hasMoreElements())
        v.addElement(e.nextElement());
    // Converting an old-style Vector
    // to a List via an Enumeration:
    ArrayList arrayList = Collections.list(v.elements());
    System.out.println("arrayList: " + arrayList);

}

From source file:gda.util.PackageMaker.java

/**
 * @param args/*w  w  w. j  a  va2 s. c  o  m*/
 */
public static void main(String args[]) {
    String destDir = null;
    if (args.length == 0)
        return;
    String filename = args[0];
    if (args.length > 1)
        destDir = args[1];
    try {
        ClassParser cp = new ClassParser(filename);
        JavaClass classfile = cp.parse();
        String packageName = classfile.getPackageName();
        String apackageName = packageName.replace(".", File.separator);
        if (destDir != null)
            destDir = destDir + File.separator + apackageName;
        else
            destDir = apackageName;
        File destFile = new File(destDir);
        File existFile = new File(filename);
        File parentDir = new File(existFile.getAbsolutePath().substring(0,
                existFile.getAbsolutePath().lastIndexOf(File.separator)));
        String allFiles[] = parentDir.list();
        Vector<String> selectedFiles = new Vector<String>();
        String toMatch = existFile.getName().substring(0, existFile.getName().lastIndexOf("."));
        for (int i = 0; i < allFiles.length; i++) {
            if (allFiles[i].startsWith(toMatch + "$"))
                selectedFiles.add(allFiles[i]);
        }
        FileUtils.copyFileToDirectory(existFile, destFile);
        Object[] filestoCopy = selectedFiles.toArray();
        for (int i = 0; i < filestoCopy.length; i++) {
            FileUtils.copyFileToDirectory(new File((String) filestoCopy[i]), destFile);
        }
    }

    catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.eclipse.swt.snippets.Snippet154.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 154");
    shell.setLayout(new FillLayout());

    Composite composite = new Composite(shell, SWT.NO_BACKGROUND | SWT.EMBEDDED);

    /*//from   ww  w .j ava  2s  .  c om
    * Set a Windows specific AWT property that prevents heavyweight
    * components from erasing their background. Note that this
    * is a global property and cannot be scoped. It might not be
    * suitable for your application.
    */
    try {
        System.setProperty("sun.awt.noerasebackground", "true");
    } catch (NoSuchMethodError error) {
    }

    /* Create and setting up frame */
    Frame frame = SWT_AWT.new_Frame(composite);
    Panel panel = new Panel(new BorderLayout()) {
        @Override
        public void update(java.awt.Graphics g) {
            /* Do not erase the background */
            paint(g);
        }
    };
    frame.add(panel);
    JRootPane root = new JRootPane();
    panel.add(root);
    java.awt.Container contentPane = root.getContentPane();

    /* Creating components */
    int nrows = 1000, ncolumns = 10;
    Vector<Vector<String>> rows = new Vector<>();
    for (int i = 0; i < nrows; i++) {
        Vector<String> row = new Vector<>();
        for (int j = 0; j < ncolumns; j++) {
            row.addElement("Item " + i + "-" + j);
        }
        rows.addElement(row);
    }
    Vector<String> columns = new Vector<>();
    for (int i = 0; i < ncolumns; i++) {
        columns.addElement("Column " + i);
    }
    JTable table = new JTable(rows, columns);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.createDefaultColumnsFromModel();
    JScrollPane scrollPane = new JScrollPane(table);
    contentPane.setLayout(new BorderLayout());
    contentPane.add(scrollPane);

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:com.intel.cosbench.driver.random.RangeIntGenerator.java

public static void main(String[] args) {
    final String pattern = "r(50,100)";
    final int all = 5;
    int i = 0;/*from w w w. ja va2s .  co m*/
    Vector<TestThread> threads = new Vector<TestThread>();
    RangeIntGenerator gen = RangeIntGenerator.parse(pattern);

    for (i = 0; i < all; i++) {
        TestThread thread = new TestThread(gen, i + 1, all);
        threads.add(thread);
        thread.start();
    }

    try {
        for (i = 0; i < all; i++) {
            threads.elementAt(i).join();
        }
    } catch (InterruptedException ie) {
        ie.printStackTrace();
    }
}

From source file:com.intel.cosbench.driver.generator.RangeIntGenerator.java

public static void main(String[] args) {
    final String pattern = "r(51,1000)";
    final int all = 5;
    int i = 0;/* w w  w. ja v a2  s .co  m*/
    Vector<TestThread> threads = new Vector<TestThread>();
    RangeIntGenerator gen = RangeIntGenerator.parse(pattern);

    for (i = 0; i < all; i++) {
        TestThread thread = new TestThread(gen, i + 1, all);
        threads.add(thread);
        thread.start();
    }

    try {
        for (i = 0; i < all; i++) {
            threads.elementAt(i).join();
        }
    } catch (InterruptedException ie) {
        ie.printStackTrace();
    }
}