Example usage for java.util Vector size

List of usage examples for java.util Vector size

Introduction

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

Prototype

public synchronized int size() 

Source Link

Document

Returns the number of components in this vector.

Usage

From source file:Main.java

/**
 *
 * @param vtData Vector/*from  ww  w. j a  va 2s.  co  m*/
 * @param iComboIndex int
 * @param iVectorIndex int
 * @param cbo JComboBox
 * @param vt Vector
 * @param bClear boolean
 * @param bHaveNull boolean
 * @throws Exception
 */
public static void fillValue(Vector vtData, int iComboIndex, int iVectorIndex, JComboBox cbo, Vector vt,
        boolean bClear, boolean bHaveNull) throws Exception {
    // Clear
    if (bClear) {
        vt.clear();
        cbo.removeAllItems();
    }

    // Add null value
    if (bHaveNull) {
        vt.addElement("");
        cbo.addItem("");
    }

    // Fill value
    for (int iRowIndex = 0; iRowIndex < vtData.size(); iRowIndex++) {
        Vector vtResultRow = (Vector) vtData.elementAt(iRowIndex);
        vt.addElement(vtResultRow.elementAt(iVectorIndex));
        cbo.addItem(vtResultRow.elementAt(iComboIndex));
    }
}

From source file:Main.java

public static String[] split(String original, String separator) {
    Vector nodes = new Vector();

    // Parse nodes into vector
    int index = original.indexOf(separator);
    while (index >= 0) {
        nodes.addElement(original.substring(0, index));
        original = original.substring(index + separator.length());
        index = original.indexOf(separator);
    }//from  www  .  jav a  2  s.co m
    // Get the last node
    nodes.addElement(original);

    // Create splitted string array
    String[] result = new String[nodes.size()];
    if (nodes.size() > 0) {
        for (int loop = 0; loop < nodes.size(); loop++)
            result[loop] = (String) nodes.elementAt(loop);
    }
    return result;
}

From source file:com.github.igor_kudryashov.utils.notes.NotesDocument.java

/**
 * As lotus.domino.Document.replaceItemValue() method modifies the value of the document Lotus
 * Notes, but only if the new value is different from existing
 *
 * @param item//w  w  w.  j  a v  a2 s. co  m
 *            - the lotus.Domino.Item object.
 * @param value
 *            - the new value of Notes item.
 * @return <code>true</code> if the value has been updated, <code>false</code> otherwise.
 * @throws NotesException
 */
@SuppressWarnings("unchecked")
public static boolean updateItemValue(Item item, Object value) throws NotesException {
    Vector<Object> vec = item.getValues();
    if (value.getClass().getName().contains("Vector")) {
        if (vec.equals(value)) {
            return false;
        } else {
            item.setValues((Vector<Object>) value);
        }
    } else {
        if (vec.size() == 1) {
            if (vec.firstElement() instanceof Number) {
                // because lotus.docmino.Item.getValues() alvays return java.util.Vector with
                // Double elements for Numeric items,
                // value parameter must be converted to Double
                MutableDouble md = new MutableDouble((Number) value);
                if (Double.compare((Double) vec.firstElement(), md.getValue()) == 0) {
                    return false;
                }
            } else if (vec.firstElement() instanceof String) {
                if (vec.firstElement().equals((String) value)) {
                    return false;
                }
            } else {
                if (vec.firstElement().equals(value)) {
                    return false;
                }
            }
        }
        vec = new Vector<Object>();
        vec.add(value);
        item.setValues(vec);
    }

    return true;

}

From source file:com.ery.ertc.estorm.util.DNS.java

/**
 * Returns all the host names associated by the provided nameserver with the address bound to the specified network interface
 * //from   w w  w  .  j  av  a2  s  .  c o m
 * @param strInterface
 *            The name of the network interface or subinterface to query (e.g. eth0 or eth0:0) or the string "default"
 * @param nameserver
 *            The DNS host name
 * @return A string vector of all host names associated with the IPs tied to the specified interface
 * @throws UnknownHostException
 */
