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:org.elasticsoftware.elasticactors.rabbitmq.cpt.RabbitMQMessagingService.java

@Override
public void removeChannelListener(final Channel channel, final ChannelListener channelListener) {
    final Set<ChannelListener> listeners = this.channelListenerRegistry.get(channel);
    if (listeners != null) {
        listeners.remove(channelListener);
    }/*from   w w w  .j a  va 2  s.  co m*/
}

From source file:com.envision.envservice.service.OrgStructureService.java

/**
 * ?ID//from w  ww.  ja v a  2s . co m
 *       ?ID
 *       ?ID
 *       ?
 * 
 *       
 */
public Set<String> queryEqualLevel(String userId) throws Exception {
    Set<String> userIds = new HashSet<String>();

    for (String higherLevelId : queryHigherLevel(userId)) {
        Set<String> lowerLevelIds = queryLowerLevel(higherLevelId);
        lowerLevelIds.remove(userId);

        userIds.addAll(lowerLevelIds);
    }

    return userIds;
}

From source file:gov.nih.nci.firebird.service.protocol.ProtocolModificationDetector.java

private void checkForOptionalityChanges(String messageKey, Map<FormType, FormOptionality> baseOptionality,
        Map<FormType, FormOptionality> modifiedOptionality) {
    Set<FormType> addedFormTypes = new HashSet<FormType>(modifiedOptionality.keySet());
    for (FormType formType : baseOptionality.keySet()) {
        FormOptionality optionality = baseOptionality.get(formType);
        if (!addedFormTypes.remove(formType)) {
            addModification(messageKey, formType.getDescription(), optionality.getDisplay(),
                    FormOptionality.NONE.getDisplay());
        } else if (optionality != modifiedOptionality.get(formType)) {
            addModification(messageKey, formType.getDescription(), optionality.getDisplay(),
                    modifiedOptionality.get(formType).getDisplay());
        }/*from   w  ww  .j a  v  a 2  s. c  om*/
    }

    for (FormType type : addedFormTypes) {
        addModification(messageKey, type.getDescription(), FormOptionality.NONE.getDisplay(),
                modifiedOptionality.get(type).getDisplay());
    }
}

From source file:io.cloudslang.engine.node.services.WorkerNodeServiceImpl.java

@Override
@Transactional//from ww w. j a v  a2  s .co m
public void updateWorkerGroups(String uuid, String... groupNames) {
    WorkerNode worker = readByUUID(uuid);

    Set<String> groupSet = groupNames != null ? new HashSet<>(Arrays.asList(groupNames))
            : new HashSet<String>();
    List<String> groups = new ArrayList<>();
    groupSet.remove(null);
    groups.addAll(groupSet);

    worker.setGroups(groups);
}

From source file:com.npower.dm.hibernate.management.ClientProvTemplateBeanImpl.java

public void dettach(Model model, ClientProvTemplate template) throws DMException {
    // Checking//from   w  w w .j  av a  2s .  c  o  m
    if (template == null || template.getID() == null || template.getID().longValue() == 0) {
        throw new DMException("Must specified a ClientProvTemplate to attach.");
    }

    if (model == null || model.getID() == 0) {
        throw new DMException("Missing model");
    }
    try {
        ModelClientProvMapId id = new ModelClientProvMapId();
        id.setTemplateId(template.getID().longValue());
        id.setModelId(model.getID());

        ModelClientProvMap modelMapping = (ModelClientProvMap) this.getHibernateSession()
                .get("com.npower.dm.hibernate.entity.ModelClientProvMapEntity", id);

        // Remove from the ModelEntity related
        Set<ModelClientProvMapEntity> set = ((ModelEntity) model).getModelClientProvMaps();
        if (set.contains(modelMapping)) {
            set.remove(modelMapping);
        }

        // Remove from the ModelClientProvMapEntity related
        set = ((ClientProvTemplateEntity) template).getModelClientProvMaps();
        if (set.contains(modelMapping)) {
            set.remove(modelMapping);
        }

        this.getHibernateSession().delete(modelMapping);

    } catch (HibernateException e) {
        throw new DMException(e);
    }
}

From source file:ch.rasc.edsutil.optimizer.graph.Graph.java

private void depResolve(Node node, List<Node> resolved, Set<Node> unresolved)
        throws CircularReferenceException, IOException {
    unresolved.add(node);//from  w w  w .j  a  va2 s .c  o m
    for (Node edge : node.getEdges()) {
        if (!resolved.contains(edge)) {
            if (unresolved.contains(edge)) {
                throw new CircularReferenceException(node, edge);
            }
            depResolve(edge, resolved, unresolved);
        }
    }
    resolved.add(node);
    unresolved.remove(node);
}

From source file:ch.rasc.wampspring.broker.DefaultSubscriptionRegistry.java

protected void removeSessionDestination(String sessionId, String destination) {

    Set<String> destinations = this.sessionDestinations.get(sessionId);
    if (destinations != null) {
        String removedDestination = null;
        String removedSessionId = null;
        synchronized (this.monitor) {
            if (destinations.remove(destination)) {
                removedDestination = destination;
                if (destinations.isEmpty()) {
                    this.sessionDestinations.remove(sessionId);
                    removedSessionId = sessionId;
                }/*from  ww  w.  java  2  s . c om*/
            }
        }
        if (removedDestination != null) {
            this.destinationCache.updateAfterRemovedDestination(sessionId, removedDestination);
        }
        if (removedSessionId != null) {
            this.destinationCache.updateAfterRemovedSession(removedSessionId);
        }
    }

}

