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:cn.sharesdk.analysis.db.MessageUtils.java

/**
 * delect msg by id// w w w  . j  a  v a  2 s  . c  o  m
 * @param c
 * @param id
 * @return
 */
public static synchronized long deleteManyMsg(Context c, ArrayList<String> idList) {
    StringBuilder buider = new StringBuilder();
    for (int i = 0; i < idList.size(); i++) {
        buider.append("'");
        buider.append(idList.get(i));
        buider.append("'");
        buider.append(",");
    }
    String list = buider.toString().substring(0, buider.length() - 1);

    DBProvider provider = DBProvider.getDBProvider(c);
    int deleteCount = provider.delete(DBHelp.TABLE_STATISTICS, DBHelp.COLUMN_ID + " in ( " + list + " )", null);
    //Ln.e("delete COUNT == %s", deleteCount);   
    return deleteCount;
}

From source file:com.libresoft.apps.ARviewer.Utils.GeoNames.AltitudeManager.java

public static void updateHeights(ArrayList<ARGeoNode> resources_list) {
    if (resources_list == null)
        return;//from w  w w .j  a v  a 2s.co m
    int length = resources_list.size();
    for (int i = (length - 1); i > -1; i--) {
        GeoNode resource = resources_list.get(i).getGeoNode();
        if (resource.getAltitude() == NO_ALTITUDE_VALUE)
            resource.setAltitude((float) getAltitudeFromLatLong((float) (double) resource.getLatitude(),
                    (float) (double) resource.getLongitude()));
    }
}

From source file:com.extrahardmode.module.UtilityModule.java

private static boolean isSameShape(ArrayList<ItemStack> recipe1, ArrayList<ItemStack> recipe2) {
    //compare recipes
    boolean isSame = true;
    for (int i = 0; i < recipe1.size(); i++) {
        if (!recipe1.get(i).getType().equals(recipe2.get(i).getType()))
            isSame = false;//  www.ja v  a2  s.c  o m
    }
    return isSame;
}

From source file:Main.java

public static ArrayList<Double> stringToDoubleListRemoved(String s, String delimeter, int[] fieldsToBeRemoved) {
    ArrayList<Double> ret = new ArrayList<Double>();

    ArrayList<Double> allFields = stringToDoubleList(s, delimeter);

    HashSet<Integer> toBeRemoved = new HashSet<Integer>();
    for (int i : fieldsToBeRemoved)
        toBeRemoved.add(i);/*from   w  ww  .j  a  v  a  2  s.  c  o m*/

    for (int i = 0; i < allFields.size(); i++) {
        if (toBeRemoved.contains(i))
            continue;
        ret.add(allFields.get(i));
    }
    return ret;
}

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

public static int getUidByPid(int pid) {
    int uid = -1;
    try {/*from w w  w  .j ava  2s.c o  m*/
        ArrayList<String> uidString = new ShellExecute().execute(String.format("cat /proc/%s/status", pid),
                "/").console.grep("Uid").strings;
        uid = Integer.valueOf(uidString.get(0).split("\t")[1]);
    } catch (Exception e) {
        print("Get uid failed!");
        e.printStackTrace();
    }
    return uid;
}

From source file:edu.uci.ics.jung.algorithms.transformation.FoldingTransformer.java

/**
 * @param target/*from  ww  w .  j a  v  a  2 s.  co m*/
 * @param e
 * @param incident
 */
private static <S, T> void populateTarget(Graph<S, Collection<T>> target, T e, ArrayList<S> incident) {
    for (int i = 0; i < incident.size(); i++) {
        S v1 = incident.get(i);
        for (int j = i + 1; j < incident.size(); j++) {
            S v2 = incident.get(j);
            Collection<T> e_coll = target.findEdge(v1, v2);
            if (e_coll == null) {
                e_coll = new ArrayList<T>();
                target.addEdge(e_coll, v1, v2);
            }
            e_coll.add(e);
        }
    }
}

From source file:imperial.modaclouds.monitoring.sda.weka.CreateArff.java

/**
 * Create arff file given the data/*from w  ww .j a  v  a  2  s  . c  o m*/
 * 
 * @param timestamps_str   the timestamps data
 * @param data   the values of the metrics
 * @param metricName   the metric name
 * @param fileName   the file name to keep the arff file
 */