public static String[] getHosts(String strInterface, String nameserver) throws UnknownHostException {
    String[] ips = getIPs(strInterface);
    Vector<String> hosts = new Vector<String>();
    for (int ctr = 0; ctr < ips.length; ctr++)
        try {
            hosts.add(reverseDns(InetAddress.getByName(ips[ctr]), nameserver));
        } catch (Exception e) {
        }

    if (hosts.size() == 0)
        return new String[] { InetAddress.getLocalHost().getCanonicalHostName() };
    else
        return hosts.toArray(new String[] {});
}

From source file:Main.java

/**
 * Retrieves the given DOM element's child elements with the specified name.
 * If name is null, all children are retrieved.
 *//*from www.  j  av a 2 s.  c  o m*/
public static Element[] getChildren(final Element el, final String name) {
    final Vector v = new Vector();
    final NodeList nodes = el.getChildNodes();
    final int len = nodes.getLength();
    for (int i = 0; i < len; i++) {
        final Node node = nodes.item(i);
        if (!(node instanceof Element))
            continue;
        final Element e = (Element) node;
        if (name == null || e.getTagName().equals(name))
            v.add(e);
    }
    final Element[] els = new Element[v.size()];
    v.copyInto(els);
    return els;
}

From source file:Main.java

/**
 * Method getTokenSeparatedStrings.//from   www . j a  v a2s  .  com
 * @param vector Vector
 * @param getter String
 * @param tokenizer String
 * @param tokenDelimiter String
 * @return String
 * @throws NoSuchMethodException
 * @throws IllegalAccessException
 * @throws Exception
 */
public static String getTokenSeparatedStrings(Vector vector, String getter, String tokenizer,
        String tokenDelimiter) throws NoSuchMethodException, IllegalAccessException, Exception {
    StringBuffer tokenSeparatedStrings = new StringBuffer("");
    String stringValue = null;
    Class[] clsParms = new Class[0];
    Object[] objParms = new Object[0];
    Object property;
    Method getterMethod = null;

    Object vectorElement = null;

    for (int i = 0; i < vector.size(); i++) {
        vectorElement = vector.elementAt(i);
        getterMethod = vectorElement.getClass().getMethod(getter, clsParms);
        property = getterMethod.invoke(vectorElement, objParms);

        if (property != null) {
            stringValue = property.toString();
        } else {
            stringValue = "";
        }

        tokenSeparatedStrings.append(tokenDelimiter + stringValue + tokenDelimiter);

        if (i < vector.size() - 1) {
            tokenSeparatedStrings.append(tokenizer);
        }
    }

    return tokenSeparatedStrings.toString();
}

From source file:com.legstar.codegen.tasks.SourceToXsdCobolTask.java

/**
 * Converts a URI into a package name. We assume a hierarchical,
 * server-based URI with the following syntax:
 * [scheme:][//host[:port]][path][?query][#fragment]
 * The package name is derived from host, path and fragment.
 * /*from w  w  w . ja v  a 2  s .c  om*/
 * @param namespaceURI the input namespace URI
 * @return the result package name
 */
