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:com.piggate.sdk.PiggateInfo.java

private static void registryInfo(ArrayList<PiggateInfo> infos) {

    ArrayList<PiggateInfo> _new_registry = new ArrayList<PiggateInfo>();
    Date date = new Date();
    PiggateInfo info;/*from  w  ww .j  a  v a2 s .c om*/

    for (int x = 0; x < infos.size(); x++) {
        info = infos.get(x);
        info.setLastCall(date);
        int index = internal_info.indexOf(info);
        if (index >= 0) {
            internal_info.remove(index);
        }
        internal_info.add(info);
    }

    for (int x = 0; x < internal_info.size(); x++) {
        info = internal_info.get(x);
        if (Piggate.getDateDiff(info.getLastCall(), date, TimeUnit.SECONDS) <= 35) {
            _new_registry.add(info);
        }
    }
    internal_info = _new_registry;
}

From source file:Estadistica.java

/**
 * Metodo calular sigma//from  w  w  w . j a v a 2s.  co  m
 * param  dos listas de valores, dos valores double double
 * @return sigma
 */
public static double getSigma(ArrayList<Double> xArrayList, ArrayList<Double> yArrayList, double b0,
        double b1) {
    ArrayList<Double> cal = new ArrayList<Double>();
    for (int i = 0; i < xArrayList.size(); i++) {
        cal.add(yArrayList.get(i) - b0 - b1 * xArrayList.get(i));
    }
    return Math.sqrt(multiple(cal, cal) / (xArrayList.size() - 2));
}

From source file:edu.lafayette.metadb.model.dataman.DataImporter.java

/**
 * Import a list of data into a project for one item.
 * @param projectName The destination project.
 * @param data Array of data strings.//  w  w w .java  2 s.  c o  m
 * @param attrList A list of attributes associated with the data. The entries in the data array should be ordered in the same way as this list.
 * @param itemNumber The item number which is being updated.
 * @param replaceEntity Flag indicating whether HTML entity codes should be unescaped on import.
 * @return true if the import completed, false otherwise.
 */
private static boolean importData(String projectName, String[] data, ArrayList<AdminDescAttribute> attrList,
        int itemNumber, boolean replaceEntity) {
    if (data == null)
        return false;

    try {
        for (int i = 0; i < attrList.size(); i++) {
            AdminDescAttribute attribute = attrList.get(i);
            String filteredData = (replaceEntity ? StringEscapeUtils.unescapeHtml(data[i]) : data[i]);
            if (!AdminDescDataDAO.updateAdminDescData(projectName, itemNumber, attribute.getElement(),
                    attribute.getLabel(), filteredData))
                throw new Exception("Cannot update data: " + projectName + " " + itemNumber + " "
                        + attribute.getElement() + " " + attribute.getLabel() + " " + filteredData);

        }
    } catch (Exception e) {
        MetaDbHelper.logEvent(e);
        return false;
    }

    return true;

}

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 ww  .ja  v a 2 s . c  om*/
            }
        }
    }
    for (int x = 0; x < locs.size(); x++) {
        ;
    }
    return dataset;
}

From source file:Main.java

public static int[] randNum(int num, int min, int max) {
    ArrayList<Integer> list = new ArrayList<Integer>();
    Random rand = new Random();
    while (true) {
        int rm = (rand.nextInt(max - min) + min);
        if (!list.contains(rm)) {
            list.add(rm);//from www.j  a v a  2s.com
            if (list.size() >= num)
                break;
        }
    }
    int result[] = new int[num];
    for (int i = 0; i < list.size(); i++) {
        result[i] = list.get(i);
    }
    return result;
}

From source file:com.predic8.membrane.core.util.TextUtil.java

public static String toEnglishList(String conjuction, String... args) {
    ArrayList<String> l = new ArrayList<String>();
    for (String arg : args)
        if (arg != null && arg.length() > 0)
            l.add(arg);/* w w w.  j ava 2 s.  c  o m*/
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < l.size(); i++) {
        sb.append(l.get(i));
        if (i == l.size() - 2) {
            sb.append(" ");
            sb.append(conjuction);
            sb.append(" ");
        }
        if (i < l.size() - 2)
            sb.append(", ");
    }
    return sb.toString();
}

From source file:ExifUtils.ExifReadWrite.java

public static File createXmp(File file) {
    String[] commandAndOptions = { "exiftool", file.getName(), "-o", file.getName() + ".xmp" };
    ArrayList<String> result = exifTool(commandAndOptions, file.getParentFile());
    if (result.get(0).endsWith("files created"))
        return new File(file.getAbsolutePath() + ".xmp");
    return null;/*from www  .  j  a va  2 s.  c  o m*/
}

