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:Main.java

/**
 * Extracts attribute names from tag string.
 * //w w w .  j  a  v a2 s. c  om
 * @param tag
 *            whole tag name
 * @return A vector with all attribute names
 * @deprecated use TagClass.getAttrList() instead
 */
public static Vector getAttributeNames(String tag) {
    Vector names = new Vector();
    int start = tag.indexOf(' '); /* avoid name of this tag */
    int end;
    while (start != -1) {
        end = tag.indexOf('=', start + 1);
        if (end == -1) {
            break;
        }
        names.addElement(tag.substring(start + 1, end));
        start = tag.indexOf('"', end + 1);
        if (start == -1) {
            break;
        }
        start = tag.indexOf('"', start + 1);
        if (start == -1) {
            break;
        }
        start = tag.indexOf(' ', start + 1);
    }
    return names;
}

From source file:Main.java

private static Vector getVectorPathFromNode(Node node) {
    Vector path = new Vector();

    while (node != null) {
        path.insertElementAt(node, 0);/*from  w  w  w.j a  v  a2 s .  c  o m*/
        node = node.getParentNode();
    }

    return path;
}

From source file:Main.java

/**
 * The method return list of child elements.
 * /*from ww w .  ja  va2  s  .co m*/
 * @param parent an org.w3c.dom.Element object.
 * @return list of child elements.
 */
static public Vector getChildElements(Element parent) {
    if (parent == null)
        throw new IllegalArgumentException("Element can not be NULL");

    Vector vect = new Vector();
    Element elem = getFirstChild(parent);
    while (elem != null) {
        vect.add(elem);
        elem = getNextSibling(elem);
    }
    return vect;
}

From source file:Main.java

/**
 * J2ME implementation of String.split(). Is very fragile.
 * /*from w w w  .  j  a v  a 2s.c o m*/
 * @param string
 * @param separator
 * @return
 */
public static String[] stringSplit(String string, char separator) {
    Vector parts = new Vector();
    int start = 0;
    for (int i = 0; i <= string.length(); i++) {
        if ((i == string.length()) || (string.charAt(i) == separator)) {
            if (start == i) {
                // no data between separators
                parts.addElement("");
            } else {
                // data between separators
                String part = string.substring(start, i);
                parts.addElement(part);
            }
            // start of next part is the char after this separator
            start = i + 1;
        }
    }
    // return as array
    String[] partsArray = new String[parts.size()];
    for (int i = 0; i < partsArray.length; i++) {
        partsArray[i] = (String) parts.elementAt(i);
    }
    return partsArray;
}

From source file:Main.java

public static Vector<byte[]> split(int command, byte[] dataToTransport, int chunksize) {
    Vector<byte[]> result = new Vector<byte[]>();
    if (chunksize < 8) {
        throw new RuntimeException("Invalid chunk size");
    }//  w ww. ja  v  a 2 s. c  om
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int remaining_length = dataToTransport.length;
    int offset = 0;
    int seq = 0;
    boolean firstPacket = true;

    while (remaining_length > 0) {
        int l = 0;
        if (!firstPacket) {
            baos.write(seq);
            l = Math.min(chunksize - 1, remaining_length);
        } else {
            baos.write(command);
            // first packet has the total transport length
            baos.write(remaining_length >> 8);
            baos.write(remaining_length);
            l = Math.min(chunksize - 3, remaining_length);
        }
        baos.write(dataToTransport, offset, l);
        remaining_length -= l;
        offset += l;
        result.add(baos.toByteArray());
        baos.reset();
        if (!firstPacket) {
            seq++;
        }
        firstPacket = false;
    }

    return result;
}

From source file:Main.java

