List of usage examples for java.util Collection removeAll
boolean removeAll(Collection<?> c);
From source file:org.apache.cayenne.dbsync.reverse.dbimport.DefaultDbImportAction.java
/** * Flattens many-to-many relationships in the generated model. *//*from w ww.j a v a 2 s .c o m*/ public static void flattenManyToManyRelationships(DataMap map, Collection<ObjEntity> loadedObjEntities, ObjectNameGenerator objectNameGenerator) { if (loadedObjEntities.isEmpty()) { return; } Collection<ObjEntity> entitiesForDelete = new LinkedList<>(); for (ObjEntity curEntity : loadedObjEntities) { ManyToManyCandidateEntity entity = ManyToManyCandidateEntity.build(curEntity); if (entity != null) { entity.optimizeRelationships(objectNameGenerator); entitiesForDelete.add(curEntity); } } // remove needed entities for (ObjEntity curDeleteEntity : entitiesForDelete) { map.removeObjEntity(curDeleteEntity.getName(), true); } loadedObjEntities.removeAll(entitiesForDelete); }
From source file:controllers.Service.java
public static void getResults(String surveyId, String resultIDs) { String[] resultsIds = resultIDs.split(","); Collection<NdgResult> results = new ArrayList<NdgResult>(); Collection<NdgResult> removalResults = new ArrayList<NdgResult>(); NdgResult result = null;// w w w .j a v a2s. c om if (resultsIds.length > 0) { for (int i = 0; i < resultsIds.length; i++) { result = NdgResult.find("byId", Long.parseLong(resultsIds[i])).first(); if (result != null) { results.add(result); } } } for (NdgResult current : results) { if (current.latitude == null || current.longitude == null) { removalResults.add(current); } } results.removeAll(removalResults); JSONSerializer surveyListSerializer = new JSONSerializer(); surveyListSerializer .include("id", "resultId", "title", "startTime", "endTime", "ndgUser", "latitude", "longitude") .exclude("*").rootName("items"); renderJSON(surveyListSerializer.serialize(results)); }
From source file:de.rallye.model.structures.GameState.java
public void nextRound() { //Did some group forget to register a position Collection<Integer> unregistered = positions.keySet(); unregistered.removeAll(upcomingPositions.keySet()); //Generate new positions for unregistered groups for (Integer group : unregistered) { Node current = positions.get(group); //TODO: Generate random valid new position upcomingPositions.put(group, current); }//from w w w.j av a2s. co m //Switch positions positions = upcomingPositions; upcomingPositions = new HashMap<Integer, Node>(); //TODO: Notify clients }
From source file:controllers.Service.java
public static void selectedToKML(String surveyId, String resultIDs) { Survey survey = Survey.findById(Long.decode(surveyId)); String[] resultsIds = resultIDs.split(","); Collection<NdgResult> results = new ArrayList<NdgResult>(); Collection<NdgResult> removalResults = new ArrayList<NdgResult>(); NdgResult result = null;/* w w w. j a v a 2 s.co m*/ if (resultsIds.length > 0) { for (int i = 0; i < resultsIds.length; i++) { result = NdgResult.find("byId", Long.parseLong(resultsIds[i])).first(); if (result != null) { results.add(result); } } } for (NdgResult current : results) { if (current.latitude == null || current.longitude == null) { removalResults.add(current); } } results.removeAll(removalResults); ByteArrayOutputStream arqExport = new ByteArrayOutputStream(); String fileName = surveyId + ".kml"; try { final Kml kml = new Kml(); final Document document = kml.createAndSetDocument(); for (NdgResult current : results) { // String description = "<![CDATA[ "; String description = ""; int i = 0; List<Question> questions = new ArrayList<Question>(); questions = survey.getQuestions(); if (questions.isEmpty()) { description += "<b> NO QUESTION </b> <br><br>"; } for (Question question : questions) { i++; description += "<h3><b>" + i + " - " + question.label + "</b></h3><br>"; Collection<Answer> answers = CollectionUtils.intersection(question.answerCollection, current.answerCollection); if (answers.isEmpty()) { description += "<br><br>"; } else if (answers.size() == 1) { Answer answer = answers.iterator().next(); if (answer.question.questionType.typeName.equalsIgnoreCase(QuestionTypesConsts.IMAGE)) { /* ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; InputStream in = answer.binaryData.get(); int n = 0; try { while( (n = in.read(buf) ) >= 0) { baos.write(buf, 0, n); } in.close(); } catch(IOException ex) { System.out.println("IO"); } byte[] bytes = baos.toByteArray(); System.out.println("image = " + Base64.encodeBase64String(bytes)); description += "<img src='data:image/jpeg;base64," + Base64.encodeBase64String(bytes) + "'/> <br><br>"; */ description += "<b> #image</b> <br><br>"; } else { description += "<h4 style='color:#3a77ca'><b>" + answer.textData + "</b></h4><br>"; } } } // description += " ]]>"; document.createAndAddPlacemark().withName(current.title).withOpen(Boolean.TRUE) .withDescription(description).createAndSetPoint() .addToCoordinates(current.longitude + ", " + current.latitude); } kml.marshal(arqExport); send(fileName, arqExport.toByteArray()); } catch (FileNotFoundException ex) { } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.JoinNotificationObj.java
@Override public Pair<JSONObject, byte[]> handleUnprocessed(final Context context, JSONObject obj) { if (DBG)/*from w ww . ja v a2 s. c o m*/ Log.i(TAG, "Message to update group. "); String feedName = obj.optString("feedName"); final Uri uri = Uri.parse(obj.optString(JoinNotificationObj.URI)); final GroupProviders.GroupProvider h = GroupProviders.forUri(uri); final DBHelper helper = DBHelper.getGlobal(context); final IdentityProvider ident = new DBIdentityProvider(helper); Maybe<Group> mg = helper.groupByFeedName(feedName); try { // group exists already, load view final Group g = mg.get(); GroupProviders.runBackgroundGroupTask(g.id, new Runnable() { public void run() { Collection<Contact> existingContacts = g.contactCollection(helper); h.handle(g.id, uri, context, g.version, false); Collection<Contact> newContacts = g.contactCollection(helper); newContacts.removeAll(existingContacts); Helpers.resendProfile(context, newContacts, true); } }); } catch (Maybe.NoValError e) { } ident.close(); helper.close(); return null; }
From source file:com.cloudera.oryx.app.als.FeatureVectors.java
/** * Removes all IDs that are mapped to a feature vector from a given collection * * @param allIDs collection to add IDs to *//*from w ww .j a va 2 s . c o m*/ public void removeAllIDsFrom(Collection<String> allIDs) { try (AutoLock al = lock.autoReadLock()) { allIDs.removeAll(vectors.keySet()); } }
From source file:ubc.pavlab.aspiredb.server.biomartquery.BioMartCacheImpl.java
@Override public Collection<GeneValueObject> findGenes(String queryString) { /*// w w w . j a v a 2s . co m * String regexQueryString = "*" + queryString + "*"; * * Criteria nameCriteria = geneNameAttribute.ilike( regexQueryString ); Criteria symbolCriteria = * geneSymbolAttribute.ilike( regexQueryString ); */ // return fetchByCriteria( nameCriteria.or( symbolCriteria ) ); Collection<GeneValueObject> results = new ArrayList<>(); // 1. Exact Gene Symbols String regexQueryString = queryString; Criteria symbolCriteria = geneSymbolAttribute.ilike(regexQueryString); results.addAll(fetchByCriteria(symbolCriteria)); // 2. Prefix Gene Symbols regexQueryString = queryString + "*"; symbolCriteria = geneSymbolAttribute.ilike(regexQueryString); Collection<GeneValueObject> tmp = fetchByCriteria(symbolCriteria); tmp.removeAll(results); results.addAll(tmp); // 3. Prefix Gene name Criteria nameCriteria = geneNameAttribute.ilike(regexQueryString); tmp = fetchByCriteria(nameCriteria); tmp.removeAll(results); results.addAll(tmp); return results; }
From source file:com.qrmedia.commons.persistence.hibernate.clone.HibernateEntityBeanCloner.java
private static Collection<String> calculateTargetedFieldNames(Object entity, boolean preserveIdFields) { Collection<String> targetedFieldNames = new ArrayList<String>(); Class<?> entityClass = entity.getClass(); for (Field field : ClassUtils.getAllDeclaredFields(entityClass)) { String fieldName = field.getName(); // ignore static members and members without a valid getter and setter if (!Modifier.isStatic(field.getModifiers()) && PropertyUtils.isReadable(entity, fieldName) && PropertyUtils.isWriteable(entity, fieldName)) { targetedFieldNames.add(field.getName()); }// www. j a v a 2s . com } /* * Assume that, in accordance with recommendations, entities are using *either* JPA property * *or* field access. Guess the access type from the location of the @Id annotation, as * Hibernate does. */ Set<Method> idAnnotatedMethods = ClassUtils.getAnnotatedMethods(entityClass, Id.class); boolean usingFieldAccess = idAnnotatedMethods.isEmpty(); // ignore fields annotated with @Version and, optionally, @Id targetedFieldNames.removeAll(usingFieldAccess ? getFieldNames(ClassUtils.getAllAnnotatedDeclaredFields(entityClass, Version.class)) : getPropertyNames(ClassUtils.getAnnotatedMethods(entityClass, Version.class))); if (!preserveIdFields) { targetedFieldNames.removeAll(usingFieldAccess ? getFieldNames(ClassUtils.getAllAnnotatedDeclaredFields(entityClass, Id.class)) : getPropertyNames(idAnnotatedMethods)); } return targetedFieldNames; }
From source file:com.tacitknowledge.noexcuses.MethodTester.java
/** * Pruning {@link Object} defined methods from the list of * the provided <code>testClass</code> methods. This way we're * assuring that we end up with the list of methods that are pertinent * to at least one level beyond that of <code>Object</code> class. * /*w w w.j a v a2 s .c o m*/ * @param testClass {@link Class} whose methods to prune * @return collection of {@link Method}s that contain all of the <code>testClass</code> * defined methods with the exclusion of those defined on {@link Object} level. */ private Collection<Method> pruneMethods(Class<?> testClass) { Method[] methods = testClass.getMethods(); Method[] objMethods = Object.class.getMethods(); Collection<Method> results = new ArrayList<Method>(Arrays.asList(methods)); results.removeAll(new ArrayList<Method>(Arrays.asList(objMethods))); return results; }
From source file:com.comcast.video.dawg.controller.house.StbModelController.java
/** * REST api to add a model/*from w w w . j a v a 2 s . c o m*/ * @param newModel The model to add * @return */ @RequestMapping(value = "models/{id}", method = RequestMethod.POST) @ResponseBody public boolean addModel(@RequestBody DawgModel newModel, @PathVariable String id) { DawgModel existing = service.getModelById(id); service.upsertModel(newModel); if (existing != null) { /** Make a diff between the existing model and the new model * and then apply that diff to every stb that is this * model */ List<String> addedCaps = new ArrayList<String>(); List<String> removedCaps = new ArrayList<String>(); List<String> existingCaps = existing.getCapabilities(); List<String> newCaps = newModel.getCapabilities(); for (String cap : newCaps) { if (!existingCaps.contains(cap)) { addedCaps.add(cap); } } for (String cap : existingCaps) { if (!newCaps.contains(cap)) { removedCaps.add(cap); } } Map<String, Object>[] datas = houseService.getStbsByKey(newModel.getName()); for (Map<String, Object> data : datas) { MetaStb stb = new MetaStb(data); if (stb.getModel().name().equals(newModel.getName())) { if (!stb.getData().containsKey(MetaStb.CAPABILITIES)) { stb.setCapabilities(enumerate(newCaps)); } else { Collection<Capability> caps = stb.getCapabilities(); caps.addAll(enumerate(addedCaps)); caps.removeAll(enumerate(removedCaps)); stb.setCapabilities(caps); } stb.setFamily(Family.valueOf(newModel.getFamily())); houseService.upsertStb(stb); } } } else { Map<String, Object>[] datas = houseService.getStbsByKey(newModel.getName()); applyModels(datas, Arrays.asList(newModel)); } return true; }