Example usage for java.util Collection remove

List of usage examples for java.util Collection remove

Introduction

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

Prototype

boolean remove(Object o);

Source Link

Document

Removes a single instance of the specified element from this collection, if it is present (optional operation).

Usage

From source file:Main.java

/**
 * Removes all elements from the {@link Collection}. 
 * @param <T> The type of the {@link Collection}s elements.
 * @param collection The {@link Collection} to remove from.
 * @param elementsToRemove The elements to remove.
 * @return {@code true} if the {@link Collection} changed as result of this call.
 *///ww  w  .j ava2 s.c om
public static <T> boolean removeAll(Collection<T> collection, T... elementsToRemove) {
    if (collection != null && elementsToRemove != null) {
        boolean result = false;
        for (T toAdd : elementsToRemove) {
            result = collection.remove(toAdd) || result;
        }
        return result;
    } else {
        return false;
    }
}

From source file:com.xpn.xwiki.doc.merge.MergeUtils.java

/**
 * Merge a {@link Collection}./*from ww w .j a  va  2 s. c o  m*/
 * 
 * @param <T> the type of the lists elements
 * @param previousList previous version of the collection
 * @param newList new version of the collection
 * @param currentList current version of the collection to modify
 * @param mergeResult the merge report
 */
public static <T> void mergeCollection(Collection<T> previousList, Collection<T> newList,
        Collection<T> currentList, MergeResult mergeResult) {
    for (T previousElement : previousList) {
        if (!newList.contains(previousElement)) {
            currentList.remove(previousElement);
        }
    }

    for (T newElement : newList) {
        if (!previousList.contains(newElement)) {
            currentList.add(newElement);
        }
    }
}

From source file:org.musicrecital.dao.hibernate.HibernateSearchTools.java

/**
 * Generates a lucene query to search for a given term in all the indexed fields of a class
 *
 * @param searchTerm the term to search for
 * @param searchedEntity the class searched
 * @param sess the hibernate session/*from  www.  ja  va 2s. c o  m*/
 * @param defaultAnalyzer the default analyzer for parsing the search terms
 * @return
 * @throws ParseException
 */
public static Query generateQuery(String searchTerm, Class searchedEntity, Session sess,
        Analyzer defaultAnalyzer) throws ParseException {
    Query qry = null;

    if (searchTerm.equals("*")) {
        qry = new MatchAllDocsQuery();
    } else {
        // Search in all indexed fields

        IndexReaderAccessor readerAccessor = null;
        IndexReader reader = null;
        try {
            FullTextSession txtSession = Search.getFullTextSession(sess);

            // obtain analyzer to parse the query:
            Analyzer analyzer;
            if (searchedEntity == null) {
                analyzer = defaultAnalyzer;
            } else {
                analyzer = txtSession.getSearchFactory().getAnalyzer(searchedEntity);
            }

            // search on all indexed fields: generate field list, removing internal hibernate search field name: _hibernate_class
            // TODO: possible improvement: cache the fields of each entity
            SearchFactory searchFactory = txtSession.getSearchFactory();
            readerAccessor = searchFactory.getIndexReaderAccessor();
            reader = readerAccessor.open(searchedEntity);
            Collection<String> fieldNames = reader.getFieldNames(IndexReader.FieldOption.INDEXED);
            fieldNames.remove("_hibernate_class");
            String[] fnames = new String[0];
            fnames = fieldNames.toArray(fnames);

            // To search on all fields, search the term in all fields
            String[] queries = new String[fnames.length];
            for (int i = 0; i < queries.length; ++i) {
                queries[i] = searchTerm;
            }

            qry = MultiFieldQueryParser.parse(Version.LUCENE_35, queries, fnames, analyzer);
        } finally {
            if (readerAccessor != null && reader != null) {
                readerAccessor.close(reader);
            }
        }
    }
    return qry;
}

From source file:org.goko.core.rs274ngcv3.RS274.java

public static GCodeToken removeToken(String strToken, Collection<GCodeToken> lstTokens) throws GkException {
    GCodeToken token = findToken(strToken, lstTokens);
    if (token != null) {
        lstTokens.remove(token);
    }/*from   w  w  w.ja va  2  s.c o  m*/
    return token;
}

From source file:com.adguard.commons.collections.Lists.java

/**
 * Safe method to remove all specified elements
 * from the collection.//w  ww  .j a v  a  2s. co m
 *
 * @param collection Collection
 * @param elements   Elements to remove
 * @param <T>        Any type
 */
public static <T> void removeAll(Collection<T> collection, Collection<T> elements) {

    if (CollectionUtils.isEmpty(collection) || CollectionUtils.isEmpty(elements)) {
        return;
    }

    for (T element : elements) {
        collection.remove(element);
    }
}

From source file:Main.java

public static boolean removeAll(final Collection<?> c, final Object... array) {
    boolean result = false;

    for (final Object element : array) {
        result |= c.remove(element);
    }//from   w  w  w .ja v  a2s.  co m

    return result;
}

From source file:Main.java

public static boolean removeAll(final Collection<? super Byte> c, final byte... array) {
    boolean result = false;

    for (final byte element : array) {
        result |= c.remove(element);
    }/*from w  w w  . j  a  va2  s . co  m*/

    return result;
}

From source file:Main.java

public static boolean removeAll(final Collection<? super Long> c, final long... array) {
    boolean result = false;

    for (final long element : array) {
        result |= c.remove(element);
    }/*from w ww.  j  a va 2 s.  c o  m*/

    return result;
}

From source file:Main.java

public static boolean removeAll(final Collection<? super Integer> c, final int... array) {
    boolean result = false;

    for (final int element : array) {
        result |= c.remove(element);
    }/*from w  w  w .j  a va 2s  .  co  m*/

    return result;
}

From source file:Main.java

public static boolean removeAll(final Collection<? super Short> c, final short... array) {
    boolean result = false;

    for (final short element : array) {
        result |= c.remove(element);
    }//  ww w . j av a  2  s  .  co  m

    return result;
}