Example usage for java.util Set remove

List of usage examples for java.util Set remove

Introduction

In this page you can find the example usage for java.util Set remove.

Prototype

boolean remove(Object o);

Source Link

Document

Removes the specified element from this set if it is present (optional operation).

Usage

From source file:com.parse.ParseRelationOperation.java

private void addParseObjectToSet(ParseObject obj, Set<ParseObject> set) {
    if (Parse.getLocalDatastore() != null || obj.getObjectId() == null) {
        // There's no way there could be duplicate instances.
        set.add(obj);//  w  w w .j av a 2s  .co  m
        return;
    }

    // We have to do this the hard way.
    for (ParseObject existingObject : set) {
        if (obj.getObjectId().equals(existingObject.getObjectId())) {
            set.remove(existingObject);
        }
    }
    set.add(obj);
}

From source file:com.datastax.loader.CqlDelimParser.java

@SuppressWarnings("unchecked")
public List<Object> parseJson(String line) {
    JSONObject jsonObject = null;//from   w  w w.  j  a  v a  2  s .co  m
    try {
        jsonObject = (JSONObject) jsonParser.parse(line);
    } catch (org.json.simple.parser.ParseException e) {
        System.err.println(String.format("Invalid format in input %d: %s", line, e.getMessage()));
        return null;
    }
    String[] row = new String[columnNames.size()];
    Set<String> fields = (Set<String>) jsonObject.keySet();
    for (int i = 0; i < columnNames.size(); i++) {
        String s = columnNames.get(i);
        Object o = jsonObject.get(s);
        if (null != o)
            row[i] = o.toString();
        else
            row[i] = null;
        fields.remove(s);
    }
    if (0 != fields.size()) {
        for (String f : fields) {
            System.err.println("Unknown JSON field " + f);
        }
        return null;
    }
    return parse(row);
}

From source file:cz.strmik.cmmitool.service.RatingServiceImpl.java

@Override
public Set<PracticeImplementationRating> getRatingsOfPracticesOfGoal(Project project, Goal goal) {
    Set<PracticeImplementationRating> pirs = new HashSet<PracticeImplementationRating>();
    Set<Practice> practices = new HashSet<Practice>(goal.getPractices());
    // add rated practices
    for (PracticeImplementationRating pir : project.getPracticeImplementation()) {
        if (practices.contains(pir.getPractice())) {
            pirs.add(pir);/*from  ww w  .  ja va2s . c o m*/
            practices.remove(pir.getPractice());
        }
    }
    // add unrated practices
    RatingScale defaultRating = getDefaultRating(project.getMethod().getPracticeImplementation());
    for (Practice p : practices) {
        PracticeImplementationRating pir = new PracticeImplementationRating();
        pir.setPractice(p);
        pir.setRating(defaultRating);
    }
    return pirs;
}

From source file:edu.umass.cs.reconfiguration.RepliconfigurableReconfiguratorDB.java

/**
 * @param toFilter//  w w  w  .  ja  v  a  2 s  .c o m
 * @return Will modify argument and return it by removing active nodes
 *         either currently being deleted or that have been deleted. Used by
 *         {@link WaitAckDropEpoch} to avoid unnecessary message send
 *         failures.
 */
public Set<NodeIDType> filterDeletedActives(Set<NodeIDType> toFilter) {
    if (this.outstandingActiveDeletion != null)
        toFilter.remove(outstandingActiveDeletion);
    for (Iterator<NodeIDType> nodeIter = toFilter.iterator(); nodeIter.hasNext();) {
        if (this.consistentNodeConfig.getNodeAddress(nodeIter.next()) == null)
            nodeIter.remove();
    }
    return toFilter;
}

From source file:com.netflix.spinnaker.orca.clouddriver.tasks.manifest.ManifestForceCacheRefreshTask.java

private boolean pendingRefreshProcessed(PendingRefresh pendingRefresh, Set<String> refreshedManifests,
        long startTime) {
    PendingRefresh.Details details = pendingRefresh.getDetails();
    if (pendingRefresh.cacheTime == null || pendingRefresh.processedTime == null || details == null) {
        log.warn("Pending refresh of {} is missing cache metadata", pendingRefresh);
        refreshedManifests.remove(toManifestIdentifier(details.getLocation(), details.getName()));
        return false;
    } else if (pendingRefresh.cacheTime < startTime) {
        log.warn("Pending refresh of {} is stale", pendingRefresh);
        refreshedManifests.remove(toManifestIdentifier(details.getLocation(), details.getName()));
        return false;
    } else if (pendingRefresh.processedTime < startTime) {
        log.info("Pending refresh of {} was cached as a part of this request, but not processed",
                pendingRefresh);/*from   w w  w.j  a  va  2 s  . co m*/
        return false;
    } else {
        return true;
    }
}

From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil.java

