Example usage for java.util ArrayList remove

List of usage examples for java.util ArrayList remove

Introduction

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

Prototype

public boolean remove(Object o) 

Source Link

Document

Removes the first occurrence of the specified element from this list, if it is present.

Usage

From source file:FileUtils.java

private static ArrayList<String> splitPath(String path) {
    ArrayList<String> pathElements = new ArrayList<String>();
    for (StringTokenizer st = new StringTokenizer(path, File.separator); st.hasMoreTokens();) {
        String token = st.nextToken();
        if (token.equals(".")) {
            // do nothing
        } else if (token.equals("..")) {
            if (!pathElements.isEmpty()) {
                pathElements.remove(pathElements.size() - 1);
            }//from w w w.  j  av  a 2  s . c o m
        } else {
            pathElements.add(token);
        }
    }
    return pathElements;
}

From source file:Main.java

public static <T> ArrayList<T> distinctList(ArrayList<T> arg) {
    ArrayList<T> distinct = new ArrayList<T>();
    if (null != arg) {
        distinct = new ArrayList<T>();
        distinct.addAll(arg);/*from  w  w  w. ja va 2s .c om*/
        for (int i = 0; i < distinct.size(); i++) {
            T t1 = distinct.get(i);
            for (int j = i + 1; j < distinct.size(); j++) {
                T t2 = distinct.get(j);
                if (t1.equals(t2)) {
                    distinct.remove(j);
                    j--;
                }
            }
        }
    }
    return distinct;
}

From source file:Main.java

public static ArrayList<ContentValues> removeEntriesWhenPresent(
        HashMap<String, ArrayList<ContentValues>> operationMap, String tableName, String idColumnName) {
    ArrayList<ContentValues> restoreOperations = operationMap.get(tableName);
    if (null == restoreOperations) {
        return null;
    }/*from   ww w  . ja v a  2  s .com*/
    ArrayList<ContentValues> removeOperations = new ArrayList<ContentValues>();
    for (ContentValues restoreCv : restoreOperations) {
        if (restoreCv.containsKey(idColumnName)) {
            removeOperations.add(restoreCv);
        }
    }
    for (ContentValues removeCv : removeOperations) {
        restoreOperations.remove(removeCv);
    }
    return removeOperations;
}

From source file:eu.scape_project.pt.mapred.input.ControlFileInputFormat.java

/**
 * Creates mapping of locations to arraylists of control lines.
 *
 * @param controlFile input control file
 * @param conf Hadoop configuration/*from   w  w w .  jav a  2  s  .  c  om*/
 * @param repo Toolspec repository
 * @param parser parser for the control lines
 * @return mapping
 */
public static Map<String, ArrayList<String>> createLocationMap(Path controlFile, Configuration conf,
        Repository repo, CmdLineParser parser) throws IOException {
    FileSystem fs = controlFile.getFileSystem(conf);
    FSDataInputStream in = fs.open(controlFile);
    LineReader lr = new LineReader(in, conf);
    Text controlLine = new Text();
    Map<String, ArrayList<String>> locationMap = new HashMap<String, ArrayList<String>>();
    ArrayList<String> allHosts = new ArrayList<String>();
    int l = 0;
    while ((lr.readLine(controlLine)) > 0) {
        l += 1;
        // read line by line
        Path[] inFiles = getInputFiles(fs, parser, repo, controlLine.toString());

        // count for each host how many blocks it holds of the current control line's input files
        String[] hostsOfFile = getSortedHosts(fs, inFiles);

        for (String host : hostsOfFile) {
            if (!allHosts.contains(host))
                allHosts.add(host);
        }
        ArrayList<String> theseHosts = (ArrayList<String>) allHosts.clone();
        for (String host : hostsOfFile) {
            theseHosts.remove(host);
        }

        String[] hosts = new String[theseHosts.size() + hostsOfFile.length];
        int h = 0;
        for (String host : hostsOfFile) {
            hosts[h] = hostsOfFile[h];
            h++;
        }
        for (String host : theseHosts) {
            hosts[h] = theseHosts.get(h - hostsOfFile.length);
            h++;
        }

        addToLocationMap(locationMap, hosts, controlLine.toString(), l);
    }
    return locationMap;
}

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 ww. j a  va 2s  . c om
        } 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:com.remobile.file.Filesystem.java

/**
 * Removes multiple repeated //s, and collapses processes ../s.
 *///from  w w w.jav  a 2  s  .co m