From source file:StringUtils.java

/**
 * Parses a comma-seperated-list into an array;
 * /*from  w ww.  j  a  v  a  2s.c o m*/
 * @param csl
 * @return
 */
public static String[] cslToArray(String csl) {
    if (csl == null) {
        return null;
    }
    ArrayList list = new ArrayList();
    String[] vals = csl.split(",");
    for (int i = 0; i < vals.length; i++) {
        String val = vals[i].trim();
        if (val.length() > 0) {
            list.add(val);
        }
    }
    String[] sl = new String[list.size()];
    for (int i = 0; i < sl.length; i++) {
        sl[i] = (String) list.get(i);
    }
    return sl;
    // seems GWT compiler dont like this.....
    //return (String[]) list.toArray(new String[list.size()]);
}

From source file:com.baidu.cafe.local.NetworkUtils.java

/**
 * invoked 100 times costs 4800ms on Nexus One
 * //from ww w  . j a  v a2s . co m
 * @param packageName
 * @param mode
 * @return
 */
private static int getPackageTraffic(String packageName, String mode) {
    if ((!MODE_RCV.equals(mode)) && (!MODE_SND.equals(mode))) {
        print("mode invaild:" + mode);
        return -1;
    }

    int traffic = 0;
    ArrayList<Integer> pids = getPidsByPackageName(packageName);
    if (pids.size() < 1) {
        print("pids.size() < 1;get pids by [" + packageName + "] failed");
        return -1;
    }
    int pid = pids.get(0);

    if (Build.VERSION.SDK_INT >= 14) {// API Level: 14. Android 4.0
        int uid = getUidByPid(pid);
        if (-1 == uid) {
            print("-1 == uid");
            return -1;
        }
        ArrayList<String> ret = new ShellExecute().execute(String.format("cat /proc/uid_stat/%s/%s", uid, mode),
                "/").console.strings;
        if (ret.size() > 0) {
            traffic = Integer.valueOf(ret.get(0));
        } else {
            print(String.format("Failed: cat /proc/uid_stat/%s/%s", uid, mode));
        }
    } else {
        Strings netString = new ShellExecute().execute(String.format("cat /proc/%s/net/dev", pid), "/").console;
        int rcv = 0;
        int snd = 0;
        for (String networkCard : NETWORK_CARD_TYPES) {
            Strings netLine = netString.grep(networkCard);
            if (netLine.strings.size() != 1) {
                continue;
            }
            rcv += Integer.valueOf(netLine.getRow("\\s{1,}", 2).strings.get(0));
            snd += Integer.valueOf(netLine.getRow("\\s{1,}", 10).strings.get(0));
        }
        if (MODE_RCV.equals(mode)) {
            traffic = rcv;
        } else if (MODE_SND.equals(mode)) {
            traffic = snd;
        }
    }
    return traffic;
}

From source file:adept.utilities.Grapher.java

/**
 * Make time vs size graph.//from w  w w .  j av  a 2  s  .  c  om
 *
 * @param timevalues the timevalues
 * @param sizevalues the sizevalues
 * @param filename the filename
 * @param linelabel the linelabel
 * @param Xlabel the xlabel
 * @param Ylabel the ylabel
 * @param title the title
 */
public static void makeTimeVsSizeGraph(ArrayList<Double> timevalues, ArrayList<Double> sizevalues,
        File filename, String linelabel, String Xlabel, String Ylabel, String title) {
    try {

        XYSeriesCollection scatter_plot_dataset = new XYSeriesCollection();
        XYSeries data = new XYSeries(linelabel);
        for (int i = 0; i < sizevalues.size(); i++) {
            data.add(sizevalues.get(i), timevalues.get(i));
        }
        scatter_plot_dataset.addSeries(data);

        /* Step -2:Define the JFreeChart object to create line chart */
        JFreeChart scatterPlotObject = ChartFactory.createScatterPlot(Ylabel, Xlabel, title,
                scatter_plot_dataset, PlotOrientation.VERTICAL, true, true, false);

        /* Step -3 : Write line chart to a file */
        int width = 640; /* Width of the image */
        int height = 480; /* Height of the image */
        ChartUtilities.saveChartAsPNG(filename, scatterPlotObject, width, height);
    }

    catch (Exception e) {
        e.printStackTrace();
    }

}