public static boolean removeFromSetProperty(Node node, String name, Object value, boolean weakRef) {
    try {/*from  w w  w .j a v  a2s. co  m*/
        //            JcrVersionUtil.ensureCheckoutNode(node);

        if (node == null) {
            throw new IllegalArgumentException("Cannot remove a property from a null-node!");
        }
        if (name == null) {
            throw new IllegalArgumentException("Cannot remove a property without a provided name");
        }

        Set<Value> values = new HashSet<>();

        if (node.hasProperty(name)) {
            values = Arrays.stream(node.getProperty(name).getValues()).collect(Collectors.toSet());
        } else {
            values = new HashSet<>();
        }

        Value existingVal = createValue(node.getSession(), value,
                values.stream().anyMatch(v -> v.getType() == PropertyType.WEAKREFERENCE));
        boolean result = values.remove(existingVal);
        node.setProperty(name, (Value[]) values.stream().toArray(size -> new Value[size]));
        return result;
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to remove from set property: " + name + "->" + value, e);
    }
}

From source file:com.redhat.rhn.manager.monitoring.ModifyFilterCommand.java

/**
 * Update the criteria with a match type in <code>rangeSet</code> so that
 * they are all of match type <code>mt</code> and match on the given
 * <code>values</code>. In other words, delete all the criteria with a match type
 * in <code>rangeSet</code> and add new ones with the given match type and values.
 * The routine tries to avoid unnecessary deletions and reinsertions of criteria.
 *//*from  ww  w . j a  v a 2 s.  co m*/
private void updateCriteria(MatchType mt, String[] values) {
    Set rangeSet = MatchType.typesInCategory(mt.getCategory());
    Set s = getCriteria();
    if (values == null) {
        values = new String[0];
    }
    Set newValues = new HashSet(Arrays.asList(values));
    for (Iterator i = s.iterator(); i.hasNext();) {
        Criteria c = (Criteria) i.next();
        if (rangeSet.contains(c.getMatchType())) {
            if (mt.equals(c.getMatchType()) && newValues.contains(c.getValue())) {
                newValues.remove(c.getValue());
            } else {
                i.remove();
            }
        }
    }
    // newValues contains all the values for which we don't
    // have a criteria yet
    for (Iterator i = newValues.iterator(); i.hasNext();) {
        String v = (String) i.next();
        if (!StringUtils.isBlank(v)) {
            filter.addCriteria(mt, v);
        }
    }
}

From source file:com.spotify.heroic.cluster.CoreClusterManager.java

@Override
public AsyncFuture<Void> removeStaticNode(URI node) {
    while (true) {
        final Set<URI> old = staticNodes.get();

        final Set<URI> update = new HashSet<>(staticNodes.get());

        /* node already registered */
        if (!update.remove(node)) {
            return async.resolved();
        }/*w w  w .j av a2 s  . c  o  m*/

        if (staticNodes.compareAndSet(old, update)) {
            break;
        }
    }

    return refresh();
}

From source file:org.jboss.aerogear.sync.server.ServerSyncEngine.java

/**
 * Removes the specified {@link Subscriber}.
 *
 * @param subscriber the {@link Subscriber} to remove
 * @param documentId the document id that the subscriber subscribes to
 *//*from  www. j ava 2s.c  om*/
public void removeSubscriber(final Subscriber<?> subscriber, final String documentId) {
    while (true) {
        final Set<Subscriber<?>> currentClients = subscribers.get(documentId);
        if (currentClients == null || currentClients.isEmpty()) {
            break;
        }
        final Set<Subscriber<?>> newClients = Collections
                .newSetFromMap(new ConcurrentHashMap<Subscriber<?>, Boolean>());
        newClients.addAll(currentClients);
        final boolean removed = newClients.remove(subscriber);
        if (removed) {
            if (subscribers.replace(documentId, currentClients, newClients)) {
                break;
            }
        }
    }
}

From source file:com.vmm.storefront.controllers.pages.ProductPageController.java

/**
 * @param lastBrowsedProducts/*  w w  w .  j a v a2  s  .c om*/
 * @param productCode
 * @param count
 * @return list
 */
private String listLatestBrowsedProducts(final String lastBrowsedProducts, final String productCode,
        final int count) {

    final String[] result = lastBrowsedProducts.split(",");

    final Set<String> uniqueList = new LinkedHashSet<String>(Arrays.asList(result));

    if (result.length >= count) {
        uniqueList.remove(result[0]);
        uniqueList.add(productCode);
    } else if (result.length < count) {
        uniqueList.remove(productCode);
        uniqueList.add(productCode);
    }

    final StringBuilder list = new StringBuilder();
    for (final String str : uniqueList) {
        list.append(str);
        list.append(',');
    }
    list.deleteCharAt(list.length() - 1);

    return list.toString();

}