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:ch.unil.genescore.vegas.LinkageDisequilibrium.java

/** loads genotype form List into a DenseMatrix object. it also normalizes the data  and mean imputes*/
static public DenseMatrix loadGenotypeIntoDenseMatrix(ArrayList<Snp> geneSnps) {
    int numberOfSnps = geneSnps.size();
    int lengthOfGenotype = Snp.getGenotypeLength();
    double[][] dataArray = new double[lengthOfGenotype][numberOfSnps];
    double genotype;
    for (int j = 0; j < numberOfSnps; ++j) {
        Snp currentSnp = geneSnps.get(j);
        byte[] currentGenotype = currentSnp.getGenotypes();
        if (currentGenotype == null)
            throw new RuntimeException();
        for (int i = 0; i < lengthOfGenotype; ++i) {

            if (currentGenotype[i] == -9)
                genotype = currentSnp.getAlleleMean();
            else/* w  ww .j  a va2s  .  co m*/
                genotype = currentGenotype[i];
            dataArray[i][j] = (genotype - currentSnp.getAlleleMean()) / currentSnp.getAlleleSd();
        }
    }
    return new DenseMatrix(dataArray);
}

From source file:com.davis.crs.CreateCannedDataSet.java

/**
 * Write data objects to json file.//from   ww  w  .  ja va 2 s .  c o  m
 *
 * @param dataHolders the data holders
 * @param fileName    the file name
 * @throws IOException the io exception
 */
public static void writeDataObjectsToJsonFile(ArrayList<CRSEndpointResponse> dataHolders, String fileName)
        throws IOException {
    System.out.println("Size of the CRSEndpointResponse Array = " + dataHolders.size());
    File file = new File(outputDir);

    if (!file.exists()) {
        file.mkdirs();
    }

    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    String json = gson.toJson(dataHolders);
    File file1 = new File(outputDir + "/" + fileName);

    FileUtils.writeStringToFile(file1, json);
}

From source file:edu.illinois.cs.cogcomp.wsim.embedding.Embedding.java

public static double[] add(ArrayList<double[]> lis) {
    double[] sum = new double[lis.get(0).length];
    for (int i = 0; i < lis.size(); i++) {
        sum = add(sum, lis.get(i));/*from   w  w  w  .  j  av a2  s.  co  m*/
    }
    return sum;
}

From source file:Main.java

/**
 * Returns map values summary list with unique elements only.
 *
 * @param map map to process/*from w  w  w . ja  v a 2s . co  m*/
 * @param <K> key object type
 * @param <V> value object type
 * @return map values summary list with unique elements only
 */
public static <K, V> ArrayList<V> valuesSummaryList(final Map<K, List<V>> map) {
    final ArrayList<V> summary = new ArrayList<V>(0);
    for (final Map.Entry<K, List<V>> entry : map.entrySet()) {
        final List<V> list = entry.getValue();
        summary.ensureCapacity(summary.size() + list.size());
        for (final V value : list) {
            if (!summary.contains(value)) {
                summary.add(value);
            }
        }
    }
    return summary;
}

From source file:Main.java

public static void sortObjectArrayListsSimple(ArrayList masterList, String paramName, ArrayList... listsIn) {
    int count = masterList.size();
    for (ArrayList al : listsIn) {
        if (al.size() != count || count == 0) {
            System.out.println("counts of lists are not the same, did not sort");
            return;
        }/* w ww.j a v  a2 s .  co  m*/
    }
    ArrayList<ArrayList> result = sortObjectArrayListSimpleMaster(masterList, paramName);
    masterList.clear();
    for (Object o : result.get(0))
        masterList.add(o);
    //masterList = result.get(0);
    ArrayList[] orderedLists = new ArrayList[listsIn.length];
    for (int i = 0; i < listsIn.length; i++)
        orderedLists[i] = new ArrayList();
    for (int i = 0; i < result.get(1).size(); i++) {
        int index = (Integer) result.get(1).get(i);
        for (int j = 0; j < listsIn.length; j++) {
            orderedLists[j].add(listsIn[j].get(index));
        }
    }

    for (int i = 0; i < listsIn.length; i++) {
        listsIn[i].clear();
        for (int j = 0; j < orderedLists[i].size(); j++) {
            listsIn[i].add(orderedLists[i].get(j));
        }
    }
}

From source file:Main.java

public static String[] split(String s, char c, int limit) {
    if (s == null) {
        return null;
    }/*from   w w  w  .  j  ava  2s  . co  m*/
    ArrayList<Integer> pos = new ArrayList<Integer>();
    int i = -1;
    while ((i = s.indexOf((int) c, i + 1)) > 0) {
        pos.add(Integer.valueOf(i));
    }
    int n = pos.size();
    int[] p = new int[n];
    i = -1;
    for (int x : pos) {
        p[++i] = x;
    }
    if ((limit == 0) || (limit > n)) {
        limit = n + 1;
    }
    String[] result = new String[limit];
    if (n > 0) {
        result[0] = s.substring(0, p[0]);
    } else {
        result[0] = s;
    }
    for (i = 1; i < limit - 1; ++i) {
        result[i] = s.substring(p[i - 1] + 1, p[i]);
    }
    if (limit > 1) {
        result[limit - 1] = s.substring(p[limit - 2] + 1);
    }
    return result;
}

From source file:com.jennifer.ui.util.StringUtil.java

public static String join(ArrayList<String> result, String splitter) {
    StringBuilder b = new StringBuilder();
    b.append(result.get(0));//from ww  w . j a v a2  s .com

    for (int i = 1, len = result.size(); i < len; i++) {
        b.append(splitter).append(result.get(i));
    }

    return b.toString().trim();
}

From source file:ded.model.Inheritance.java

/** Return the value to which 'index' is mapped in 'integerToInheritance'. */
public static Inheritance fromJSONRef(ArrayList<Inheritance> integerToInheritance, long index)
        throws JSONException {
    if (0 <= index && index < integerToInheritance.size()) {
        return integerToInheritance.get((int) index);
    } else {/* w ww.j a  v a2  s  . c om*/
        throw new JSONException("invalid entity ref " + index);
    }
}

From source file:Main.java

public static <T> int floor(ArrayList<T> list, T key, Comparator<? super T> c) {
    if (c.compare(list.get(0), key) > 0) {
        return -1;
    }//  www.  j  a v  a 2  s .  co  m
    if (c.compare(list.get(list.size() - 1), key) <= 0) {
        return list.size() - 1;
    }
    int start = 0, end = list.size() - 1, res;
    T mid;
    while (start < end - 1) {
        mid = list.get((start + end) / 2);
        res = c.compare(mid, key);
        //            System.out.println("res = " + res);
        //            System.out.println("mid = " + mid);
        if (res > 0) {
            end = (start + end) / 2;
        } else {
            start = (start + end) / 2;
        }
        //            System.out.println("start = " + start);
        //            System.out.println("end = "+ end);
    }
    res = c.compare(list.get(end), key);
    if (res > 0) {
        return start;
    } else {
        if (res == 0) {
            return end;
        } else {
            return -1;
        }
    }

}

From source file:com.mycompany.asyncreq.Main.java

private static void writeToCSV(List<ArrayList<String>> csvInput, String csv) throws IOException {

    CSVWriter writer = null;//w  w w  .j  a  v  a  2  s. com

    try {
        writer = new CSVWriter(new FileWriter(csv));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    for (ArrayList<String> each : csvInput) {
        String[] eachTemp = each.toArray(new String[each.size()]);
        writer.writeNext(eachTemp);
    }

    writer.close();
}