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

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

    for (final float element : array) {
        result |= c.remove(element);
    }/*from   w w  w . j a  v a 2  s. c om*/

    return result;
}

From source file:Main.java

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

    for (final char element : array) {
        result |= c.remove(element);
    }/*from  www.  j a v  a 2s.  c  o  m*/

    return result;
}

From source file:Main.java

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

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

    return result;
}

From source file:Main.java

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

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

    return result;
}

From source file:Main.java

/**
 * <p>//from  ww w.ja  va2  s.c om
 * Checks if the given two {@link Collection}s contains the same elements
 * in any order.
 * </p>
 * <p>
 * Empty {@link Collection}s and {@code null} parameters are treated as equal.
 * </p> 
 * @param first The first {@link Collection}.
 * @param second The second {@link Collection}.
 * @return {@code true} both {@link Collection}s contains same elements, {@code false} {@link Collection}s are different.
 */
public static <T> boolean containsSame(Collection<T> first, Collection<T> second) {
    if (first != null) {
        if (second != null) {
            if (first.size() == second.size()) {
                Collection<T> firstCopy = new LinkedList<T>(first);
                boolean same = true;
                Iterator<T> secondIter = second.iterator();
                while (same && secondIter.hasNext()) {
                    T secondNext = secondIter.next();
                    same = firstCopy.remove(secondNext);
                }
                return same;
            } else {
                return false;
            }
        } else {
            return first.size() == 0;
        }
    } else {
        return second == null || second.size() == 0;
    }
}

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

/**
 * Safe method to remove an element from collection.
 * If either collection is empty or element is null - returns false.
 *
 * @param collection Collection//from  ww w  .j  a  v a2 s .  c o  m
 * @param element    Element
 * @param <T>        Any type
 * @return true if element has been removed
 */
public static <T> boolean remove(Collection<T> collection, T element) {

    if (element == null) {
        return false;
    }
    //noinspection SimplifiableIfStatement
    if (CollectionUtils.isEmpty(collection)) {
        return false;
    }

    return collection.remove(element);
}

From source file:org.kuali.kfs.module.ld.util.ConsolidationUtil.java

/**
 * Utility class for helping DAOs deal with building queries for the consolidation option
 * // ww  w .j a  v a2 s  .  c o m
 * @param query Query to make consolidated
 * @param extraFields fields included in the query
 * @param ignoredFields to omit from the query
 */
