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:io.sloeber.core.managers.Manager.java

/**
 * Completely replace the list with jsons with a new list
 *
 * @param newBoardJsonUrls//from  w  ww.  j av  a  2 s . c om
 */
public static void setBoardsPackageURL(String[] newBoardJsonUrls) {

    String curJsons[] = getBoardsPackageURLList();
    HashSet<String> origJsons = new HashSet<>(Arrays.asList(curJsons));
    HashSet<String> currentSelectedJsons = new HashSet<>(Arrays.asList(newBoardJsonUrls));
    currentSelectedJsons.removeAll(origJsons);
    // remove the files from disk which were in the old lst but not in the
    // new one
    for (String curJson : currentSelectedJsons) {
        File localFile = getLocalFileName(curJson);
        if (localFile.exists()) {
            localFile.delete();
        }
    }
    // save to configurationsettings before calling LoadIndices
    ConfigurationPreferences.setBoardsPackageURLs(newBoardJsonUrls);
    // reload the indices (this will remove all potential remaining
    // references
    // existing files do not need to be refreshed as they have been
    // refreshed at startup
    // new files will be added
    loadIndices(false);
}

From source file:util.LdapUtil.java

/**
* removeElements() remove the elements from list1 that are in list2 and return list1.
* @param list1 remove the elements that contains in the list2
* @param list2  has elements that need to be removed from list1
* @return List return the list of elements from the list1
*//*from  w  w  w . j a v a  2  s  .c  o m*/
public static List removeElements(List list1, List list2) throws Exception {

    if (list1 == null) {
        throw new Exception("list1 is null");
    }

    if (list2 == null) {
        return list1;
    }

    HashSet hs1 = new HashSet((List) list1);
    logger.info(" list1= " + list1.size() + " hs1 = " + hs1.size());

    HashSet hs2 = new HashSet((List) list2);
    logger.info(" list2= " + list2.size() + " hs2 = " + hs2.size());

    if (hs1 != null && hs2 != null) {
        if (hs1.removeAll(hs2)) {
            logger.info("removed the elements of list2 from list1" + hs1.size());
        } else {
            logger.info("did not find any elements of list1 in list2" + hs1.size());
        }
    }
    logger.info("hs1 = " + hs1.toString());

    if (hs1 != null) {
        return new ArrayList(hs1);
    } else {
        return null;
    }
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.common.vbb.impl.RecursiveCluster.java

private static Set<UniversalModelExpression> getHierarchyRoot(Model model, SubstantialTypeExpression clazz,
        RelationshipEndExpression ref) {
    Collection<InstanceExpression> outers = model.findAll(clazz);

    // Find the most outer objects. Removes all objects from the list of objects
    // with type outer that have an incoming outer2outer relation. This leaves only
    // the most outer objects in the list.
    HashSet<UniversalModelExpression> fullOuters = new HashSet<UniversalModelExpression>(outers);

    // As the hierarchy is optional, it might not be set
    if (ref != null) {
        //unfold the relationship to find the hierarchy roots even if some nodes in between paths to the root are filtered out
        UnfoldRelationshipEnd unfolded = new UnfoldRelationshipEnd(ref);
        for (InstanceExpression outerObject : outers) {
            if (!outerObject.getConnecteds(unfolded).isEmpty()) {
                fullOuters.removeAll(outerObject.getConnecteds(unfolded));
            }/*from   w w w .ja  v a2 s  .  c  o  m*/
        }
    }

    return fullOuters;
}

From source file:jef.tools.ArrayUtils.java

/**
 * ?(??ls??ls2) ???ls??ls2/*  www . j a  va2s. c  o  m*/
 * 
 * @param ls
 * @param ls2
 * @return
 */
public static Object[] minus(Object[] ls, Object[] ls2) {
    HashSet<Object> set = new HashSet<Object>(Arrays.asList(ls));
    set.removeAll(Arrays.asList(ls2));
    return set.toArray();
}

From source file:com.goncalomb.bukkit.nbteditor.TestBosEntities.java

@Test
public void testBosEntities() {
    HashSet<EntityType> entityTypes = new HashSet<EntityType>();
    entityTypes.addAll(Arrays.asList(EntityType.values()));
    entityTypes.removeAll(EntityNBT.getValidEntityTypes());
    if (!entityTypes.isEmpty()) {
        System.out.print("Missing BoS entities: ");
        System.out.print(StringUtils.join(entityTypes, ", "));
        System.out.println(".");
    }/*from  w  w  w.j a va  2 s  .c  o  m*/
}

From source file:jasima.core.util.ExperimentTest.java

/**
 * Checks whether key sets of actual and expected results are the same.
 * /*from  w  w  w.  jav  a  2  s .  c o m*/
 * @param resActual
 *            The map of results actually obtained.
 * @param resExpected
 *            The map of expected results.
 */
protected void checkKeySets(Map<String, Object> resActual, Map<String, Object> resExpected) {
    Set<String> keysAct = new HashSet<String>(resActual.keySet());
    Set<String> keysExp = new HashSet<String>(resExpected.keySet());

    HashSet<String> all = new HashSet<String>();
    all.addAll(keysAct);
    all.addAll(keysExp);

    HashSet<String> onlyExp = new HashSet<String>(all);
    onlyExp.removeAll(keysAct);

    HashSet<String> onlyAct = new HashSet<String>(all);
    onlyAct.removeAll(keysExp);
    errorCollector.checkThat("key sets should be equal.\n" + "keys missing in actual result map: " + onlyExp
            + ";\n" + "keys only in actual result map: " + onlyAct, keysAct, is(keysExp));
}

From source file:herddb.cluster.PreferLocalBookiePlacementPolicy.java

@Override
public synchronized Set<BookieSocketAddress> onClusterChanged(Set<BookieSocketAddress> writableBookies,
        Set<BookieSocketAddress> readOnlyBookies) {
    HashSet<BookieSocketAddress> deadBookies;
    deadBookies = new HashSet<>(knownBookies);
    deadBookies.removeAll(writableBookies);
    // readonly bookies should not be treated as dead bookies
    deadBookies.removeAll(readOnlyBookies);
    knownBookies = writableBookies;/*from w w w.  j  av  a 2  s .  c  om*/
    return deadBookies;
}

From source file:util.MysqlSearch.java

public HashSet getUniqueTags(HashSet tagSet1, HashSet tagSet2) {
    if (tagSet1 != null && tagSet2 != null) {
        tagSet1.removeAll(tagSet2);
        tagSet1.addAll(tagSet2);//from   ww  w  .  j ava 2  s.co m
    }
    if (tagSet1 == null && tagSet2 != null) {
        return tagSet2;
    }
    return tagSet1;
}

From source file:org.xwalk.runtime.extension.api.contacts.ContactEventListener.java

private HashSet<String> getDiffSet(HashSet<String> setA, HashSet<String> setB) {
    HashSet<String> resultSet = new HashSet<String>();
    resultSet.addAll(setA);//from   www  .  j a  v a  2s.  co  m
    resultSet.removeAll(setB);
    return resultSet;
}

From source file:cc.kave.commons.model.groum.SubGroum.java

private Node findRoot() {
    HashSet<Node> candidates = new HashSet<>(nodes);
    for (Node node : nodes) {
        Set<Node> successors = getSuccessors(node);
        candidates.removeAll(successors);
    }/*from   w w  w . j  a  v  a2  s  .c o  m*/
    if (candidates.size() == 1) {
        return candidates.iterator().next();
    } else {
        throw new IllegalStateException(
                "Groum has no uniquly identifiable root (candidates: " + candidates + ")");
    }
}