public static void cosineSimilarityCW() {
    Iterator<Integer> ids = CommentWordCount.keySet().iterator();
    while (ids.hasNext()) {
        int com_id = ids.next();
        Set<String> words1;
        words1 = CommentWordCount.get(com_id).keySet();
        Iterator<Integer> com_iter = CommentWordCount.keySet().iterator();
        while (com_iter.hasNext()) {
            int id = com_iter.next();
            if (com_id < id) {
                Set<String> words2;
                words2 = CommentWordCount.get(id).keySet();

                Vector<Integer> vecA = new Vector<Integer>();
                Vector<Integer> vecB = new Vector<Integer>();

                Iterator<String> w1 = words1.iterator();
                Iterator<String> w2 = words2.iterator();

                HashSet<String> imp = new HashSet<String>();
                while (w1.hasNext()) {
                    String s = w1.next();
                    imp.add(s);/*from www.java  2s  . c o  m*/
                }
                while (w2.hasNext()) {
                    String s = w2.next();
                    imp.add(s);
                }
                for (String s : imp) {
                    if (CommentWordCount.get(com_id).containsKey(s)) {
                        vecA.add(CommentWordCount.get(com_id).get(s));
                    } else
                        vecA.add(0);

                    if (CommentWordCount.get(id).containsKey(s)) {
                        vecB.add(CommentWordCount.get(id).get(s));
                    } else
                        vecB.add(0);
                }

                //System.out.println("Size : A"+vecA.size()+" Size: B"+vecB.size()+"maxLen:"+maxlength);
                double similarity;
                int product = 0;
                double sumA = 0;
                double sumB = 0;
                for (int i = 0; i < vecA.size(); i++) {
                    product += vecA.elementAt(i) * vecB.elementAt(i);
                    sumA += vecA.elementAt(i) * vecA.elementAt(i);
                    sumB += vecB.elementAt(i) * vecB.elementAt(i);
                }
                sumA = Math.sqrt(sumA);
                sumB = Math.sqrt(sumB);
                similarity = product / (sumA * sumB);
                similarity = Math.acos(similarity) * 180 / Math.PI;
                //System.out.println("Result "+com_id+" "+id+" :"+similarity);

                if (similarity < 75) {
                    //System.out.println("Result "+com_id+" "+id);
                    if (Topic.containsKey(com_id)) {
                        int val = Topic.get(com_id);
                        val++;
                        Topic.put(com_id, val);
                    } else
                        Topic.put(com_id, 1);
                    if (Topic.containsKey(id)) {
                        int val = Topic.get(id);
                        val++;
                        Topic.put(id, val);
                    } else
                        Topic.put(id, 1);
                }

            }
        }
    }
}

From source file:Main.java

/**
 * Searches parent node for matching child nodes and collects and returns
 * their values./*from  w  w  w.j  a va  2 s.  c  o  m*/
 *
 * @param node     The parent node
 * @param elemName The matching child node element name
 * @return List of node values
 */
public static Enumeration getChildrenNodeValues(Node node, String elemName) {
    Vector vect = new Vector();
    NodeList nl = node.getChildNodes();
    int n = nl.getLength();
    for (int i = 0; i < n; i++) {
        Node nd = nl.item(i);
        if (nd.getNodeName().equals(elemName)) {
            Node child = nd.getFirstChild();
            if (child == null) {
                vect.add("");
            } else {
                vect.add(child.getNodeValue());
            }
        }
    }
    return vect.elements();
}

From source file:Main.java

public static <T> List<T> toList(T[] array) {

    if (array == null)
        return new Vector<T>();

    List<T> list = new ArrayList<T>(array.length);

    for (T t : array)
        list.add(t);//from  w  ww  . java2s  . co  m

    return list;
}

From source file:Main.java

public static Vector copy(Vector v) {
    Vector copy = new Vector();
    synchronized (v) {
        for (Enumeration en = v.elements(); en.hasMoreElements();) {
            copy.addElement(en.nextElement());
        }/*  w  w w  .  jav  a2 s.  co m*/
    }
    return copy;
}

From source file:Main.java

Main(String title) {
    super(title);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Vector v = new Vector();
    v.add("A");// www .ja va  2 s .c  om
    v.add("B");
    v.add("C");
    JComboBox jcb = new JComboBox(v);

    getContentPane().add(jcb);

    setSize(200, 50);
    setVisible(true);
}