Example usage for java.util ArrayList size

List of usage examples for java.util ArrayList size

Introduction

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

Prototype

int size

To view the source code for java.util ArrayList size.

Click Source Link

Document

The size of the ArrayList (the number of elements it contains).

Usage

From source file:Main.java

public static String getTextElementValue(String elementName, Element parentElement, boolean showEmptyAsNull) {
    ArrayList<Node> childNodesWithTagName = getChildNodesWithTagName(elementName, parentElement);

    if (childNodesWithTagName.size() > 0) {
        Node childNode = childNodesWithTagName.get(0);
        String text = childNode.getFirstChild().getNodeValue().trim();

        return text.equals("") && showEmptyAsNull ? null : text;
    }/*from   w w  w.jav  a  2 s  .  c o m*/

    return null;
}

From source file:com.integryst.kdbrowser.PTHelpers.PTPropertyHelper.java

public static int getPropId(String propName) {
    ArrayList properties = PropertyHelper.getProperties(null);
    for (int x = 0; x < properties.size(); x++) {
        Property tempProp = (Property) properties.get(x);
        if (propName.equals(tempProp.getName()))
            return tempProp.getId();
    }//from   ww  w  . j  a  v a  2 s  .  c o  m
    return -1;
}

From source file:Main.java

/**
 * Given a list of coordinates, calculate the total distance travelled.
 *
 * @param gpsCoordArray ArrayList of Location objects. Users route
 * @return Integer total distance in meters.
 *//*from  w  w w . ja v  a2  s.c  o  m*/
public static int calculateTotalDistance(ArrayList<Location> gpsCoordArray) {
    int totalDistance = 0;

    for (int i = 1; i < gpsCoordArray.size(); i++) {
        totalDistance += getDistance(gpsCoordArray.get(i - 1), gpsCoordArray.get(i));
    }

    return totalDistance;
}

From source file:Main.java

public static String join(final ArrayList<String> array, String separator) {
    StringBuffer result = new StringBuffer();
    if (array != null && array.size() > 0) {
        for (String str : array) {
            result.append(str);/*from   w  w w  . ja  v  a2s  . c  o m*/
            result.append(separator);
        }
        result.delete(result.length() - 1, result.length());
    }
    return result.toString();
}

From source file:Main.java

public static String getAllListValue(ArrayList<String> data) {
    String value = "";
    if (data == null)
        return value;
    for (int i = 0; i < data.size(); i++) {
        value = value + data.get(i) + (i == data.size() - 1 ? "" : ",");
    }//from   w  ww  .  j  a  v  a  2  s . c o  m
    return value;
}

From source file:com.cprassoc.solr.auth.util.CommandLineExecutor.java

public static int execChain(ArrayList<String> cmds) {
    int exitValue = -1;
    try {// w  ww.j ava 2s.c o  m
        for (int i = 0; i < cmds.size(); i++) {
            exitValue = exec(cmds.get(i));
            if (exitValue > 0) {
                throw new IOException();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return exitValue;
}

From source file:Main.java

/**
 * Sarches for ressources that have to be downloaded and creates a list with all download links.
 *
 * @param node to check for download links
 * @return list with all found download links
 *///  w w  w  . ja v a  2  s .c  o  m
private static ArrayList<String> findUrls(Node node) {

    int type = node.getNodeType();
    ArrayList<String> result = new ArrayList<>();
    String temp = null;
    NamedNodeMap atts = node.getAttributes();
    Log.i(TAG, "parsing for ressources.  node: " + node.getNodeName() + " value: " + node.getNodeValue()
            + " atts length: " + atts.getLength() + "type: " + type);
    switch (type) {
    //Element
    case Node.ELEMENT_NODE:
        //TODO: This method is stupid. It just looks for
        // attributes named ressourcepath. What if we have to download several ressources?

        for (int j = 0; j < atts.getLength(); j++) {
            Log.i(TAG, "atts: " + atts.item(j).getNodeName() + " value: " + atts.item(j).getNodeValue());
            temp = atts.item(j).getNodeValue();

            if (temp != null) {
                result.add(temp);
                Log.i(TAG, "added path: " + temp);
            }

            Log.i(TAG, "parent node:" + node.getParentNode().getNodeName());
            Element parent = (Element) node.getParentNode();
            parent.setAttribute("TESTITEST", "dllink");

        }
        // get the pages, means the children
        for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
            ArrayList<String> childres = findUrls(child);
            if (childres.size() > 0) {
                result.addAll(childres);
            }
        }
        break;
    }
    return result;
}

From source file:mongodb.MongoUtils.java

public static Document ListToDocument(ArrayList<Object> liste, ArrayList<Colonne> colonnes) {
    Document resultat = new Document();
    for (int i = 0; i < colonnes.size(); i++) {
        construct(resultat, colonnes.get(i).getNom(), liste.get(i));
    }/* w w  w  . j ava 2s .co  m*/

    return resultat;
}

From source file:Main.java

public static ArrayList<Integer> intersection(ArrayList<Integer> arrayList1, ArrayList<Integer> arrayList2) {
    ArrayList<Integer> intersectionList = new ArrayList<Integer>(
            arrayList1.size() > arrayList2.size() ? arrayList1.size() : arrayList2.size());
    intersectionList.addAll(arrayList1);
    intersectionList.retainAll(arrayList2);
    return intersectionList;
}

From source file:Main.java

/**
 * returns a P with the value of the specifed attribute of the specifed tags
 * /*from  w w w.  j  a  va  2s  .  c om*/
 * @param doc
 * @param strTagName
 * @param strAttribute
 * @return
 */
public static Properties getPropertiesFromArrayList(ArrayList<String> al) {

    Properties pr = new Properties();

    // cycles on all of them
    for (int i = 0; i < al.size(); i++) {

        pr.setProperty(al.get(i), "");
    }

    return pr;
}