Example usage for java.util ArrayList get

List of usage examples for java.util ArrayList get

Introduction

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

Prototype

public E get(int index) 

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:loci.apps.SlideScannerImport.MiniBioformatsTool.java

public static void attachROIStoImage(ImagePlus imp, ArrayList<ArrayList<Float>> vertices) {

    imp.deleteRoi();/*from   w  ww. ja  v a  2 s . c  om*/

    //this is just for visually creating ROIs on the image, assuming vertices is list of <x,y> coordinates and there are equal 
    //   number of x and y points (if there aren't, then vertices weren't generated properly)
    int npoints = vertices.get(0).size();
    float[] x = new float[npoints], y = new float[npoints];

    for (int i = 0; i < npoints; i++) {
        x[i] = vertices.get(0).get(i).floatValue();
        y[i] = vertices.get(1).get(i).floatValue();
    }
    imp.setRoi((new PolygonRoi(x, y, Roi.POLYGON)));
    imp.show();
}

From source file:mt.LengthDistribution.java

public static void WriteLengthdistroFile(ArrayList<File> AllMovies, XYSeries counterseries, int framenumber) {

    try {/* w  ww.jav a2  s . com*/

        File ratesfile = new File(AllMovies.get(0).getParentFile() + "//" + "Length-Distribution At T " + " = "
                + framenumber + ".txt");

        if (framenumber == 0)
            ratesfile = new File(AllMovies.get(0).getParentFile() + "//" + "Mean Length-Distribution" + ".txt");

        FileWriter fw = new FileWriter(ratesfile);

        BufferedWriter bw = new BufferedWriter(fw);

        bw.write("\tLength(real units) \tCount\n");

        for (int index = 0; index < counterseries.getItems().size(); ++index) {

            double Count = counterseries.getX(index).doubleValue();
            double Length = counterseries.getY(index).doubleValue();

            bw.write("\t" + Length + "\t" + "\t" + Count + "\t" + "\n");

        }

        bw.close();
        fw.close();

    }

    catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:module.siadap.domain.wrappers.SiadapYearWrapper.java

public static SiadapYearWrapper getCurrentYearOrLatestAvailableWrapper() {
    SiadapYearWrapper siadapYearWrapper = null;
    ArrayList<Integer> yearsWithConfigs = SiadapYearsFromExistingSiadapConfigurations
            .getYearsWithExistingConfigs();
    if (yearsWithConfigs.contains(new Integer(new LocalDate().getYear()))) {
        int year = new LocalDate().getYear();
        siadapYearWrapper = new SiadapYearWrapper(year);
    } else {//from w  w w  .ja  v  a 2  s  .c om
        siadapYearWrapper = new SiadapYearWrapper(yearsWithConfigs.get(yearsWithConfigs.size() - 1));
    }

    return siadapYearWrapper;

}

From source file:be.ac.ucl.lfsab1509.llncampus.ADE.java

/**
 * Fetch information about courses which codes are given as parameter.
 * //from  w ww.j  a va  2 s .  com
 * @param code
 *            Code of courses to fetch, separated by comma (e.g. "lelec1530,lfsab1509").
 * @param weeks
 *            Week numbers, separated by comma (e.g. "0,1,2,3,42").
 * @return An ArrayList of Events or null if failure.
 */
public static ArrayList<Event> getInfo(final String code, final String weeks) {
    String html = ""; // A long string containing all the HTML
    ArrayList<Event> events = new ArrayList<Event>();
    if (!connectADE(code, weeks)) {
        return null;
    }
    try {
        HttpClient client = ExternalAppUtility.getHttpClient();
        HttpGet request = new HttpGet(SERVER_URL + INFO_PATH);
        HttpResponse response = client.execute(request);

        html = EntityUtils.toString(response.getEntity());

        String table = HTMLAnalyser.getTagsContent(html, "table").get(0);
        ArrayList<String> lines = HTMLAnalyser.getTagsContent(table, "tr");

        // Skip the 2 header lines.
        for (int i = 2; i < lines.size(); i++) {
            ArrayList<String> cells = HTMLAnalyser.getTagsContent(lines.get(i), "td");

            String date = HTMLAnalyser.removeHTMLTag(cells.get(0));
            String beginHour = HTMLAnalyser.removeHTMLTag(cells.get(2));
            String duration = HTMLAnalyser.removeHTMLTag(cells.get(3));

            Event event = new Event(date, beginHour, duration);
            event.addDetail("trainees", HTMLAnalyser.removeHTMLTag(cells.get(6)));
            event.addDetail("trainers", HTMLAnalyser.removeHTMLTag(cells.get(7)));
            event.addDetail("room", HTMLAnalyser.removeHTMLTag(cells.get(8)));
            event.addDetail("course", HTMLAnalyser.removeHTMLTag(cells.get(9)));
            event.addDetail("activity_name", HTMLAnalyser.removeHTMLTag(cells.get(1)));
            events.add(event);
        }
    } catch (Exception e) {
        Log.e("ADE.java", "Error with connection or analysis of HTML : " + e.getMessage());
        e.printStackTrace();
        return null;
    }
    return events;
}

From source file:com.nuance.expertassistant.ContentCrawler.java

public static void crawl(String URL, int maxdepth) {

    final ArrayList<String> URLList1 = new ArrayList<String>();
    URLList1.addAll(listURLs(URL, 1));

    if (maxdepth == 1) {
        return;/*w  ww  .  j  av a  2 s. co m*/
    }

    final ArrayList<String> URLList2 = new ArrayList<String>();

    for (int i = 0; i < URLList1.size(); i++) {
        URLList2.addAll(listURLs(URLList1.get(i), 2));
    }

    if (maxdepth == 2) {
        return;
    }

    final ArrayList<String> URLList3 = new ArrayList<String>();

    for (int i = 0; i < URLList2.size(); i++) {
        URLList3.addAll(listURLs(URLList2.get(i), 3));
    }

    if (maxdepth == 3) {
        return;
    }

    final ArrayList<String> URLList4 = new ArrayList<String>();

    for (int i = 0; i < URLList3.size(); i++) {
        URLList4.addAll(listURLs(URLList3.get(i), 4));
    }

    if (maxdepth == 4) {
        return;
    }

    final ArrayList<String> URLList5 = new ArrayList<String>();

    for (int i = 0; i < URLList4.size(); i++) {
        URLList5.addAll(listURLs(URLList4.get(i), 5));
    }

    if (maxdepth == 5) {
        return;
    }

    return;

}

From source file:jog.my.memory.gcm.ServerUtilities.java

/**
 * Convert images to the string representation
 * @param pics - pictures to send//from   w w  w  .jav  a  2  s  . c o m
 * @return arraylist of string representation of pictures
 */
public static byte[] convertPhotosToByteRepresentation(ArrayList<Picture> pics) {
    ArrayList<byte[]> listPhotos = new ArrayList<>();
    for (int i = 0; i < pics.size(); i++) {
        String stringEncodedImage = Base64.encodeToString(pics.get(i).getmImageAsByteArray(), Base64.DEFAULT);
        listPhotos.add(pics.get(i).getmImageAsByteArray());
    }
    return listPhotos.get(0);
}

From source file:Main.java

private static ArrayList<ArrayList> sortObjectArrayListSimpleMaster(ArrayList listIn, String paramName) {
    ArrayList<ArrayList> answer = new ArrayList<ArrayList>();
    ArrayList newList = new ArrayList();
    ArrayList<Integer> indices = new ArrayList<Integer>();
    try {/*from w  ww .j a va 2s  .  c om*/
        if (listIn.size() > 0) {
            Class<?> c = listIn.get(0).getClass();
            Field f = c.getDeclaredField(paramName);
            f.setAccessible(true);
            Class<?> t = f.getType();
            Double dd = new Double(14);
            Float ff = new Float(14);
            Integer ii = new Integer(14);
            Map sortedPos = new LinkedHashMap();
            Map sortedNeg = new LinkedHashMap();
            Map unsorted = new LinkedHashMap();
            int indexCount = 0;
            long count = 0;
            if (t.isPrimitive()) {
                for (Object thisObj : listIn) {
                    Object o = f.get(thisObj);
                    double d = 0;
                    if (t.getName().equals("char")) {
                        d = (int) ((Character) o);
                    } else if (t.isInstance(dd))
                        d = (Double) o;
                    else if (t.isInstance(ff))
                        d = (Float) o;
                    else if (t.isInstance(ii))
                        d = (Integer) o;
                    else
                        d = new Double(o.toString());

                    boolean isNegative = false;

                    if (d < 0) {
                        isNegative = true;
                        d = Math.abs(d);
                    }

                    String format = "%1$30f";
                    String newKey = String.format(format, d);
                    String format2 = "%1$20d";
                    String countString = String.format(format2, count);
                    newKey += "-" + countString;
                    if (isNegative) {
                        sortedNeg.put(newKey, thisObj);
                    } else {
                        sortedPos.put(newKey, thisObj);
                    }
                    unsorted.put(thisObj, indexCount);
                    count++;
                    indexCount++;
                }
                TreeMap<String, Object> resultPos = new TreeMap();
                resultPos.putAll(sortedPos);
                sortedPos = resultPos;
                TreeMap<String, Object> resultNeg = new TreeMap();
                resultNeg.putAll(sortedNeg);
                sortedNeg = resultNeg;
            } else if (t.isInstance(paramName)) {
                // System.out.println("is a string with value " + o);
                for (Object thisObj : listIn) {
                    String key = (String) (f.get(thisObj));
                    sortedPos.put(key + "-" + count, thisObj);
                    unsorted.put(thisObj, indexCount);
                    count++;
                    indexCount++;
                }
                TreeMap<String, Object> result = new TreeMap(String.CASE_INSENSITIVE_ORDER);
                result.putAll(sortedPos);
                sortedPos = result;
            }

            Iterator itNeg = sortedNeg.entrySet().iterator();
            while (itNeg.hasNext()) {
                Map.Entry pairs = (Map.Entry) itNeg.next();
                newList.add(pairs.getValue());
                itNeg.remove();
            }

            Collections.reverse(newList);

            Iterator itPos = sortedPos.entrySet().iterator();
            while (itPos.hasNext()) {
                Map.Entry pairs = (Map.Entry) itPos.next();
                Object obj = pairs.getValue();
                newList.add(obj);
                indices.add((Integer) unsorted.get(obj));
                itPos.remove();
            }
        }
    } catch (Exception e) {
        System.out
                .println("problem sorting list.  listIn.size(): " + listIn.size() + " and param: " + paramName);
        answer.add(newList);
        answer.add(indices);
        return answer;
    }
    answer.add(newList);
    answer.add(indices);
    return answer;
}

From source file:edu.illinois.ncsa.springdata.SpringData.java

/**
 * Check each field in object to see if it is already seen. This will modify
 * collections, lists and arrays as well as the fields in an object.
 * /*from www.j  a va  2s  .com*/
 * @param obj
 *            the object to be checked for duplicates.
 * @param seen
 *            objects that have already been checked.
 * @return the object with all duplicates removed
 */
private static <T> T removeDuplicate(T obj, Map<String, Object> seen) {
    if (obj == null) {
        return null;
    }
    if (obj instanceof AbstractBean) {
        String id = ((AbstractBean) obj).getId();
        if (seen.containsKey(id)) {
            return (T) seen.get(id);
        }
        seen.put(id, obj);

        // check all subfields
        for (Field field : obj.getClass().getDeclaredFields()) {
            if ((field.getModifiers() & Modifier.FINAL) == 0) {
                try {
                    field.setAccessible(true);
                    field.set(obj, removeDuplicate(field.get(obj), seen));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

    } else if (obj instanceof Collection<?>) {
        Collection col = (Collection) obj;
        ArrayList arr = new ArrayList(col);
        col.clear();
        for (int i = 0; i < arr.size(); i++) {
            Object x = removeDuplicate(arr.get(i), seen);
            col.add(x);
        }
    } else if (obj instanceof Map<?, ?>) {
        Map map = (Map) obj;
        ArrayList<Entry> arr = new ArrayList(map.entrySet());
        map.clear();
        for (int i = 0; i < arr.size(); i++) {
            Object k = removeDuplicate(arr.get(i).getKey(), seen);
            Object v = removeDuplicate(arr.get(i).getValue(), seen);
            map.put(k, v);
        }
    } else if (obj.getClass().isArray()) {
        Object[] arr = (Object[]) obj;
        for (int i = 0; i < arr.length; i++) {
            arr[i] = removeDuplicate(arr[i], seen);
        }
    }

    return obj;
}

From source file:kip.utils.PowerUtils.java

/**
 * Calculates the frequency from a packet
 * @param samples   Samples to calculate frequency on
 * @return          the frequency of the power
 *//*from ww w  . ja va  2 s.c o m*/
public static double getFrequency(int[] samples) {
    ArrayList<Integer> maximas = new ArrayList<Integer>();
    for (int i = 2; i < samples.length - 2; i++) {
        if ((samples[i] >= samples[i + 1]) && (samples[i] >= samples[i - 1]))
            if ((samples[i] > samples[i + 2]) && (samples[i] > samples[i - 2])) {
                if (samples[i] > 4) {
                    if (maximas.size() > 0) {
                        if (i - maximas.get(maximas.size() - 1) > 5) {
                            maximas.add(i);
                        }
                    } else {
                        maximas.add(i);
                    }
                }

            }
    }
    if (maximas.size() < 2) {
        return 0.0;
    }
    return 1500 * (1.0 / (maximas.get(1) - maximas.get(0)));
}

From source file:ch.unil.genescore.vegas.LinkageDisequilibrium.java

/** Compute correlation (LD) r values for the given snps (use snpCorrelation_ to avoid recomputing previous values) */
static public RealMatrix computeCorrelationMatrix(ArrayList<Snp> geneSnps) {

    // The correlation matrix for the given set of snps
    RealMatrix corr = MatrixUtils.createRealMatrix(geneSnps.size(), geneSnps.size());

    // For each snp pair
    for (int i = 0; i < geneSnps.size(); i++) {
        for (int j = i + 1; j < geneSnps.size(); j++) {
            Snp snp_i = geneSnps.get(i);
            Snp snp_j = geneSnps.get(j);

            double r = computeCorrelation(snp_i, snp_j);
            corr.setEntry(i, j, r);/* w  w w.  j  av a 2 s  .co m*/
            corr.setEntry(j, i, r);
        }
    }

    // Set diagonal to 1
    for (int i = 0; i < geneSnps.size(); i++)
        corr.setEntry(i, i, 1);

    return corr;
}