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:Main.java

/**
 * replaces a list of files with another list of files, indicated by names
 * @param originalList//from w  w w.java2s.com
 * @param newList
 * @return
 */
public static void replaceFiles(ArrayList<String> originalList, ArrayList<String> newList)
        throws UnsupportedOperationException, OperationCanceledException {

    if (originalList.size() != newList.size())
        throw new UnsupportedOperationException();
    else {
        String name = null;
        for (int i = 0, size = originalList.size(); i < size; i++) {
            name = originalList.get(i);
            File f = new File(name);
            File newF = new File(newList.get(i));
            if (f.exists() && newF.exists()) {
                if (f.delete()) {
                    File temp = new File(name);
                    newF.renameTo(temp);
                } else {
                    throw new OperationCanceledException("Delete failed");
                }
            } else {
                throw new UnsupportedOperationException("Wrong lists of file names");
            }
        }
    }
}

From source file:com.acmeair.loader.FlightLoader.java

static private boolean alreadyInCollection(String airportCode, ArrayList<AirportCodeMapping> airports) {
    for (int ii = 0; ii < airports.size(); ii++) {
        if (airports.get(ii).getAirportCode().equals(airportCode)) {
            return true;
        }//from  ww w.j a  va  2 s. c  o  m
    }
    return false;
}

From source file:Main.java

/**
 *  Find the first  descendant element of the given parent Node
 *  whose tag name.equals the given tag.
 *
 *  @param parent The root of the xml dom tree to search.
 *  @param tag The tag name to match.//  www.  j a v a2 s  .c o  m
 *  @return The element foudn or null
 */
public static Element findDescendant(Node parent, String tag) {
    ArrayList found = new ArrayList();
    findDescendants(parent, tag, found);
    if (found.size() == 0) {
        return null;
    }
    return (Element) found.get(0);
}

From source file:Main.java

public static String[] generateArrayWithStringValuesInRange(int min, int max) {
    ArrayList<String> arrayList = new ArrayList<>();
    for (int i = min; i < max; i++) {
        arrayList.add(Integer.toString(i));
    }/*from  w  w  w. jav  a  2 s .  co m*/
    String[] stringArray = new String[arrayList.size()];
    for (int i = 0; i < arrayList.size(); i++) {
        stringArray[i] = arrayList.get(i);
    }
    return stringArray;
}

From source file:com.readystatesoftware.simpl3r.utils.SharedPreferencesUtils.java

public static void setStringArrayPref(SharedPreferences prefs, String key, ArrayList<String> values) {
    SharedPreferences.Editor editor = prefs.edit();
    JSONArray a = new JSONArray();
    for (int i = 0; i < values.size(); i++) {
        a.put(values.get(i));//from ww  w .  j ava  2s  .  c o m
    }
    if (!values.isEmpty()) {
        editor.putString(key, a.toString());
    } else {
        editor.putString(key, null);
    }
    SharedPreferencesCompat.apply(editor);
}

From source file:Main.java

public static boolean isServiceRunning(Context context, String service) {
    ActivityManager actManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ArrayList<ActivityManager.RunningServiceInfo> serviceList = (ArrayList<ActivityManager.RunningServiceInfo>) actManager
            .getRunningServices(50);/* w  w  w .j  a va 2 s . c  om*/
    for (int n = 0; n < serviceList.size(); n++) {
        if (serviceList.get(n).service.getClassName().toString().equals(service)) {
            return true;
        }
    }

    return false;
}

From source file:FaceRatios.java

private static double[] listToArray(ArrayList<Double> list) {
    double[] data = new double[list.size()];
    for (int i = 0; i < list.size(); i++)
        data[i] = list.get(i);/*from w w w . j  a v  a  2s .  co m*/
    return data;
}

From source file:Main.java

public static List<ByteBuffer> mergeAdjacentBuffers(List<ByteBuffer> samples) {
    ArrayList<ByteBuffer> nuSamples = new ArrayList<ByteBuffer>(samples.size());
    for (ByteBuffer buffer : samples) {
        int lastIndex = nuSamples.size() - 1;
        if (lastIndex >= 0 && buffer.hasArray() && nuSamples.get(lastIndex).hasArray()
                && buffer.array() == nuSamples.get(lastIndex).array() && nuSamples.get(lastIndex).arrayOffset()
                        + nuSamples.get(lastIndex).limit() == buffer.arrayOffset()) {
            ByteBuffer oldBuffer = nuSamples.remove(lastIndex);
            ByteBuffer nu = ByteBuffer
                    .wrap(buffer.array(), oldBuffer.arrayOffset(), oldBuffer.limit() + buffer.limit()).slice();
            // We need to slice here since wrap([], offset, length) just sets position and not the arrayOffset.
            nuSamples.add(nu);/*from w w w  .  j a va2 s  .  co m*/
        } else if (lastIndex >= 0 && buffer instanceof MappedByteBuffer
                && nuSamples.get(lastIndex) instanceof MappedByteBuffer && nuSamples.get(lastIndex)
                        .limit() == nuSamples.get(lastIndex).capacity() - buffer.capacity()) {
            // This can go wrong - but will it?
            ByteBuffer oldBuffer = nuSamples.get(lastIndex);
            oldBuffer.limit(buffer.limit() + oldBuffer.limit());
        } else {
            buffer.reset();
            nuSamples.add(buffer);
        }
    }
    return nuSamples;
}

From source file:biblioteca.reportes.ChartCreator.java

public static DefaultCategoryDataset asignarBarDataset(ArrayList<String> Valores) {
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    int size = Valores.size();
    size = (size <= 32) ? size : 32;/*from ww w  . ja v a 2s .c o m*/
    for (int i = 2; i < size; i += 2) {
        dataSet.setValue(Double.parseDouble(Valores.get(i + 1)), "Grafica", Valores.get(i));
    }
    return dataSet;
}

From source file:Main.java

public static BigInteger getZ(ArrayList<byte[]> c1, ArrayList<byte[]> c2, BigInteger p) {
    BigInteger z = BigInteger.ZERO;

    //TODO: make sure c1 and c2 are of the same size
    int size = c1.size();
    if (size > c2.size()) {
        size = c2.size();//  w ww. jav a2 s .c  o m
    }

    for (int i = 0; i < size; i++) {
        BigInteger c1BI = new BigInteger(1, c1.get(i));
        BigInteger c2BI = new BigInteger(1, c2.get(i));
        BigInteger exp = new BigInteger(1, ByteBuffer.allocate(8).putLong((long) Math.pow(2, i)).array());

        z = z.add((c1BI.multiply(c2BI)).modPow(exp, p));
        Log.d("CeCk", "z calculation " + i + "/" + size + " round");
    }
    return z.mod(p);
}