public static void create(ArrayList<ArrayList<String>> timestamps_str, ArrayList<ArrayList<String>> data,
        ArrayList<String> metricName, String fileName) {

    System.out.println("data: " + data.get(0));

    long min_timestamp = Long.valueOf(Collections.min(timestamps_str.get(0)));
    long max_timestamp = Long.valueOf(Collections.max(timestamps_str.get(0)));

    for (int i = 1; i < timestamps_str.size(); i++) {
        long min_temp = Long.valueOf(Collections.min(timestamps_str.get(i)));
        long max_temp = Long.valueOf(Collections.max(timestamps_str.get(i)));

        if (max_temp < max_timestamp) {
            max_timestamp = max_temp;
        }

        if (min_temp > min_timestamp) {
            min_timestamp = min_temp;
        }
    }

    for (int i = 0; i < timestamps_str.size(); i++) {
        Iterator<String> iter_time = timestamps_str.get(i).iterator();
        Iterator<String> iter_data = data.get(i).iterator();

        while (iter_time.hasNext()) {
            long temp_timestamps = Long.valueOf(iter_time.next());
            if (temp_timestamps < min_timestamp || temp_timestamps > max_timestamp) {
                iter_time.remove();

                iter_data.next();
                iter_data.remove();
            }
        }
    }

    double[] timestamps = convertDoubles(timestamps_str.get(0));
    double[] targetData = convertDoubles(data.get(0));

    double[][] otherData = new double[data.size() - 1][timestamps.length];
    for (int i = 0; i < data.size() - 1; i++) {
        double[] timestamps_temp = convertDoubles(timestamps_str.get(i));
        double[] targetData_temp = convertDoubles(data.get(i));

        SplineInterpolator spline = new SplineInterpolator();

        Map<Double, Integer> map = new TreeMap<Double, Integer>();
        for (int j = 0; j < timestamps_temp.length; j++) {
            map.put(timestamps_temp[j], j);
        }
        Collection<Integer> indices = map.values();

        int[] indices_int = ArrayUtils.toPrimitive(indices.toArray(new Integer[indices.size()]));
        double[] timestamps_temp_new = new double[indices_int.length];
        double[] targetData_temp_new = new double[indices_int.length];

        for (int j = 0; j < indices_int.length; j++) {
            timestamps_temp_new[j] = timestamps_temp[indices_int[j]];
            targetData_temp_new[j] = targetData_temp[indices_int[j]];
        }

        PolynomialSplineFunction polynomical = spline.interpolate(timestamps_temp_new, targetData_temp_new);

        for (int j = 0; j < timestamps.length; j++) {
            try {
                otherData[i][j] = polynomical.value(timestamps[j]);
            } catch (Exception ex) {
                otherData[i][j] = targetData_temp_new[j];
            }
        }
    }

    ArrayList<Attribute> attributes;
    Instances dataSet;

    attributes = new ArrayList<Attribute>();

    for (String metric : metricName) {
        attributes.add(new Attribute(metric));
    }

    dataSet = new Instances("data", attributes, 0);

    for (int i = 0; i < timestamps.length; i++) {
        double[] instanceValue1 = new double[dataSet.numAttributes()];
        instanceValue1[0] = timestamps[i];
        instanceValue1[1] = targetData[i];

        for (int j = 0; j < data.size() - 1; j++) {
            instanceValue1[2 + j] = otherData[j][i];
        }

        DenseInstance denseInstance1 = new DenseInstance(1.0, instanceValue1);

        dataSet.add(denseInstance1);
    }

    ArffSaver saver = new ArffSaver();
    saver.setInstances(dataSet);
    try {
        String workingDir = System.getProperty("user.dir");
        System.out.println("workingDir: " + workingDir);
        saver.setFile(new File(workingDir + "/" + fileName));
        saver.writeBatch();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static String toString(ArrayList<String> arrayList, String separator, int indexStart, int indexTo) {
    StringBuilder sb = new StringBuilder();

    for (int i = indexStart; i < arrayList.size(); i++) {
        if (i > indexTo) {
            continue;
        }/*  w  ww .j  a  v a2  s  . c  o  m*/

        if (i > indexStart) {
            sb.append(separator);
        }

        sb.append(arrayList.get(i));
    }

    return sb.toString();
}

From source file:Main.java

/**
 * Returns true if the two ArrayLists are equal with respect to the objects they contain.
 * The objects must be in the same order and be reference equal (== not .equals()).
 */// w  ww  .java2s  .  co  m
public static <T> boolean referenceEquals(ArrayList<T> a, ArrayList<T> b) {
    if (a == b) {
        return true;
    }

    final int sizeA = a.size();
    final int sizeB = b.size();
    if (a == null || b == null || sizeA != sizeB) {
        return false;
    }

    boolean diff = false;
    for (int i = 0; i < sizeA && !diff; i++) {
        diff |= a.get(i) != b.get(i);
    }
    return !diff;
}

From source file:edu.mit.genecircuits.GcUtils.java

/** Return true if the given array is an ordered list of positive doubles, given in increasing order */
public static boolean posDoubleIncreasing(ArrayList<Double> x) {

    if (x == null || x.size() == 0)
        return true;

    for (int i = 0; i < x.size(); i++) {
        if (x.get(i) <= 0)
            return false;
        if (i > 0 && x.get(i) <= x.get(i - 1))
            return false;
    }/*from ww  w  .j  ava  2 s.co  m*/
    return true;
}