List of usage examples for java.util Collection removeAll
boolean removeAll(Collection<?> c);
From source file:net.imagini.cassandra.DumpSSTables.SSTableExport.java
/** * Export specific rows from an SSTable and write the resulting JSON to a * PrintStream.//from www . ja v a 2s . c om * * @param desc * the descriptor of the sstable table to read from * @param outs * PrintStream to write the output to * @param toExport * the keys corresponding to the rows to export * @param excludes * keys to exclude from export * @throws IOException * on failure to read/write input/output */ public static void export(Descriptor desc, PrintStream outs, Collection<String> toExport, String[] excludes) throws IOException { SSTableReader reader = SSTableReader.open(desc); SSTableScanner scanner = reader.getDirectScanner(); IPartitioner<?> partitioner = reader.partitioner; if (excludes != null) toExport.removeAll(Arrays.asList(excludes)); int i = 0; // last key to compare order DecoratedKey lastKey = null; for (String key : toExport) { DecoratedKey decoratedKey = partitioner.decorateKey(ByteBufferUtil.hexToBytes(key)); if (lastKey != null && lastKey.compareTo(decoratedKey) > 0) throw new IOException("Key out of order! " + lastKey + " > " + decoratedKey); lastKey = decoratedKey; scanner.seekTo(decoratedKey); if (!scanner.hasNext()) continue; SSTableIdentityIterator row = (SSTableIdentityIterator) scanner.next(); if (!row.getKey().equals(decoratedKey)) continue; serializeRow(row, decoratedKey, outs); if (i != 0) outs.println(","); i++; } outs.println("\n"); outs.flush(); scanner.close(); }
From source file:controllers.Service.java
public static void getAllResults(String surveyId) { Survey survey = Survey.findById(Long.decode(surveyId)); Collection<NdgResult> results = new ArrayList<NdgResult>(); Collection<NdgResult> removalResults = new ArrayList<NdgResult>(); results = survey.resultCollection;//from w ww . j a v a 2 s .c o m 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:isl.FIMS.utils.Utils.java
public static Collection Subtract(Collection coll1, Collection coll2) { Collection result = new ArrayList(coll2); result.removeAll(coll1); return result; }
From source file:org.apache.cassandra.db.SystemKeyspace.java
/** * Convenience method to update the list of tokens in the local system keyspace. * * @param addTokens tokens to add/*w w w .j a v a 2 s. c om*/ * @param rmTokens tokens to remove * @return the collection of persisted tokens */ public static synchronized Collection<Token> updateLocalTokens(Collection<Token> addTokens, Collection<Token> rmTokens) { Collection<Token> tokens = getSavedTokens(); tokens.removeAll(rmTokens); tokens.addAll(addTokens); updateTokens(tokens); return tokens; }
From source file:controllers.Service.java
public static void allToKML(String surveyId) { Survey survey = Survey.findById(Long.decode(surveyId)); Collection<NdgResult> results = new ArrayList<NdgResult>(); Collection<NdgResult> removalResults = new ArrayList<NdgResult>(); results = survey.resultCollection;//from w w w .j a v a 2 s .c o m 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(); //TODO Include image, right byte[] buf = new byte[1024]; //now it adds base64 to the img InputStream in = answer.binaryData.get(); //tag but it doesn't show on int n = 0; //the map 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:de.tbuchloh.kiskis.persistence.PersistenceManager.java
/** * @return all files without a representing attachment object. *//* w ww .ja v a 2 s . com*/ private static Collection<File> getOrphanedAttachmentFiles(TPMDocument doc) { final Set<File> knownFiles = new HashSet<File>(); for (final Attachment a : doc.getAttachments()) { final File attFile = createAttachmentFile(a); knownFiles.add(attFile.getAbsoluteFile()); } final Collection<File> listFiles = new HashSet<File>(); for (final File f : listAttachments(doc)) { listFiles.add(f.getAbsoluteFile()); } listFiles.removeAll(knownFiles); return listFiles; }
From source file:org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils.java
/** * Gets the sub object class descriptions of the given object class description. * /* w w w . j ava 2 s . com*/ * @param ocd the object class description * @param schema the schema * * @return the sub object class descriptions */ public static List<ObjectClass> getSubObjectClassDescriptions(ObjectClass ocd, Schema schema) { List<ObjectClass> subOcds = new ArrayList<ObjectClass>(); for (ObjectClass testOcd : schema.getObjectClassDescriptions()) { Collection<String> superiorNames = toLowerCaseSet(testOcd.getSuperiorOids()); if (superiorNames.removeAll(getLowerCaseIdentifiers(ocd))) { subOcds.add(testOcd); } } return subOcds; }
From source file:org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils.java
/** * Gets all matching rule description names the given attribute type * description applies to according to the schema's matchin rul use * descritpions.//from w w w . java 2 s .com * * @param atd the attribute type description * @param schema the schema * * @return all matching rule description names this attribute type * description applies to according to the schema's matching * rule use descriptions */ public static Collection<String> getOtherMatchingRuleDescriptionNames(AttributeType atd, Schema schema) { Set<String> otherMatchingRules = new TreeSet<String>(nameAndOidComparator); for (MatchingRuleUse mrud : schema.getMatchingRuleUseDescriptions()) { Collection<String> atdSet = toLowerCaseSet(mrud.getApplicableAttributeOids()); if (atdSet.removeAll(getLowerCaseIdentifiers(atd))) { otherMatchingRules.addAll(mrud.getNames()); } } return otherMatchingRules; }
From source file:org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils.java
/** * Gets all object class description using the given attribute type * description as may attribute./*from w w w . j ava2 s . c o m*/ * * @param atd the attribute type description * @param schema the schema * * @return all object class description using the given attribute type * description as may attribute */ public static Collection<ObjectClass> getUsedAsMay(AttributeType atd, Schema schema) { Collection<String> lowerCaseIdentifiers = getLowerCaseIdentifiers(atd); Set<ObjectClass> ocds = new TreeSet<ObjectClass>(schemaElementNameComparator); for (ObjectClass ocd : schema.getObjectClassDescriptions()) { Collection<String> mustSet = toLowerCaseSet(getMayAttributeTypeDescriptionNamesTransitive(ocd, schema)); if (mustSet.removeAll(lowerCaseIdentifiers)) { ocds.add(ocd); } } return ocds; }
From source file:org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils.java
/** * Gets all object class description using the given attribute type * description as must attribute.//from w ww.j av a 2 s. c o m * * @param atd the attribute type description * @param schema the schema * * @return all object class description using the given attribute type * description as must attribute */ public static Collection<ObjectClass> getUsedAsMust(AttributeType atd, Schema schema) { Collection<String> lowerCaseIdentifiers = getLowerCaseIdentifiers(atd); Set<ObjectClass> ocds = new TreeSet<ObjectClass>(schemaElementNameComparator); for (ObjectClass ocd : schema.getObjectClassDescriptions()) { Collection<String> mustSet = toLowerCaseSet( getMustAttributeTypeDescriptionNamesTransitive(ocd, schema)); if (mustSet.removeAll(lowerCaseIdentifiers)) { ocds.add(ocd); } } return ocds; }