List of usage examples for java.util Set remove
boolean remove(Object o);
From source file:com.imaginea.mongodb.controllers.DocumentController.java
/** * Maps POST Request to perform operations like update/delete/insert * document inside a collection inside a database present in mongo db to a * service function that returns the list. Also forms the JSON response for * this request and sent it to client. In case of any exception from the * service files an error object if formed. * * @param dbName Name of Database * @param collectionName Name of Collection * @param documentData Contains the document to be inserted * @param _id Object id of document to delete or update * @param keys new Document values in case of update * @param action Query Parameter with value PUT for identifying a create * database request and value DELETE for dropping a database. * @param connectionId Mongo Db Configuration provided by user to connect to. * @param request Get the HTTP request context to extract session parameters * @return String with Status of operation performed. */// ww w. ja va 2 s . c o m @POST @Produces(MediaType.APPLICATION_JSON) public String postDocsRequest(@PathParam("dbName") final String dbName, @PathParam("collectionName") final String collectionName, @DefaultValue("POST") @QueryParam("action") final String action, @FormParam("document") final String documentData, @FormParam("_id") final String _id, @FormParam("keys") final String keys, @QueryParam("connectionId") final String connectionId, @Context final HttpServletRequest request) { String response = new ResponseTemplate().execute(logger, connectionId, request, new ResponseCallback() { public Object execute() throws Exception { DocumentService documentService = new DocumentServiceImpl(connectionId); JSONObject resultJSON = new JSONObject(); String result = null; RequestMethod method = null; for (RequestMethod m : RequestMethod.values()) { if ((m.toString()).equals(action)) { method = m; break; } } switch (method) { case PUT: { if ("".equals(documentData)) { ApplicationException e = new DocumentException(ErrorCodes.DOCUMENT_DOES_NOT_EXIST, "Document Data Missing in Request Body"); result = formErrorResponse(logger, e); } else { DBObject document = (DBObject) JSON.parse(documentData); result = documentService.insertDocument(dbName, collectionName, document); } break; } case DELETE: { if ("".equals(_id)) { ApplicationException e = new DocumentException(ErrorCodes.DOCUMENT_DOES_NOT_EXIST, "Document Data Missing in Request Body"); result = formErrorResponse(logger, e); } else { result = documentService.deleteDocument(dbName, collectionName, _id); } break; } case POST: { if ("".equals(_id) || "".equals(keys)) { ApplicationException e = new DocumentException(ErrorCodes.DOCUMENT_DOES_NOT_EXIST, "Document Data Missing in Request Body"); formErrorResponse(logger, e); } else { // New Document Keys DBObject newDoc = (DBObject) JSON.parse(keys); result = documentService.updateDocument(dbName, collectionName, _id, newDoc); Set<String> completeSet = new HashSet<String>(); getNestedKeys(newDoc, completeSet, ""); completeSet.remove("_id"); resultJSON.put("keys", completeSet); } break; } default: { result = "Action parameter value is wrong"; break; } } resultJSON.put("result", result); return resultJSON; } }); return response; }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaTagDao.java
/** * Populate the droplet tags table./*from w w w. j ava 2 s . c o m*/ * * @param drops */ private void insertDropletTags(List<Drop> drops) { // List of drop IDs in the drops list List<Long> dropIds = new ArrayList<Long>(); // List of tags in a drop Map<Long, Set<Long>> dropletTagsMap = new HashMap<Long, Set<Long>>(); for (Drop drop : drops) { if (drop.getTags() == null) continue; dropIds.add(drop.getId()); for (Tag tag : drop.getTags()) { Set<Long> tags = null; if (dropletTagsMap.containsKey(drop.getId())) { tags = dropletTagsMap.get(drop.getId()); } else { tags = new HashSet<Long>(); dropletTagsMap.put(drop.getId(), tags); } tags.add(tag.getId()); } } // Find droplet tags that already exist in the db String sql = "SELECT droplet_id, tag_id FROM droplets_tags 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_tags from our Set for (Map<String, Object> result : results) { long dropletId = ((Number) result.get("droplet_id")).longValue(); long tagId = ((Number) result.get("tag_id")).longValue(); Set<Long> tagSet = dropletTagsMap.get(dropletId); if (tagSet != null) { tagSet.remove(tagId); } } // Insert the remaining items in the set into the db sql = "INSERT INTO droplets_tags (droplet_id, tag_id) VALUES (?,?)"; final List<long[]> dropletTagsList = new ArrayList<long[]>(); for (Long dropletId : dropletTagsMap.keySet()) { for (Long tagId : dropletTagsMap.get(dropletId)) { long[] dropletTag = { dropletId, tagId }; dropletTagsList.add(dropletTag); } } jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { long[] dropletTag = dropletTagsList.get(i); ps.setLong(1, dropletTag[0]); ps.setLong(2, dropletTag[1]); } public int getBatchSize() { return dropletTagsList.size(); } }); }
From source file:com.jaspersoft.jasperserver.api.metadata.user.service.impl.UserManagerServiceImpl.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = false) public void updateUser(ExecutionContext context, String userName, User userDetails, Set<Role> assignedRoleSet, Set<Role> unassignedRoleSet) { User oldUser = this.userService.getUser(null, userName); String newPassword = userDetails.getPassword(); String oldPassword = oldUser.getPassword(); if (newPassword == null) { userDetails.setPassword(oldPassword); } else if (!newPassword.equals(oldPassword)) { userDetails.setPreviousPasswordChangeTime(new Date()); }/*from ww w .j a va 2 s. c o m*/ Set roles = oldUser.getRoles(); FilterCriteria filter = FilterCriteria.createFilter(Role.class); List<Role> allRoles = userService.getRoles(null, filter); if (allRoles != null) { for (Role assignedRole : unassignedRoleSet) { roles.remove(getRole(assignedRole, allRoles)); } for (Role assignedRole : assignedRoleSet) { roles.add(getRole(assignedRole, allRoles)); } } userDetails.setRoles(roles); userService.updateUser(null, userName, userDetails); }
From source file:com.netflix.genie.core.jpa.services.JpaApplicationServiceImpl.java
/** * {@inheritDoc}//from ww w .j a v a2s . c o m */ @Override public void removeTagForApplication( @NotBlank(message = "No application id entered. Unable to remove tag.") final String id, @NotBlank(message = "No tag entered. Unable to remove.") final String tag) throws GenieException { final ApplicationEntity app = this.findApplication(id); final Set<String> tags = app.getTags(); tags.remove(tag); app.setTags(tags); }
From source file:io.cloudslang.lang.compiler.modeller.transformers.Java_ActionTransformer.java
@Override public Map<String, String> transform(Map<String, String> rawData) { Set<String> expectedKeySet = new HashSet<>( Arrays.asList(ScoreLangConstants.ACTION_CLASS_KEY, ScoreLangConstants.ACTION_METHOD_KEY)); if (rawData != null) { // validation case: there is at least one key under java_action property Set<String> actualKeySet = rawData.keySet(); for (String key : actualKeySet) { if (!expectedKeySet.remove(key)) { throw new RuntimeException("Invalid key for java action: " + key); }//w w w . j av a2s . c om } if (!expectedKeySet.isEmpty()) { throw new RuntimeException( "The following keys for java action are missing: " + StringUtils.join(expectedKeySet, ",")); } } return rawData; }
From source file:com.opengamma.id.ExternalIdBundleWithDates.java
/** * Returns a new bundle with the specified identifier removed. * This instance is immutable and unaffected by this method call. * /*ww w . jav a 2 s .co m*/ * @param externalId the identifier to remove from the returned bundle, not null * @return the new bundle, not null */ public ExternalIdBundleWithDates withoutExternalId(ExternalIdWithDates externalId) { ArgumentChecker.notNull(externalId, "externalId"); Set<ExternalIdWithDates> ids = new HashSet<ExternalIdWithDates>(_externalIds); if (ids.remove(externalId) == false) { return this; } return create(ids); }
From source file:Main.java
static <E> Set<E> ungrowableSet(final Set<E> s) { return new Set<E>() { @Override/*from ww w . j a v a 2s . c o m*/ public int size() { return s.size(); } @Override public boolean isEmpty() { return s.isEmpty(); } @Override public boolean contains(Object o) { return s.contains(o); } @Override public Object[] toArray() { return s.toArray(); } @Override public <T> T[] toArray(T[] a) { return s.toArray(a); } @Override public String toString() { return s.toString(); } @Override public Iterator<E> iterator() { return s.iterator(); } @Override public boolean equals(Object o) { return s.equals(o); } @Override public int hashCode() { return s.hashCode(); } @Override public void clear() { s.clear(); } @Override public boolean remove(Object o) { return s.remove(o); } @Override public boolean containsAll(Collection<?> coll) { return s.containsAll(coll); } @Override public boolean removeAll(Collection<?> coll) { return s.removeAll(coll); } @Override public boolean retainAll(Collection<?> coll) { return s.retainAll(coll); } @Override public boolean add(E o) { throw new UnsupportedOperationException(); } @Override public boolean addAll(Collection<? extends E> coll) { throw new UnsupportedOperationException(); } }; }
From source file:it.unibo.alchemist.language.protelis.datatype.ArrayTupleImpl.java
@Override public Tuple subtract(final Tuple t) { final Set<Object> l = new HashSet<>(Arrays.asList(a)); for (final Object o : t) { l.remove(o); }//from w w w . j av a 2 s .c om return Tuples.create(l.toArray()); }
From source file:com.cimpoint.mes.server.repositories.StepRepository.java
@Transactional public void remove(Long id, TrxInfo trxInfo) { EStep e = entityManager.find(entityClass, id); //detach work centers from step so they don't get removed when the step is removed Set<EWorkCenter> wcs = e.getWorkCenters(); if (wcs != null) { for (EWorkCenter wc : wcs) { wc.removeStep(e);/*from w w w . j a v a2 s. c o m*/ } } e.setWorkCenters(null); //detach transitions from step so they don't get removed when the step is removed // Set<ETransition> incomingTransitions = e.getIncomingTransitions(); // Set<ETransition> outgoingTransitions = e.getOutgoingTransitions(); // if (incomingTransitions != null) { // for (ETransition t : incomingTransitions) { // t.setToStep(null); // t.setFromStep(null); // } // } // // if (outgoingTransitions != null) { // for (ETransition t : outgoingTransitions) { // t.setToStep(null); // t.setFromStep(null); // } // } // e.setIncomingTransitions(null); // e.setOutgoingTransitions(null); // detach operation EOperation operation = e.getOperation(); Set<EStep> steps = operation.getSteps(); if (steps != null && !steps.isEmpty()) { steps.remove(e); } e.setOperation(null); super.remove(e, trxInfo); }
From source file:net.riezebos.thoth.content.comments.dao.CommentDao.java
@Override public List<Comment> getOrphanedComments(String contextName, List<String> allPaths) throws ContentManagerException { Set<String> invalidPaths = getReferencedPaths(contextName); // Make sure we compare apples with apples (we use paths without a '/' prefix in the comment manager) for (String path : allPaths) invalidPaths.remove(ThothUtil.stripPrefix(path, "/")); try (Connection connection = thothDB.getConnection(); // SqlStatement commentStmt = constructCommentQuery(connection, contextName, null, null)) { List<Comment> result = new ArrayList<>(); try (ResultSet rs = commentStmt.executeQuery()) { while (rs.next()) { String path = rs.getString(PATH_COLUMN_INDEX); if (invalidPaths.contains(path)) { result.add(setComment(rs)); }//from w w w .j a v a2s. com } } return result; } catch (SQLException e) { throw new ContentManagerException(e); } }