Example usage for java.util Set removeAll

List of usage examples for java.util Set removeAll

Introduction

In this page you can find the example usage for java.util Set 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 <T> Set<T> subtract(Set<T> set1, Set<T> set2) {
    if (set1 == null || set2 == null) {
        return null;
    }//  ww  w .  jav  a 2  s.c o m
    Set<T> result = createHashSet(set1);
    result.removeAll(set2);
    return result;
}

From source file:Main.java

/**
 * Appends value to collection. If value is collection all elements are added, if value is object it is simply
 * added. If skipDuplicates is set to true, objects already contained in the collection are not added again. Note
 * that element would be type casted to collection type.
 * //from   w w w.  j a  v  a  2s .  co  m
 * @param data
 *            is the collection to update - set, list, etc. Should be modifiable
 * @param value
 *            is value of type T or {@link Collection} of elements of type T
 * @param skipDuplicates
 *            whether to treat data as {@link Set}. Note if data is already {@link Set} parameter does not affect
 *            the result. Note if data already contains duplicate elements they are not affected.
 * @return the updated data collection
 */
@SuppressWarnings("unchecked")
public static <T> Collection<T> addValue(Collection<T> data, Object value, boolean skipDuplicates) {
    if (value instanceof Collection) {
        Collection<T> toBeAdded = (Collection<T>) value;
        if (skipDuplicates && !(data instanceof Set)) {
            Set<T> nonDuplicates = new LinkedHashSet<>(toBeAdded);
            nonDuplicates.removeAll(data);
            data.addAll(nonDuplicates);
        } else {
            data.addAll(toBeAdded);
        }
    } else if (value != null) {
        if (skipDuplicates && !(data instanceof Set) && data.contains(value)) {
            return data;
        }
        data.add((T) value);
    }
    return data;
}

From source file:Main.java

/**
 * Test whether col2 is contained in col1.
 * // w w  w .  j ava 2 s. c  om
 * @param <T> type of collection
 * @param col1 the first collection
 * @param col2 the second collection
 * @return <code>null</code> if col1 contains all of col2, else return the extra items that col2
 *         have.
 */
static public <T> Set<T> contains(final Set<T> col1, final Set<T> col2) {
    if (col1.containsAll(col2))
        return null;
    else {
        final Set<T> names = new HashSet<T>(col2);
        names.removeAll(col1);
        return names;
    }
}

From source file:Main.java

public static Set intersection(Set one, Set two) {
    Set big, small;
    if (one.size() >= two.size()) {
        big = new HashSet(one);
        small = two;/*w  ww  .j  av  a2 s . co m*/
    } else {
        big = new HashSet(two);
        small = one;
    }
    big.removeAll(small);
    return big;
}

From source file:cc.kave.commons.pointsto.evaluation.cv.CVEvaluator.java

private static Set<ICoReMethodName> getExpectation(Usage validationUsage, Query q) {
    Set<CallSite> missingCallsites = new HashSet<>(validationUsage.getReceiverCallsites());
    missingCallsites.removeAll(q.getAllCallsites());

    Set<ICoReMethodName> expectation = new HashSet<>(missingCallsites.size());
    for (CallSite callsite : missingCallsites) {
        expectation.add(callsite.getMethod());
    }/*from w w  w. j av  a 2 s  . c o m*/
    return expectation;
}

From source file:com.eryansky.common.utils.collections.Collections3.java

/**
 * ?list2list1??//w  w  w  . j a v  a2  s  .  com
 * ???List?hashcodeequals
 * A={2,3} comple B={1,1,2,6} => C={1,6}
 * @param a
 * @param b
 * @return
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public static <T> List<T> comple(Collection<T> a, Collection<T> b) {
    Set<T> set = new LinkedHashSet();
    set.addAll(a);
    set.removeAll(intersection(a, b));
    return new ArrayList(set);
}

From source file:tr.edu.gsu.nerwip.recognition.internal.modelless.subee.SubeeTools.java

/**
 * Updates the file containing unknown types so that it contains
 * all types retrieved from Freebase not already present in the
 * existing type files./*  w  ww  .  j  a  v a  2 s. c om*/
 * 
 * @throws RecognizerException 
 *       Problem while loading/retrieving the FB types.
 * @throws org.json.simple.parser.ParseException 
 *       Problem while loading/retrieving the FB types.
 * @throws IOException 
 *       Problem while loading/retrieving the FB types.
 * @throws ClientProtocolException 
 *       Problem while loading/retrieving the FB types.
 */
