Example usage for java.util Iterator remove

List of usage examples for java.util Iterator remove

Introduction

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

Prototype

default void remove() 

Source Link

Document

Removes from the underlying collection the last element returned by this iterator (optional operation).

Usage

From source file:cooccurrence.Omer_Levy.java

/**
 * Method to populate the apache matrix from cooccur hashmap
 * @param matrixR//from  w w w.j  a v a 2 s . c o m
 * @param cooccur
 * @param rowStrings
 * @param colStrings 
 */
private static void populateMatrixR(RealMatrix matrixR, HashMap<String, HashMap<String, Double>> cooccur,
        ArrayList<String> rowStrings, ArrayList<String> colStrings) {
    Iterator iter = cooccur.keySet().iterator();

    while (iter.hasNext()) {
        String row = iter.next().toString();
        int i = rowStrings.indexOf(row);
        HashMap<String, Double> inner = cooccur.get(row);
        for (String col : inner.keySet()) {
            int j = colStrings.indexOf(col);
            double val = inner.get(col);
            matrixR.setEntry(i, j, val);
        }
        iter.remove();
    }
}

From source file:com.evolveum.midpoint.schema.util.AdminGuiConfigTypeUtil.java

private static void joinForms(ObjectFormsType objectForms, ObjectFormType newForm) {
    Iterator<ObjectFormType> iterator = objectForms.getObjectForm().iterator();
    while (iterator.hasNext()) {
        ObjectFormType currentForm = iterator.next();
        if (isTheSameObjectForm(currentForm, newForm)) {
            iterator.remove();
        }// www . j  a  v  a 2s .  c  om
    }
    objectForms.getObjectForm().add(newForm.clone());
}

From source file:it.evilsocket.dsploit.net.http.RequestParser.java

public static ArrayList<BasicClientCookie> getCookiesFromHeaders(ArrayList<String> headers) {
    ArrayList<String> values = getHeaderValues("Cookie", headers);

    if (values != null && values.size() > 0) {
        ArrayList<BasicClientCookie> cookies = new ArrayList<BasicClientCookie>();
        for (String value : values) {
            ArrayList<BasicClientCookie> lineCookies = parseRawCookie(value);
            if (lineCookies != null && lineCookies.size() > 0) {
                cookies.addAll(lineCookies);
            }//w  ww.ja v  a  2 s  . c om
        }

        // remove google and cloudflare cookies
        Iterator<BasicClientCookie> it = cookies.iterator();
        while (it.hasNext()) {
            BasicClientCookie cookie = (BasicClientCookie) it.next();
            if (cookie.getName().startsWith("__utm") || cookie.getName().equals("__cfduid"))
                it.remove();
        }

        return cookies.size() > 0 ? cookies : null;
    }

    return null;
}

From source file:ai.susi.mind.SusiSkill.java

/**
 * if no keys are given, we compute them from the given phrases
 * @param phrases//from   w w  w.j  a v a2s.  c o  m
 * @return
 */
private static JSONArray computeKeysFromPhrases(List<SusiPhrase> phrases) {
    Set<String> t = new LinkedHashSet<>();

    // create a list of token sets from the phrases
    List<Set<String>> ptl = new ArrayList<>();
    final AtomicBoolean needsCatchall = new AtomicBoolean(false);
    phrases.forEach(phrase -> {
        Set<String> s = new HashSet<>();
        for (String token : SPACE_PATTERN.split(phrase.getPattern().toString())) {
            String m = SusiPhrase.extractMeat(token.toLowerCase());
            if (m.length() > 1)
                s.add(m);
        }
        // if there is no meat inside, it will not be possible to access the skill without the catchall skill, so remember that
        if (s.size() == 0)
            needsCatchall.set(true);

        ptl.add(s);
    });

    // this is a kind of emergency case where we need a catchall skill because otherwise we cannot access one of the phrases
    JSONArray a = new JSONArray();
    if (needsCatchall.get())
        return a.put(CATCHALL_KEY);

    // collect all token
    ptl.forEach(set -> set.forEach(token -> t.add(token)));

    // if no tokens are available, return the catchall key
    if (t.size() == 0)
        return a.put(CATCHALL_KEY);

    // make a copy to make it possible to use the original key set again
    Set<String> tc = new LinkedHashSet<>();
    t.forEach(c -> tc.add(c));

    // remove all token that do not appear in all phrases
    ptl.forEach(set -> {
        Iterator<String> i = t.iterator();
        while (i.hasNext())
            if (!set.contains(i.next()))
                i.remove();
    });

    // if no token is left, use the original tc set and add all keys
    if (t.size() == 0) {
        tc.forEach(c -> a.put(c));
        return a;
    }

    // use only the first token, because that appears in all the phrases
    return new JSONArray().put(t.iterator().next());
}