From source file:com.dhenton9000.birt.jpa.service.impl.security.GroupsServiceImpl.java

@Override
@Transactional//from   w  w w  . jav a  2s. c  o  m
public Users removeUserFromGroup(Integer userId, Integer groupId) {

    Groups g = this.findOne(groupId);
    if (g == null) {
        throw new ResourceNotFoundException("cannot find group " + groupId);
    }

    Users u = usersRepository.findOne(userId);
    if (u == null) {
        throw new ResourceNotFoundException("cannot find user " + userId);
    }

    if (!g.getUsersSet().contains(u)) {
        throw new ResourceNotFoundException(
                String.format("user %d should be in group %d but isn't", userId, groupId));
    }

    Set<Users> users = g.getUsersSet();
    //        HashSet<Users> cutList = users.stream().filter(ut -> {
    //
    //            return !ut.getUserid().equals(u.getUserid());
    //        }).collect(Collectors.toCollection(HashSet::new));
    users.remove(u);
    g.setUsersSet(users);
    return u;

}

From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaMediaDao.java

/**
 * Populate the droplet media table./*from   w  w  w. j a  va 2  s. co  m*/
 * 
 * @param drops
 */
private void insertDropletMedia(List<Drop> drops) {

    // List of drop IDs in the drops list
    List<Long> dropIds = new ArrayList<Long>();
    // List of media in a drop
    Map<Long, Set<Long>> dropletMediaMap = new HashMap<Long, Set<Long>>();
    // List of drops and the media that is the drop image
    final List<long[]> dropImages = new ArrayList<long[]>();
    for (Drop drop : drops) {

        if (drop.getMedia() == null)
            continue;

        dropIds.add(drop.getId());

        for (Media media : drop.getMedia()) {
            Set<Long> m = null;
            if (dropletMediaMap.containsKey(drop.getId())) {
                m = dropletMediaMap.get(drop.getId());
            } else {
                m = new HashSet<Long>();
                dropletMediaMap.put(drop.getId(), m);
            }

            // Is this the drop image?
            if (drop.getImage() != null && media.getUrl().equals(drop.getImage().getUrl())) {
                long[] dropImage = { drop.getId(), media.getId() };
                dropImages.add(dropImage);
            }

            m.add(media.getId());
        }
    }

    // Find droplet media that already exist in the db
    String sql = "SELECT droplet_id, media_id FROM droplets_media WHERE droplet_id in (:ids)";

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("ids", dropIds);

    List<Map<String, Object>> results = this.namedJdbcTemplate.queryForList(sql, params);

    // Remove already existing droplet_media from our Set
    for (Map<String, Object> result : results) {
        long dropletId = ((Number) result.get("droplet_id")).longValue();
        long mediaId = ((Number) result.get("media_id")).longValue();

        Set<Long> mediaSet = dropletMediaMap.get(dropletId);
        if (mediaSet != null) {
            mediaSet.remove(mediaId);
        }
    }

    // Insert the remaining items in the set into the db
    sql = "INSERT INTO droplets_media (droplet_id, media_id) VALUES (?,?)";

    final List<long[]> dropletMediaList = new ArrayList<long[]>();
    for (Long dropletId : dropletMediaMap.keySet()) {
        for (Long mediaId : dropletMediaMap.get(dropletId)) {
            long[] dropletMedia = { dropletId, mediaId };
            dropletMediaList.add(dropletMedia);
        }
    }
    jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            long[] dropletMedia = dropletMediaList.get(i);
            ps.setLong(1, dropletMedia[0]);
            ps.setLong(2, dropletMedia[1]);
        }

        public int getBatchSize() {
            return dropletMediaList.size();
        }
    });

    if (dropImages.size() > 0) {
        sql = "UPDATE droplets SET droplet_image = ? WHERE id = ?";
        jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
            public void setValues(PreparedStatement ps, int i) throws SQLException {
                long[] update = dropImages.get(i);
                ps.setLong(1, update[1]);
                ps.setLong(2, update[0]);
            }

            public int getBatchSize() {
                return dropImages.size();
            }
        });
    }
}

From source file:info.raack.appliancelabeler.machinelearning.weka.WekaMachineLearningEngine.java

private List<String> extractValuesForAttributeIndex(int index, List<double[]> mlData,
        Map<Integer, List<String>> memoizedValues) {
    if (memoizedValues.containsKey(index)) {
        return memoizedValues.get(index);
    } else {// ww w.j  a  va2  s. c o  m
        // perform memoization
        Set<String> uniqueValues = new HashSet<String>();
        for (double[] datapoint : mlData) {
            uniqueValues.add(datapoint[index] + "");
        }

        // remove missing class
        uniqueValues.remove(Double.valueOf(Utils.missingValue()).toString());

        memoizedValues.put(index, new ArrayList<String>(uniqueValues));
        return memoizedValues.get(index);
    }
}