public static String packageFromURI(final URI namespaceURI) {

    StringBuilder result = new StringBuilder();
    URI nURI = namespaceURI.normalize();
    boolean firstToken = true;

    /*
     * First part of package name is built from host with tokens in
     * reverse order.
     */
    if (nURI.getHost() != null && nURI.getHost().length() != 0) {
        Vector<String> v = new Vector<String>();
        StringTokenizer t = new StringTokenizer(nURI.getHost(), ".");
        while (t.hasMoreTokens()) {
            v.addElement(t.nextToken());
        }

        for (int i = v.size(); i > 0; i--) {
            if (!firstToken) {
                result.append('.');
            } else {
                firstToken = false;
            }
            result.append(v.get(i - 1));
        }
    }

    /* Next part of package is built from the path tokens */
    if (nURI.getPath() != null && nURI.getPath().length() != 0) {
        Vector<String> v = new Vector<String>();
        StringTokenizer t = new StringTokenizer(nURI.getPath(), "/");
        while (t.hasMoreTokens()) {
            v.addElement(t.nextToken());
        }

        for (int i = 0; i < v.size(); i++) {
            String token = v.get(i);
            /* ignore situations such as /./../ */
            if (token.equals(".") || token.equals("..")) {
                continue;
            }
            if (!firstToken) {
                result.append('.');
            } else {
                firstToken = false;
            }
            result.append(v.get(i));
        }
    }

    /* Finally append any fragment */
    if (nURI.getFragment() != null && nURI.getFragment().length() != 0) {
        if (!firstToken) {
            result.append('.');
        } else {
            firstToken = false;
        }
        result.append(nURI.getFragment());
    }

    /*
     * By convention, namespaces are lowercase and should not contain
     * invalid Java identifiers
     */
    String s = result.toString().toLowerCase();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
        Character c = s.charAt(i);
        if (Character.isJavaIdentifierPart(c) || c.equals('.')) {
            sb.append(c);
        } else {
            sb.append("_");
        }
    }
    return sb.toString();
}

From source file:esg.node.core.Resource.java

@SuppressWarnings("unchecked")
private static String[] split(String str, String delim) {
    // Use a Vector to hold the split strings.
    Vector v = new Vector();

    // Use a StringTokenizer to do the splitting.
    StringTokenizer tokenizer = new StringTokenizer(str, delim);
    while (tokenizer.hasMoreTokens()) {
        v.addElement(tokenizer.nextToken());
    }//from  w  ww.  j a  v  a 2s .  c  o  m

    String[] ret = new String[v.size()];
    v.copyInto(ret);
    return ret;
}

From source file:Main.java

/**
 * Method getTokenSeparatedStrings.//from w w w  . jav  a 2  s  .  com
 * @param vector Vector
 * @param getter String
 * @param tokenizer String
 * @param tokenDelimiter String
 * @return String
 * @throws NoSuchMethodException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static String getTokenSeparatedStrings(Vector vector, String getter, String tokenizer,
        String tokenDelimiter) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    StringBuffer tokenSeparatedStrings = new StringBuffer("");
    String stringValue = null;
    Class[] clsParms = new Class[0];
    Object[] objParms = new Object[0];
    Object property;
    Method getterMethod = null;

    Object vectorElement = null;

    for (int i = 0; i < vector.size(); i++) {
        vectorElement = vector.elementAt(i);
        getterMethod = vectorElement.getClass().getMethod(getter, clsParms);
        property = getterMethod.invoke(vectorElement, objParms);

        if (property != null) {
            stringValue = property.toString();
        } else {
            stringValue = "";
        }

        tokenSeparatedStrings.append(tokenDelimiter + stringValue + tokenDelimiter);

        if (i < vector.size() - 1) {
            tokenSeparatedStrings.append(tokenizer);
        }
    }

    return tokenSeparatedStrings.toString();
}

From source file:Main.java

public static NodeList getChildsByTagName(Element root, String name) {
    final Vector<Node> v = new Vector<Node>();
    NodeList nl = root.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node n = nl.item(i);/*from www  .j av a 2s.c  om*/
        if (n.getNodeType() == Element.ELEMENT_NODE) {
            Element e = (Element) n;
            if (name.equals("*") || e.getNodeName().equalsIgnoreCase(name))
                v.add(n);
        }
    }

    return new NodeList() {
        public Node item(int index) {
            if (index >= v.size() || index < 0)
                return null;
            else
                return v.get(index);
        }

        public int getLength() {
            return v.size();
        }
    };
}