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:io.seldon.clustering.recommender.RecommendationContext.java

public static RecommendationContext buildContext(String client, AlgorithmStrategy strategy, Long user,
        String clientUserId, Long currentItem, Set<Integer> dimensions, String lastRecListUUID,
        int numRecommendations, DefaultOptions defaultOptions, FilteredItems includedItems) {

    OptionsHolder optsHolder = new OptionsHolder(defaultOptions, strategy.config);
    List<String> inclusionKeys = new ArrayList<String>();
    Set<Long> contextItems = new HashSet<>();

    if (includedItems != null) {
        contextItems.addAll(includedItems.getItems());
        inclusionKeys.add(includedItems.getCachingKey());
        return new RecommendationContext(MODE.INCLUSION, contextItems, Collections.<Long>emptySet(),
                inclusionKeys, currentItem, lastRecListUUID, optsHolder);
    }// w  ww .  j  av a2  s. co m

    Set<ItemIncluder> inclusionProducers = strategy.includers;
    Set<ItemFilter> itemFilters = strategy.filters;
    if (inclusionProducers == null || inclusionProducers.size() == 0) {
        if (itemFilters == null || itemFilters.size() == 0) {
            logger.warn("No filters or includers present in strategy");
            return new RecommendationContext(MODE.NONE, Collections.<Long>emptySet(),
                    Collections.<Long>emptySet(), Collections.<String>emptyList(), currentItem, lastRecListUUID,
                    optsHolder);
        }
        for (ItemFilter filter : itemFilters) {
            contextItems.addAll(filter.produceExcludedItems(client, user, clientUserId, optsHolder, currentItem,
                    lastRecListUUID, numRecommendations));
        }
        return new RecommendationContext(MODE.EXCLUSION, contextItems, contextItems, inclusionKeys, currentItem,
                lastRecListUUID, optsHolder);
    }

    Integer itemsPerIncluder = optsHolder.getIntegerOption(ITEMS_PER_INCLUDER_OPTION_NAME);
    if (itemFilters == null || itemFilters.size() == 0) {
        for (ItemIncluder producer : inclusionProducers) {
            FilteredItems filteredItems = producer.generateIncludedItems(client, dimensions, itemsPerIncluder);
            contextItems.addAll(filteredItems.getItems());
            inclusionKeys.add(filteredItems.getCachingKey());
        }
        return new RecommendationContext(MODE.INCLUSION, contextItems, Collections.<Long>emptySet(),
                inclusionKeys, currentItem, lastRecListUUID, optsHolder);
    }

    Set<Long> included = new HashSet<>();
    Set<Long> excluded = new HashSet<>();
    for (ItemFilter filter : itemFilters) {
        excluded.addAll(filter.produceExcludedItems(client, user, clientUserId, optsHolder, currentItem,
                lastRecListUUID, numRecommendations));
    }
    for (ItemIncluder producer : inclusionProducers) {
        FilteredItems filteredItems = producer.generateIncludedItems(client, dimensions, itemsPerIncluder);
        included.addAll(filteredItems.getItems());
        inclusionKeys.add(filteredItems.getCachingKey());
    }
    included.removeAll(excluded); // ok to do this as the excluded items that weren't in "included" will never
                                  // be recommended

    return new RecommendationContext(MODE.INCLUSION, included, excluded, inclusionKeys, currentItem,
            lastRecListUUID, optsHolder);
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static <V extends Node> Set<Edge<V>> removeNodelessEdges(Set<Edge<V>> edges, Set<V> nodes) {
    Set<Edge<V>> removed = edges.stream()
            .filter(e -> !nodes.contains(e.getFrom()) || !nodes.contains(e.getTo()))
            .collect(Collectors.toCollection(LinkedHashSet::new));

    edges.removeAll(removed);

    return removed;
}

From source file:com.liferay.events.global.mobile.Utils.java

public static double getInterestLikeness(EventContact me, EventContact targetContact) throws JSONException {

    JSONArray words1o = JSONFactoryUtil.createJSONArray(me.getInterests());
    JSONArray words2o = JSONFactoryUtil.createJSONArray(targetContact.getInterests());

    List<String> words1 = new ArrayList<String>();
    List<String> words2 = new ArrayList<String>();
    Map<String, Integer> count1 = new HashMap<String, Integer>();
    Map<String, Integer> count2 = new HashMap<String, Integer>();
    Map<String, Double> weight1 = new HashMap<String, Double>();
    Map<String, Double> weight2 = new HashMap<String, Double>();

    for (int i = 0; i < words1o.length(); i++) {
        JSONObject o = words1o.getJSONObject(i);

        String word = o.getString("word");
        int count = o.getInt("count");
        double weight = o.getDouble("weight");

        words1.add(word);//from  ww w.  j a  va  2s  . c  om
        count1.put(word, count);
        weight1.put(word, weight);
    }

    for (int i = 0; i < words2o.length(); i++) {
        JSONObject o = words2o.getJSONObject(i);

        String word = o.getString("word");
        int count = o.getInt("count");
        double weight = o.getDouble("weight");

        words2.add(word);
        count2.put(word, count);
        weight2.put(word, weight);
    }

    Set<String> commonWords = new HashSet<String>(words1);
    commonWords.retainAll(words2);

    Set<String> uncommonWords = new HashSet<String>(words1);
    uncommonWords.addAll(words2);
    uncommonWords.removeAll(commonWords);

    double matchedScore = 0.0;
    double unmatchedScore = 0.0;

    for (String commonWord : commonWords) {
        matchedScore += (((double) count1.get(commonWord) * weight1.get(commonWord))
                + (((double) count2.get(commonWord) * weight2.get(commonWord))));
    }

    for (String uncommonWord : uncommonWords) {
        if (words1.contains(uncommonWord)) {
            unmatchedScore += ((double) count1.get(uncommonWord) * weight1.get(uncommonWord));
        } else {
            unmatchedScore += ((double) count2.get(uncommonWord) * weight2.get(uncommonWord));
        }
    }

    return unmatchedScore > 0 ? ((matchedScore * 2.0) / (unmatchedScore + (matchedScore * 2.0))) : 1.0;
}

From source file:org.zenoss.zep.dao.impl.EventDaoHelper.java

public static Map<String, EventDetail> mergeDetails(List<EventDetail> oldDetails,
        List<EventDetail> newDetails) {

    Map<String, EventDetail> detailsMap = new LinkedHashMap<String, EventDetail>(
            oldDetails.size() + newDetails.size());
    for (EventDetail detail : oldDetails) {
        detailsMap.put(detail.getName(), detail);
    }/*from   w ww  .j a  va 2  s .c o m*/
    for (EventDetail newDetail : newDetails) {
        final EventDetailMergeBehavior mergeBehavior = newDetail.getMergeBehavior();
        if (mergeBehavior == EventDetailMergeBehavior.REPLACE) {
            // If a new detail specifies an empty value, it is removed
            if (newDetail.getValueCount() == 0) {
                detailsMap.remove(newDetail.getName());
            } else {
                detailsMap.put(newDetail.getName(), newDetail);
            }
        } else {
            final EventDetail existing = detailsMap.get(newDetail.getName());
            if (existing == null) {
                detailsMap.put(newDetail.getName(), newDetail);
            } else if (mergeBehavior == EventDetailMergeBehavior.APPEND) {
                final EventDetail.Builder merged = EventDetail.newBuilder(existing);
                merged.addAllValue(newDetail.getValueList());
                detailsMap.put(newDetail.getName(), merged.build());
            } else if (mergeBehavior == EventDetailMergeBehavior.UNIQUE) {
                final EventDetail.Builder merged = EventDetail.newBuilder(existing);
                final Set<String> newValues = new LinkedHashSet<String>(newDetail.getValueList());
                newValues.removeAll(existing.getValueList());
                merged.addAllValue(newValues);
                detailsMap.put(newDetail.getName(), merged.build());
            } else {
                logger.warn("Unsupported merge behavior: {}", mergeBehavior);
            }
        }
    }
    return detailsMap;
}

From source file:org.opendatakit.security.server.SecurityServiceUtil.java

/**
 * Given a collection of users, ensure that each user is a registered user (creating a registered
 * user if one doesn't exist).//from   w w w  .j  av  a  2  s .c  om
 * </p>
 * <p>
 * The collection is assumed to be exhaustive. Users not in the list will be deleted.
 * </p>
 *
 * @param users
 * @param cc
 * @return map of users to their Uri strings
 * @throws DatastoreFailureException
 * @throws AccessDeniedException
 */
private static Map<UserSecurityInfo, String> setUsers(ArrayList<UserSecurityInfo> users, CallingContext cc)
        throws DatastoreFailureException, AccessDeniedException {
    List<UserSecurityInfo> allUsersList = getAllUsers(false, cc);

    Set<UserSecurityInfo> removedUsers = new TreeSet<UserSecurityInfo>();
    removedUsers.addAll(allUsersList);
    removedUsers.removeAll(users);

    Datastore ds = cc.getDatastore();
    User user = cc.getCurrentUser();

    Map<UserSecurityInfo, String> pkMap = new HashMap<UserSecurityInfo, String>();
    try {
        // mark absent users as removed...
        for (UserSecurityInfo u : removedUsers) {
            if (u.getType() != UserType.REGISTERED)
                continue;
            RegisteredUsersTable t;
            if (u.getUsername() == null) {
                t = RegisteredUsersTable.getUniqueUserByEmail(u.getEmail(), ds, user);
            } else {
                t = RegisteredUsersTable.getUniqueUserByUsername(u.getUsername(), ds, user);
            }
            if (t != null) {
                t.setIsRemoved(true);
                ds.putEntity(t, user);
            }
        }
        // go through all other users. Assert that they exist.
        // This will update the fields to match those specified.
        for (UserSecurityInfo u : users) {
            if (u.getType() != UserType.REGISTERED)
                continue;
            RegisteredUsersTable t = RegisteredUsersTable.assertActiveUserByUserSecurityInfo(u, cc);
            pkMap.put(u, t.getUri());
        }
    } catch (ODKDatastoreException e) {
        e.printStackTrace();
        throw new DatastoreFailureException("Incomplete security update", e);
    }
    return pkMap;
}

From source file:com.github.rinde.rinsim.scenario.measure.Metrics.java

static ImmutableList<Double> sum(long st, List<LoadPart> parts, int num) {
    checkArgument(num >= 1);//from  w  ww. ja  va2s. c o  m
    final ImmutableList.Builder<Double> builder = ImmutableList.builder();
    long i = st;
    final Set<LoadPart> partSet = newLinkedHashSet(parts);
    while (!partSet.isEmpty()) {
        double currentLoadVal = 0d;
        final List<LoadPart> toRemove = newArrayList();
        for (final LoadPart lp : partSet) {
            if (lp.isIn(i)) {
                currentLoadVal += lp.get(i);
            }
            if (!lp.isBeforeEnd(i)) {
                toRemove.add(lp);
            }
        }
        partSet.removeAll(toRemove);

        if (!partSet.isEmpty()) {
            if (num > 1) {
                currentLoadVal /= num;
            }
            builder.add(currentLoadVal);
            i++;
        }
    }
    return builder.build();
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static <V extends Node> Set<V> removeEdgelessNodes(Set<V> nodes, Set<Edge<V>> edges) {
    Set<V> nodesWithEdges = new LinkedHashSet<>();

    for (Edge<V> edge : edges) {
        nodesWithEdges.add(edge.getFrom());
        nodesWithEdges.add(edge.getTo());
    }/*  w  w  w.j  a v a  2 s.c om*/

    Set<V> removed = new LinkedHashSet<>(Sets.difference(nodes, nodesWithEdges));

    nodes.removeAll(removed);

    return removed;
}

From source file:io.sloeber.core.managers.Manager.java

/**
 * This method removes the json files from disk and removes memory
 * references to these files or their content
 *
 * @param packageUrlsToRemove/*from  w  w w  . ja v a  2  s .  c o  m*/
 */
public static void removeBoardsPackageURLs(Set<String> packageUrlsToRemove) {
    // remove the files from memory
    Set<String> activeBoardUrls = new HashSet<>(
            Arrays.asList(ConfigurationPreferences.getBoardsPackageURLList()));

    activeBoardUrls.removeAll(packageUrlsToRemove);

    ConfigurationPreferences.setBoardsPackageURLs(activeBoardUrls.toArray(null));

    // remove the files from disk
    for (String curJson : packageUrlsToRemove) {
        File localFile = getLocalFileName(curJson);
        if (localFile.exists()) {
            localFile.delete();
        }
    }

    // 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
    loadIndices(false);

}

From source file:SetExampleV2.java

public void resolveCollision(CompositeSet comp, Set existing, Set added, Collection intersection) {

    added.removeAll(intersection);
}

From source file:com.centeractive.ws.builder.soap.SchemaUtils.java

/**
 * Extracts namespaces - used in tool integrations for mapping..
 */// w  ww .j  a v  a  2  s  .  c  om

public static Collection<String> extractNamespaces(SchemaTypeSystem schemaTypes, boolean removeDefault) {
    Set<String> namespaces = new HashSet<String>();
    SchemaType[] globalTypes = schemaTypes.globalTypes();
    for (int c = 0; c < globalTypes.length; c++) {
        namespaces.add(globalTypes[c].getName().getNamespaceURI());
    }

    if (removeDefault) {
        namespaces.removeAll(defaultSchemas.keySet());
        namespaces.remove(Constants.SOAP11_ENVELOPE_NS);
        namespaces.remove(Constants.SOAP_ENCODING_NS);
    }

    return namespaces;
}