public static void updateUnknownTypes() throws RecognizerException, ClientProtocolException, IOException,
        org.json.simple.parser.ParseException {
    logger.setName("Updating-Subee-List");
    logger.log("Updating Subee unknown FB types list");

    // build Subee and loads the necessary files
    logger.log("Load the Subee files");
    Subee subee = new Subee(true, true, true, true, true);
    subee.prepareRecognizer();

    // retrieve the loaded lists
    logger.log("Get the existing type lists from these files");
    Set<String> knownTypes = new TreeSet<String>();
    knownTypes.addAll(Subee.TYPE_MAP.keySet());
    knownTypes.addAll(Subee.UNKNOWN_TYPES);

    // retrieve the last types from Freebase
    logger.log("Get the last type from Freebase");
    Set<String> fbTypes = FbTypeTools.retrieveDomainTypes();

    // retain only the unknown ones
    logger.log("Udpdate the 'unknown' file");
    fbTypes.removeAll(knownTypes);

    // append them to the 'unknown' file
    subee.updateUnknownTypes("-NOT A TYPE^^---------------------");
    for (String type : fbTypes)
        subee.updateUnknownTypes(type);
}

From source file:eu.h2020.symbiote.ontology.validation.ValidationHelper.java

public static Set<String> getUndefinedButUsedClasses(OntModel model) {
    Set<String> definedClasses = getDefinedClasses(model);
    Set<String> usedClasses = getUsedClasses(model);
    usedClasses.removeAll(definedClasses);
    return usedClasses;
}

From source file:de.xwic.appkit.core.transport.xml.EtoSerializer.java

/**
 * @param proxy//from   www  .  j  av a 2  s .c om
 * @param to
 * @param type
 * @return
 * @throws IntrospectionException
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 */
private static IEntity transferData(final IEntity proxy, final Class<? extends IEntity> type)
        throws IntrospectionException, IllegalArgumentException, IllegalAccessException,
        InvocationTargetException {

    final IEntity result = EntityUtil.createEntity(type);
    Map<String, PropertyDescriptor> objectProp = getMap(result);
    Map<String, PropertyDescriptor> proxyProp = getMap(proxy);
    Set<String> allSet = new HashSet<String>(objectProp.keySet());
    allSet.addAll(proxyProp.keySet());
    allSet.removeAll(IGNORE_PROPERTIES);
    for (String prop : allSet) {
        if (proxyProp.containsKey(prop) && objectProp.containsKey(prop)) {
            Method readMethod = proxyProp.get(prop).getReadMethod();
            Method writeMethod = objectProp.get(prop).getWriteMethod();
            if (readMethod == null || writeMethod == null) {
                System.out.println("Illegal " + prop);
                continue;
            }
            writeMethod.invoke(result, readMethod.invoke(proxy));
        }
    }

    return result;
}

From source file:eu.h2020.symbiote.ontology.validation.ValidationHelper.java

public static Map<Resource, Model> sepearteResources(OntModel instances, Model pim) {
    Map<Resource, Model> result = new HashMap<>();
    instances.addSubModel(pim);/*from ww  w  . j  ava 2  s.c  o  m*/
    Set<Individual> resourcesDefinedInPIM = ModelHelper.withInf(pim).listIndividuals(CIM.Resource).toSet();
    Set<Individual> resourceIndividuals = instances.listIndividuals(CIM.Resource).toSet();
    resourceIndividuals.removeAll(resourcesDefinedInPIM);
    instances.removeSubModel(pim);
    for (Individual resource : resourceIndividuals) {
        GET_RESOURCE_CLOSURE.setIri(TAG_RESOURCE_URI, resource.getURI());
        try (QueryExecution qexec = QueryExecutionFactory.create(GET_RESOURCE_CLOSURE.asQuery(),
                instances.getRawModel())) {
            Model resourceClosure = qexec.execConstruct();
            result.put(resourceClosure.getResource(resource.getURI()), resourceClosure);
        }
    }
    return result;
}