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

/**
 * Returns a List of Lists: all combinations of the elements of the given
 * List./* w  w  w  . j  a  v  a  2 s .  c om*/
 *
 * @param maxCombinationSize combinations larger than this value are
 * discarded
 * @param mandatoryItem an item that all returned combinations must contain,
 * or null to leave unspecified
 */
public static List combinations(List original, int maxCombinationSize, Object mandatoryItem) {
    ArrayList combinations = new ArrayList();

    //Combinations are given by the bits of each binary number from 1 to 2^N
    for (int i = 1; i <= ((int) Math.pow(2, original.size()) - 1); i++) {
        ArrayList combination = new ArrayList();
        for (int j = 0; j < original.size(); j++) {
            if ((i & (int) Math.pow(2, j)) > 0) {
                combination.add(original.get(j));
            }
        }
        if (combination.size() > maxCombinationSize) {
            continue;
        }
        if ((mandatoryItem != null) && !combination.contains(mandatoryItem)) {
            continue;
        }
        combinations.add(combination);
    }

    return combinations;
}

From source file:Main.java

/**
 * Get an array of specific attributes for specific elements
 * in a Node tree. If the node is a Document, use the document
 * element as the starting point./*from   w  w  w  .  j  ava2s  .  co  m*/
 * @param node the top of the tree to search.
 * @param nodeName the element names to include in the search.
 * @param attrName the name of the attributes to include.
 * @return the array of attribute values natching the criteria.
 */
public static String[] getAttributeValues(Node node, String nodeName, String attrName) {
    if (node instanceof Document)
        node = ((Document) node).getDocumentElement();
    if (!(node instanceof Element))
        return new String[0];
    NodeList nodeList = ((Element) node).getElementsByTagName(nodeName);
    ArrayList list = new ArrayList();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Attr attr = ((Element) nodeList.item(i)).getAttributeNode(attrName);
        if (attr != null)
            list.add(attr.getValue());
    }
    String[] values = new String[list.size()];
    return (String[]) list.toArray(values);
}

From source file:SageCollegeProject.guideBox.java

public static void UpdateAllShowJsonFile() {
    System.out.println("Getting ready to read all guidebox data for shows.");
    ArrayList<guide_ShowObject> res = new ArrayList<>();
    ReadAllShowsFromWeb(res);/*from   w w  w  .  java2  s  .c  o m*/
    Gson gson = new GsonBuilder().create();
    String json = gson.toJson(res);
    System.out.println(res.size());
    WriteJsonToFile(json, AllShowsJsonFile);
    sagex.api.Configuration.SetServerProperty(guideboxUpdateProp,
            java.lang.String.valueOf(System.currentTimeMillis()));
}

From source file:Main.java

@SuppressWarnings("nls")
public static String[] getStringIdArray(String serializedTree) {
    ArrayList<String> ids = new ArrayList<String>();
    String[] values = serializedTree.split("[\\[\\],\"\\s]"); // Split on [ ] , or whitespace chars
    for (String idString : values) {
        if (!TextUtils.isEmpty(idString))
            ids.add(idString);// w w  w. ja va  2s. c om
    }
    return ids.toArray(new String[ids.size()]);
}

From source file:bb.mcmc.analysis.ConvergeStatUtils.java

public static <T> List<T> getSubList(ArrayList<T> list, int burnin) {
    List<T> subList = list.subList(burnin, list.size());
    return subList;
}

From source file:com.clust4j.algo.preprocess.impute.NearestNeighborImputation.java

private static double[] exclude(double[] vec, ArrayList<Integer> exclude) {
    final double[] comp = new double[vec.length - exclude.size()];
    final int n = vec.length;

    int j = 0;//from   w w w . j av a2  s  .c  om
    for (int i = 0; i < n; i++) {
        if (exclude.contains(i))
            continue;
        comp[j++] = vec[i];
    }

    return comp;
}

From source file:Main.java

/**
 * A helper method to get a String[] out of a fieldArray
 *
 * @param fields R.strings.class.getFields()
 * @return a String[] with the string ids we need
 *///from  w ww  .  ja  va 2  s  . c o  m
private static String[] getDefinedFonts(Context ctx, Field[] fields) {
    ArrayList<String> fieldArray = new ArrayList<String>();
    for (Field field : fields) {
        if (field.getName().contains("define_font_")) {
            fieldArray.add(getStringResourceByName(ctx, field.getName()));
        }
    }
    return fieldArray.toArray(new String[fieldArray.size()]);
}

From source file:Estadistica.java

/**
 * Metodo  multiple//from w ww .j  av a 2 s .  c  o  m
 * param  una lista de valores (xArrayList)
 * @return
 */
public static double multiple(ArrayList<Double> xArrayList) {
    double cal = 0;
    for (int i = 0; i < xArrayList.size(); i++) {
        cal += xArrayList.get(i);
    }
    return cal;
}

From source file:Utils.java

public static Element[] getElements(Document document, Element parent) {
    if (parent == null) {
        return new Element[] {};
    }/*from w w w .j a v  a  2  s . c  o m*/

    NodeList nl = parent.getChildNodes();
    ArrayList al = new ArrayList();

    for (int i = 0; i < nl.getLength(); i++) {
        Node n = nl.item(i);

        if (n instanceof Element) {
            al.add((Element) nl.item(i));
        }
    }

    Element[] ret = new Element[al.size()];
    Iterator it = al.iterator();
    int i = 0;
    while (it.hasNext()) {
        ret[i] = (Element) it.next();
        i++;
    }

    return ret;
}

From source file:Main.java

public static Element[] getElementsByName(Element parent, String name) {
    ArrayList resList = new ArrayList();
    NodeList nl = getNodeList(parent);
    for (int i = 0; i < nl.getLength(); i++) {
        Node nd = nl.item(i);//from   w  w w .j  av a  2s. c o m
        if (nd.getNodeName().equals(name)) {
            resList.add(nd);
        }
    }
    Element[] res = new Element[resList.size()];
    for (int i = 0; i < resList.size(); i++) {
        res[i] = (Element) resList.get(i);
    }
    logger.debug(parent.getNodeName() + "'s children of " + name + "'s num:" + res.length);
    return res;
}