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:DataCharts.Chart.java

private static PieDataset createPieDataset(ArrayList<YearData> locs) {
    DefaultPieDataset dataset = new DefaultPieDataset();

    for (int x = 0; x < locs.size(); x++) {
        for (int y = 0; y < 12; y++) {
            MonthData[] months = locs.get(x).getMonths();
            for (int z = 0; z < 12; z++) {
                if (months[y].getAreaCodeData().size() > z) {
                    dataset.setValue("" + months[y].getMonth().toString(),
                            months[y].getAreaCodeData().get(z).getAreaCode());
                }/*  w w w .  ja va 2  s . c o  m*/
            }
        }
    }
    for (int x = 0; x < locs.size(); x++) {
        ;
    }
    return dataset;
}

From source file:Estadistica.java

/**
 * Metodo  para calcular r/* w w w  . j  av  a2s.  c o m*/
 * param  dos listas de valores (xArrayList,ArrayList)
 * @return el valor de r
 */
public static double calR(ArrayList<Double> xArrayList, ArrayList<Double> yArrayList) {
    double cal = 0;
    cal = xArrayList.size() * multiple(xArrayList, yArrayList) - multiple(xArrayList) * multiple(yArrayList);
    double minus = 0;
    minus = xArrayList.size() * multiple(xArrayList, xArrayList) - multiple(xArrayList) * multiple(xArrayList);
    minus *= yArrayList.size() * multiple(yArrayList, yArrayList) - multiple(yArrayList) * multiple(yArrayList);
    cal = cal / Math.sqrt(minus);
    return cal;
}

From source file:ProcessLauncher.java

private static String[] toStringArray(ArrayList list) {
    String[] result = new String[list.size()];
    Iterator iter = list.iterator();
    int arrayIndex = 0;
    while (iter.hasNext()) {
        result[arrayIndex++] = iter.next().toString();
    }// ww  w  .  j  ava2s .  c o m
    return result;
}

From source file:com.espe.distribuidas.pmaldito.servidorbdd.operaciones.Archivo.java

/**
 * permite separar la lista de detalles en registros de listas
 *
 * @param valosCampos/*from   ww w. j a va2  s. c o  m*/
 * @return
 */
public static ArrayList<String> detalle(ArrayList<String> valosCampos) {
    int contador = 0;
    ArrayList<String> detalleParse = new ArrayList<>();
    while (contador < valosCampos.size()) {
        detalleParse.add(parsearCampos(valosCampos.subList(contador, contador + 5)));
        contador = contador + 5;
    }
    return detalleParse;
}

From source file:mlflex.helper.MathUtilities.java

/** Calculates the mean (average) value from a list of numeric values.
 *
 * @param values List of numeric values//from  ww  w.ja v a 2  s  .  com
 * @return Mean (average) value
 * @throws Exception
 */
public static double Mean(ArrayList<Double> values) throws Exception {
    if (values.size() == 0)
        throw new Exception("Cannot determine mean on an empty list.");

    return Sum(values) / (double) values.size();
}

From source file:Main.java

/**
 * Move an object in List down/*  w ww. j  a va  2 s  .  co m*/
 * 
 * @param list
 * @param key
 * @param keyMapper
 * @return
 */
public static <T, K> boolean moveDown(List<T> list, K key, Function<T, K> keyMapper, int n) {
    ArrayList<T> newList = new ArrayList<T>();
    boolean changed = false;
    int start = list.size() - 1;
    for (int i = start; i >= 0; i--) {
        T item = list.get(i);

        if (i != start && key.equals(keyMapper.apply(item))) {
            int posi = n;
            if (newList.size() < posi)
                posi = newList.size();
            newList.add(posi, item);
            changed = true;
        } else
            newList.add(0, item);
    }

    if (changed) {
        list.clear();
        list.addAll(newList);
        return true;
    }
    return false;
}

From source file:mlflex.MathUtility.java

