Example usage for java.util HashSet removeAll

List of usage examples for java.util HashSet removeAll

Introduction

In this page you can find the example usage for java.util HashSet removeAll.

Prototype

boolean removeAll(Collection<?> c);

Source Link

Document

Removes from this set all of its elements that are contained in the specified collection (optional operation).

Usage

From source file:Main.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    HashSet<String> set = new HashSet<String>(Arrays.asList(elements));

    elements = new String[] { "B", "D", "F", "G", "1", "2", "3", "4" };
    HashSet<String> set2 = new HashSet<String>(Arrays.asList(elements));

    set.removeAll(set2);
    System.out.println(set);//  www.jav  a2 s.  c  o  m
}

From source file:Main.java

/**
 * Gets the changes made to the a list of items
 * /*from  w  w w  .j a  va 2 s .com*/
 * @return HashMap the a list of items removed from the original list and a
 *         list of items added to the original list
 * */
public static <T> HashMap<String, HashSet<T>> getChangesToList(List<T> original, List<T> edited) {
    HashMap<String, HashSet<T>> changeSet = new HashMap<String, HashSet<T>>();
    HashSet<T> removed = new HashSet<T>(original);
    HashSet<T> added = new HashSet<T>(edited);
    removed.removeAll(edited);
    added.removeAll(original);

    changeSet.put(REMOVED_TAG, removed);
    changeSet.put(ADDED_TAG, added);

    return changeSet;
}

From source file:Main.java

/**
 * Returns the set-theoretic difference between the first and the additional
 * collections, i.e. a set containing all elements that occur in the first,
 * but not in any of the other collections. We use a {@link HashSet}, so the
 * elements should support hashing.//from   www.j av a  2s  .c o  m
 */
@SafeVarargs
public static <T> HashSet<T> differenceSet(Collection<T> collection1, Collection<T>... furtherCollections) {
    HashSet<T> result = new HashSet<T>(collection1);
    for (Collection<T> collection : furtherCollections) {
        if (collection instanceof Set) {
            result.removeAll(collection);
        } else {
            // if the collection is not already a set, it will be
            // significantly faster to first build a set, to speed up the
            // containment query in the following call.
            result.removeAll(new HashSet<T>(collection));
        }
    }
    return result;
}

From source file:org.apache.kylin.cube.CubeCapabilityChecker.java

private static Set<TblColRef> unmatchedDimensions(Collection<TblColRef> dimensionColumns, CubeInstance cube) {
    HashSet<TblColRef> result = Sets.newHashSet(dimensionColumns);
    CubeDesc cubeDesc = cube.getDescriptor();
    result.removeAll(cubeDesc.listDimensionColumnsIncludingDerived());
    return result;
}

From source file:org.apache.kylin.cube.CubeCapabilityChecker.java

private static Set<FunctionDesc> unmatchedAggregations(Collection<FunctionDesc> aggregations,
        CubeInstance cube) {/*  w  ww  .  j  ava 2  s . co m*/
    HashSet<FunctionDesc> result = Sets.newHashSet(aggregations);
    CubeDesc cubeDesc = cube.getDescriptor();
    result.removeAll(cubeDesc.listAllFunctions());
    return result;
}

From source file:edu.tum.cs.conqat.quamoco.qiesl.QIESLEngine.java

/** Computes the set difference */
public static <T> Set<T> difference(Set<T> set1, Set<T> set2) {
    HashSet<T> result = new HashSet<T>(set1);
    result.removeAll(set2);
    return result;
}

From source file:pt.ist.maidSyncher.domain.MaidRoot.java

@SuppressWarnings("unused")
@Atomic(mode = TxMode.WRITE)/*from  w w  w . j  a v  a 2s  .  co m*/
private static void registerPropertyDescriptorNotConsideredWarning(
        Collection<String> changedPropertyDescriptors, Collection<String> propertyDescriptorsTicked,
        SyncEvent syncEvent) {
    StringBuilder exceptionMessageBuilder = new StringBuilder();
    exceptionMessageBuilder
            .append("One didn't consider a property descriptor change. Property descriptors not ticked: ");
    HashSet<String> copyOfChangedDescriptors = new HashSet<>(changedPropertyDescriptors);
    copyOfChangedDescriptors.removeAll(propertyDescriptorsTicked);
    for (String propertyDescriptor : copyOfChangedDescriptors) {
        exceptionMessageBuilder.append(propertyDescriptor + " ");
    }
    if (syncEvent != null && syncEvent.getOriginObject() != null) {
        exceptionMessageBuilder
                .append("Class of origin object: " + syncEvent.getOriginObject().getClass().getName());

    } else {
        exceptionMessageBuilder.append("Class of Origin object unknown because syncEvent is null.");
    }

    new SyncWarningLog(MaidRoot.getInstance().getCurrentSyncLog(), exceptionMessageBuilder.toString());

}