From source file:com.aurel.track.screen.item.action.ScreenAction.java

/**
 * Prepares the replacement triggers//w ww  .j av  a 2 s. co  m
 * @param personID
 * @return
 */
public static List<TScreenBean> prepareReplacementScreens(List<Integer> screenIDs) {
    List<TScreenBean> replacementScreenList = ScreenDAOAdapter.getInstance().loadAll();
    if (replacementScreenList != null && screenIDs != null) {
        Iterator<TScreenBean> iterator = replacementScreenList.iterator();
        while (iterator.hasNext()) {
            TScreenBean screenBean = iterator.next();
            if (screenIDs.contains(screenBean.getObjectID())) {
                iterator.remove();
            } else {
                //taken the name as label
                screenBean.setLabel(screenBean.getName());
            }
        }
    }
    return replacementScreenList;
}

From source file:com.hybris.mobile.Hybris.java

public static void addPreviousSearch(String searchString) {
    // Trim if full
    if (getPreviousSearches().size() > ExternalConstants.MAX_PREVIOUS_SEARCHES) {

        // Removing the first element of the list
        Iterator<String> iterPreviousSearch = getPreviousSearches().iterator();

        if (iterPreviousSearch != null && iterPreviousSearch.hasNext()) {
            iterPreviousSearch.next();//ww w .ja va 2s.  c  o  m
            iterPreviousSearch.remove();
        }

    }
    // Add
    getPreviousSearches().add(searchString);
    // Save
    if (Hybris.context != null) {
        SharedPreferences.Editor editor = getSharedPreferences().edit();
        editor.putStringSet("savedSearches", sPreviousSearches);
        editor.commit();
    }
}

From source file:net.dv8tion.jda.core.utils.SimpleLog.java

/**
 * Removes all File-logs created via {@link #addFileLog(net.dv8tion.jda.core.utils.SimpleLog.Level, java.io.File)} with given File.
 * To remove the sout and serr logs, call {@link #addFileLogs(java.io.File, java.io.File)} with null args.
 *
 * @param file/*from  www . j  av a2 s  .c om*/
 *      The file to remove from all FileLogs (except sout and serr logs)
 * @throws java.io.IOException
 *      If the File can't be canonically resolved (access denied)
 */
public static void removeFileLog(File file) throws IOException {
    File canonicalFile = file.getCanonicalFile();
    Iterator<Map.Entry<Level, Set<File>>> setIter = fileLogs.entrySet().iterator();
    while (setIter.hasNext()) {
        Map.Entry<Level, Set<File>> set = setIter.next();
        Iterator<File> fileIter = set.getValue().iterator();
        while (fileIter.hasNext()) {
            File logFile = fileIter.next();
            if (logFile.equals(canonicalFile)) {
                fileIter.remove();
                break;
            }
        }
        if (set.getValue().isEmpty()) {
            setIter.remove();
        }
    }
}

From source file:com.aurel.track.item.consInf.ConsInfBL.java

/**
 * Removes the person from the list// w  w w .  j  ava2 s . c om
 * @param personBeans
 * @param personID
 * @return
 */