protected static String normalizePath(String rawPath) {
    // If this is an absolute path, trim the leading "/" and replace it later
    boolean isAbsolutePath = rawPath.startsWith("/");
    if (isAbsolutePath) {
        rawPath = rawPath.replaceFirst("/+", "");
    }
    ArrayList<String> components = new ArrayList<String>(Arrays.asList(rawPath.split("/+")));
    for (int index = 0; index < components.size(); ++index) {
        if (components.get(index).equals("..")) {
            components.remove(index);
            if (index > 0) {
                components.remove(index - 1);
                --index;
            }
        }
    }
    StringBuilder normalizedPath = new StringBuilder();
    for (String component : components) {
        normalizedPath.append("/");
        normalizedPath.append(component);
    }
    if (isAbsolutePath) {
        return normalizedPath.toString();
    } else {
        return normalizedPath.toString().substring(1);
    }
}

From source file:Main.java

public static ArrayList<ContentValues> removeEntriesWhenEquals(
        HashMap<String, ArrayList<ContentValues>> operationMap, String tableName, String idColumnName,
        String compareValue) {//from   w ww  .j a  va2 s  .  c om
    ArrayList<ContentValues> restoreOperations = operationMap.get(tableName);
    if (null == restoreOperations || null == compareValue) {
        return null;
    }
    ArrayList<ContentValues> removeOperations = new ArrayList<ContentValues>();
    for (ContentValues restoreCv : restoreOperations) {
        if (restoreCv.containsKey(idColumnName) && compareValue.equals(restoreCv.getAsString(idColumnName))) {
            removeOperations.add(restoreCv);
        }
    }
    for (ContentValues removeCv : removeOperations) {
        restoreOperations.remove(removeCv);
    }
    return removeOperations;
}

From source file:id.zelory.tanipedia.util.Utils.java

public static ArrayList<Berita> getRandomBerita(Context context, String alamat) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayList<Berita> beritaArrayList = null;
    try {// w w  w.  j  a v a  2s  .  co  m
        beritaArrayList = mapper.readValue(PrefUtils.ambilString(context, "berita"),
                mapper.getTypeFactory().constructCollectionType(ArrayList.class, Berita.class));
    } catch (IOException e) {
        e.printStackTrace();
    }

    for (int i = 0; i < 5; i++) {
        int x = randInt(0, beritaArrayList.size() - 1);
        if (beritaArrayList.get(x).getAlamat().equals(alamat)) {
            beritaArrayList.remove(x);
            i--;
        } else {
            beritaArrayList.set(i, beritaArrayList.get(x));
            beritaArrayList.remove(x);
        }
    }

    for (int i = 5; i < beritaArrayList.size(); i++)
        beritaArrayList.remove(i);

    return beritaArrayList;
}

From source file:Main.java

static List<String> getEmailAddresses(Context context, int limit) {
    ArrayList<String> emails = new ArrayList<String>();
    AccountManager am = AccountManager.get(context);
    if (am == null) {
        return emails;
    }// w  w w. j a va2s .  co m
    Account[] accounts = am.getAccountsByType("com.google");
    if (accounts == null || accounts.length == 0) {
        return emails;
    }
    for (Account a : accounts) {
        if (a.name == null || a.name.length() == 0) {
            continue;
        }
        emails.add(a.name.trim().toLowerCase());
    }
    while (emails.size() > limit) {
        emails.remove(emails.size() - 1);
    }
    return emails;
}

From source file:com.yamin.kk.vlc.Util.java

public static void removeCustomDirectory(String path) {
    SharedPreferences preferences = PreferenceManager
            .getDefaultSharedPreferences(VLCApplication.getAppContext());
    if (!preferences.getString("custom_paths", "").contains(path))
        return;//from w ww. j  av  a 2  s . c o m
    ArrayList<String> dirs = new ArrayList<String>(
            Arrays.asList(preferences.getString("custom_paths", "").split(":")));
    dirs.remove(path);
    String custom_path;
    if (dirs.size() > 0) {
        StringBuilder builder = new StringBuilder();
        builder.append(dirs.remove(0));
        for (String s : dirs) {
            builder.append(":");
            builder.append(s);
        }
        custom_path = builder.toString();
    } else { // don't do unneeded extra work
        custom_path = "";
    }
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString("custom_paths", custom_path);
    editor.commit();
}