From source file:org.apache.sling.distribution.packaging.impl.DistributionPackageUtils.java

public static boolean release(File file, @Nonnull String[] holderNames) throws IOException {
    if (holderNames.length == 0) {
        throw new IllegalArgumentException("holder name cannot be null or empty");
    }/*from  w  w w.  j a v  a  2s  .  co m*/

    synchronized (filelock) {
        try {

            HashSet<String> set = new HashSet<String>();

            if (file.exists()) {
                ObjectInputStream inputStream = getSafeObjectInputStream(new FileInputStream(file));
                set = (HashSet<String>) inputStream.readObject();
                IOUtils.closeQuietly(inputStream);
            }

            set.removeAll(Arrays.asList(holderNames));

            if (set.isEmpty()) {
                FileUtils.deleteQuietly(file);
                return true;
            }

            ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
            outputStream.writeObject(set);
            IOUtils.closeQuietly(outputStream);
        } catch (ClassNotFoundException e) {
            log.error("Cannot release file", e);
        }
    }
    return false;
}

From source file:pku.sei.checkedcoverage.slicing.Slicer.java

/**
 * get unchecked map, based on covered map and checked map.
 * @return//from  ww w  . ja va  2 s.  c om
 */
public static HashMap<String, HashSet<Instruction>> getUncheckedMap() {
    HashMap<String, HashSet<Instruction>> uncheckedMap = new HashMap<String, HashSet<Instruction>>();
    HashMap<String, HashSet<Instruction>> covered = TraceResult.getCoveredInsts();
    HashMap<String, HashSet<Instruction>> checked = getCheckedLines();
    Iterator<String> keys = covered.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        HashSet<Instruction> unchecked = new HashSet<Instruction>(covered.get(key));
        unchecked.removeAll(checked.get(key));
        uncheckedMap.put(key, unchecked);
    }
    return uncheckedMap;
}

From source file:org.apache.accumulo.server.init.Initialize.java

private static void addVolumes(VolumeManager fs) throws IOException {

    String[] volumeURIs = VolumeConfiguration.getVolumeUris(SiteConfiguration.getInstance());

    HashSet<String> initializedDirs = new HashSet<String>();
    initializedDirs.addAll(Arrays.asList(ServerConstants.checkBaseUris(volumeURIs, true)));

    HashSet<String> uinitializedDirs = new HashSet<String>();
    uinitializedDirs.addAll(Arrays.asList(volumeURIs));
    uinitializedDirs.removeAll(initializedDirs);

    Path aBasePath = new Path(initializedDirs.iterator().next());
    Path iidPath = new Path(aBasePath, ServerConstants.INSTANCE_ID_DIR);
    Path versionPath = new Path(aBasePath, ServerConstants.VERSION_DIR);

    UUID uuid = UUID.fromString(ZooUtil.getInstanceIDFromHdfs(iidPath, SiteConfiguration.getInstance()));
    for (Pair<Path, Path> replacementVolume : ServerConstants.getVolumeReplacements()) {
        if (aBasePath.equals(replacementVolume.getFirst()))
            log.error(aBasePath + " is set to be replaced in " + Property.INSTANCE_VOLUMES_REPLACEMENTS
                    + " and should not appear in " + Property.INSTANCE_VOLUMES
                    + ". It is highly recommended that this property be removed as data could still be written to this volume.");
    }//from   ww w  .  j  a  v  a  2 s.c  om

    if (ServerConstants.DATA_VERSION != Accumulo.getAccumuloPersistentVersion(
            versionPath.getFileSystem(CachedConfiguration.getInstance()), versionPath)) {
        throw new IOException("Accumulo " + Constants.VERSION + " cannot initialize data version "
                + Accumulo.getAccumuloPersistentVersion(fs));
    }

    initDirs(fs, uuid, uinitializedDirs.toArray(new String[uinitializedDirs.size()]), true);
}