public static void buildConsolidatedQuery(ReportQueryByCriteria query, String... extraFields) {
    Collection<String> attributeList = buildAttributeCollection(extraFields);
    Collection<String> groupByList = buildGroupByCollection();

    attributeList.remove(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
    groupByList.remove(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
    attributeList.remove(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
    groupByList.remove(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
    attributeList.remove(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE);
    groupByList.remove(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE);

    // set the selection attributes
    String[] attributes = (String[]) attributeList.toArray(new String[attributeList.size()]);
    query.setAttributes(attributes);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Built Attributes for Query: " + attributeList.toString());
    }
    // add the group criteria into the selection statement
    String[] groupBy = (String[]) groupByList.toArray(new String[attributeList.size()]);
    query.addGroupBy(groupBy);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Built GroupBy for Query: " + groupByList.toString());
    }
}

From source file:org.hyperledger.fabric.sdk.helper.SDKUtil.java

/**
 * Compress the given directory src to target tar.gz file
 * @param src The source directory/*w ww .j  a  va  2s  .c  om*/
 * @param target The target tar.gz file
 * @throws IOException
 */
public static void generateTarGz(String src, String target) throws IOException {
    File sourceDirectory = new File(src);
    File destinationArchive = new File(target);

    String sourcePath = sourceDirectory.getAbsolutePath();
    FileOutputStream destinationOutputStream = new FileOutputStream(destinationArchive);

    TarArchiveOutputStream archiveOutputStream = new TarArchiveOutputStream(
            new GzipCompressorOutputStream(new BufferedOutputStream(destinationOutputStream)));
    archiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);

    try {
        Collection<File> childrenFiles = org.apache.commons.io.FileUtils.listFiles(sourceDirectory, null, true);
        childrenFiles.remove(destinationArchive);

        ArchiveEntry archiveEntry;
        FileInputStream fileInputStream;
        for (File childFile : childrenFiles) {
            String childPath = childFile.getAbsolutePath();
            String relativePath = childPath.substring((sourcePath.length() + 1), childPath.length());

            relativePath = FilenameUtils.separatorsToUnix(relativePath);
            archiveEntry = new TarArchiveEntry(childFile, relativePath);
            fileInputStream = new FileInputStream(childFile);
            archiveOutputStream.putArchiveEntry(archiveEntry);

            try {
                IOUtils.copy(fileInputStream, archiveOutputStream);
            } finally {
                IOUtils.closeQuietly(fileInputStream);
                archiveOutputStream.closeArchiveEntry();
            }
        }
    } finally {
        IOUtils.closeQuietly(archiveOutputStream);
    }
}

From source file:org.artifactory.util.ArchiveUtils.java

/**
 * Archives the contents of the given directory into the given archive using the apache commons compress tools
 *
 * @param sourceDirectory    Directory to archive
 * @param destinationArchive Archive file to create
 * @param recurse            True if should recurse file scan of source directory. False if not
 * @param archiveType        Archive type to create
 * @throws java.io.IOException      Any exceptions that might occur while handling the given files and used streams
 * @throws IllegalArgumentException Thrown when given invalid destinations
 *//*from  w  w  w. ja  v a2  s  .c om*/
public static void archive(File sourceDirectory, File destinationArchive, boolean recurse,
        ArchiveType archiveType) throws IOException {
    if ((sourceDirectory == null) || (destinationArchive == null)) {
        throw new IllegalArgumentException("Supplied destinations cannot be null.");
    }
    if (!sourceDirectory.isDirectory()) {
        throw new IllegalArgumentException("Supplied source directory must be an existing directory.");
    }
    String sourcePath = sourceDirectory.getAbsolutePath();
    String archivePath = destinationArchive.getAbsolutePath();
    log.debug("Beginning to archive '{}' into '{}'", sourcePath, archivePath);
    FileOutputStream destinationOutputStream = new FileOutputStream(destinationArchive);
    ArchiveOutputStream archiveOutputStream = createArchiveOutputStream(
            new BufferedOutputStream(destinationOutputStream), archiveType);
    try {
        @SuppressWarnings({ "unchecked" })
        Collection<File> childrenFiles = org.apache.commons.io.FileUtils.listFiles(sourceDirectory, null,
                recurse);
        childrenFiles.remove(destinationArchive);

        ArchiveEntry archiveEntry;
        FileInputStream fileInputStream;
        for (File childFile : childrenFiles) {
            String childPath = childFile.getAbsolutePath();
            String relativePath = childPath.substring((sourcePath.length() + 1), childPath.length());

            /**
             * Need to convert separators to unix format since zipping on windows machines creates windows specific
             * FS file paths
             */
            relativePath = FilenameUtils.separatorsToUnix(relativePath);
            archiveEntry = createArchiveEntry(childFile, relativePath, archiveType);
            fileInputStream = new FileInputStream(childFile);
            archiveOutputStream.putArchiveEntry(archiveEntry);

            try {
                IOUtils.copy(fileInputStream, archiveOutputStream);
            } finally {
                IOUtils.closeQuietly(fileInputStream);
                archiveOutputStream.closeArchiveEntry();
            }
            log.debug("Archive '{}' into '{}'", childPath, archivePath);
        }
    } finally {
        IOUtils.closeQuietly(archiveOutputStream);
    }

    log.debug("Completed archiving of '{}' into '{}'", sourcePath, archivePath);
}

From source file:org.sipfoundry.sipxconfig.common.DataCollectionUtil.java

/**
 * Removes items from collections by their primary key and updates the positions on the items
 *
 * @param c items must implement DataCollectionItem
 *//*from  www  . jav  a  2 s.com*/
public static Collection removeByPrimaryKey(Collection c, Object... primaryKeys) {
    Collection removed = findByPrimaryKey(c, primaryKeys);
    Iterator remove = removed.iterator();
    while (remove.hasNext()) {
        c.remove(remove.next());
    }
    return removed;
}