/** Identifies the quartiles in a list of numbers.
 *
 * @param values Values to be tested//from   w  w  w . ja v a  2  s.com
 * @return An array with the lower quartile, median, and upper quartile
 * @throws Exception
 */
public static double[] Quartiles(ArrayList<Double> values) throws Exception {
    if (values.size() < 3)
        throw new Exception("This method is not designed to handle lists with fewer than 3 elements.");

    double median = Median(values);

    ArrayList<Double> lowerHalf = Lists.LessThan(values, median, true);
    ArrayList<Double> upperHalf = Lists.GreaterThan(values, median, true);

    return new double[] { Median(lowerHalf), median, Median(upperHalf) };
}

From source file:Estadistica.java

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

From source file:Main.java

public static String evalConcat(Node n, String delimiter, XPathExpression... exprs)
        throws XPathExpressionException {
    ArrayList<String> results = new ArrayList<String>();
    for (XPathExpression expr : exprs) {
        results.add(orEmptyStr(expr, n));
    }/* ww w  .java  2  s.c  o  m*/

    while (results.remove(""))
        ;

    String retn = "";

    for (String s : results) {
        retn += s;
        if (results.indexOf(s) != results.size() - 1) {
            retn += delimiter;
        }
    }

    return retn;
}

From source file:com.medlog.webservice.services.tone.ToneProcessorFactory.java

/**
 *
 * @param dbc// w  w w.  j  a  va 2  s. c o  m
 * @param vo
 * @return
 * @see PersonalityInsights
 * @see WatsonService
 * @see ToneAnalyzer
 * @see DiaryVO
 */
public static String execute(DbConnection dbc, DiaryVO vo) {
    ToneAnalysis tone = null;
    Profile profile = null;
    try {
        ToneAnalyzer service = new ToneAnalyzer(ToneAnalyzer.VERSION_DATE_2016_05_19, SETTINGS.WATSON_USER,
                SETTINGS.WATSON_PASS);
        PersonalityInsights insights = new PersonalityInsights(PersonalityInsights.VERSION_DATE_2016_10_19,
                SETTINGS.WATSON_USER, SETTINGS.WATSON_PASS);
        //            service.setUsernameAndPassword(SETTINGS.WATSON_USER, SETTINGS.WATSON_PASS);
        String txtToProcess = buildTextToAnalyze(vo);

        //            profile = insights.getProfile(buildPersonalityProfileOPtions(txtToProcess)).execute();
        tone = service.getTone(txtToProcess, null).execute();
        //            List<Behavior> b = profile.getBehavior();
        //            List<ConsumptionPreferences> cp = profile.getConsumptionPreferences();
        //            List<Trait> prof = profile.getNeeds();
        //            List<Trait> person = profile.getPersonality();
        //            List<Trait> val = profile.getValues();
        //            profile.getWarnings();

        System.out.println("com.medlog.webservice.services.tone.ToneProcessorFactory.execute()" + tone);
        ArrayList<Integer> counts = processTone(dbc, tone, vo.getId());
        int successes = counts.size();

        if (false && counts != null) {
            Collections.sort(counts);
            for (int count : counts) {
                if (count == EXECUTE_FAILED) {
                    successes--;
                }
                if (count > 0) {
                    break;
                }
            }
            System.out.printf(
                    "\ncom.medlog.webservice.services.tone.ToneProcessorFactory.execute() [%d / %d ] rows addded.\n+++++++++++++++++++++++++++++++++++++++++++++\n",
                    successes, counts.size());
        }
    } catch (UnauthorizedException | TooManyRequestsException | RequestTooLargeException
            | BadRequestException e) {
        e.printStackTrace();
    } catch (RuntimeException ee) {
        ee.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        return toS(
                new GsonBuilder().setPrettyPrinting().create()
                        .toJson(ToneCategory.builder().profile(profile).tone(tone).build()),
                tone == null ? "" : tone.toString() + "\n" + profile.toString());
    } catch (Exception e) {
        e.printStackTrace();
        return "";
    }
}