public static void meRemove(List<TPersonBean> personBeans, Integer personID) {
    TPersonBean personBean;
    if (personBeans == null || personID == null) {
        return;
    }
    Iterator<TPersonBean> iterator = personBeans.iterator();
    while (iterator.hasNext()) {
        personBean = iterator.next();
        if (personBean.getObjectID().equals(personID)) {
            iterator.remove();
            return;
        }
    }
}

From source file:com.github.rinde.opt.localsearch.Swaps.java

/**
 * Removes all items from list and returns the indices of the removed items.
 * @param list The list to remove items from.
 * @param item The item to remove from the list.
 * @return The indices of the removed items, or an empty list if the item was
 *         not found in list./* ww  w . ja v a2  s . co m*/
 */
static <T> IntList removeAll(List<T> list, T item) {
    final Iterator<T> it = list.iterator();
    final IntArrayList indices = new IntArrayList();
    int i = 0;
    while (it.hasNext()) {
        if (it.next().equals(item)) {
            it.remove();
            indices.add(i);
        }
        i++;
    }
    return IntLists.unmodifiable(indices);
}

From source file:I18NUtil.java

/**
 * Searches for the nearest locale from the available options.  To match any locale, pass in
 * <tt>null</tt>.//from  w w  w . j a  va  2  s .  co  m
 * 
 * @param templateLocale the template to search for or <tt>null</tt> to match any locale
 * @param options the available locales to search from
 * @return Returns the best match from the available options, or the <tt>null</tt> if
 *      all matches fail
 */
public static Locale getNearestLocale(Locale templateLocale, Set<Locale> options) {
    if (options.isEmpty()) // No point if there are no options
    {
        return null;
    } else if (templateLocale == null) {
        for (Locale locale : options) {
            return locale;
        }
    } else if (options.contains(templateLocale)) // First see if there is an exact match
    {
        return templateLocale;
    }
    // make a copy of the set
    Set<Locale> remaining = new HashSet<Locale>(options);

    // eliminate those without matching languages
    Locale lastMatchingOption = null;
    String templateLanguage = templateLocale.getLanguage();
    if (templateLanguage != null && !templateLanguage.equals("")) {
        Iterator<Locale> iterator = remaining.iterator();
        while (iterator.hasNext()) {
            Locale option = iterator.next();
            if (option != null && !templateLanguage.equals(option.getLanguage())) {
                iterator.remove(); // It doesn't match, so remove
            } else {
                lastMatchingOption = option; // Keep a record of the last match
            }
        }
    }
    if (remaining.isEmpty()) {
        return null;
    } else if (remaining.size() == 1 && lastMatchingOption != null) {
        return lastMatchingOption;
    }

    // eliminate those without matching country codes
    lastMatchingOption = null;
    String templateCountry = templateLocale.getCountry();
    if (templateCountry != null && !templateCountry.equals("")) {
        Iterator<Locale> iterator = remaining.iterator();
        while (iterator.hasNext()) {
            Locale option = iterator.next();
            if (option != null && !templateCountry.equals(option.getCountry())) {
                // It doesn't match language - remove
                // Don't remove the iterator. If it matchs a langage but not the country, returns any matched language                     
                // iterator.remove();
            } else {
                lastMatchingOption = option; // Keep a record of the last match
            }
        }
    }
    /*if (remaining.isEmpty())
    {
    return null;
    }
    else */
    if (remaining.size() == 1 && lastMatchingOption != null) {
        return lastMatchingOption;
    } else {
        // We have done an earlier equality check, so there isn't a matching variant
        // Also, we know that there are multiple options at this point, either of which will do.

        // This gets any country match (there will be worse matches so we take the last the country match)
        if (lastMatchingOption != null) {
            return lastMatchingOption;
        } else {
            for (Locale locale : remaining) {
                return locale;
            }
        }
    }
    // The logic guarantees that this code can't be called
    throw new RuntimeException("Logic should not allow code to get here.");
}