List of usage examples for java.util Set retainAll
boolean retainAll(Collection<?> c);
From source file:org.eel.kitchen.jsonschema.keyword.KeywordFactory.java
/** * Return the set of validators for a particular schema * * @param schema the schema as a {@link JsonNode} * @return the set of validators//from ww w . ja v a 2 s . c om */ public Set<KeywordValidator> getValidators(final JsonNode schema) { final Set<KeywordValidator> ret = Sets.newHashSet(); final Set<String> set = JacksonUtils.fieldNames(schema); set.retainAll(validators.keySet()); KeywordValidator validator; for (final String keyword : set) { validator = buildValidator(validators.get(keyword), schema); if (!validator.alwaysTrue()) ret.add(validator); } return ImmutableSet.copyOf(ret); }
From source file:dkpro.similarity.algorithms.structure.StopwordNGramContainmentMeasure.java
@Override public double getSimilarity(Collection<String> stringList1, Collection<String> stringList2) throws SimilarityException { // Get n-grams (retain stopwords only) Set<List<String>> ngrams1 = getNGrams(retainStopwords(stringList1)); Set<List<String>> ngrams2 = getNGrams(retainStopwords(stringList2)); // Compare using the containment measure (Broder, 1997) Set<List<String>> commonNGrams = new HashSet<List<String>>(); commonNGrams.addAll(ngrams1);// w w w . jav a 2 s . co m commonNGrams.retainAll(ngrams2); double norm = Math.max(ngrams1.size(), ngrams2.size()); double sim = 0.0; if (norm > 0.0) sim = commonNGrams.size() / norm; return sim; }
From source file:uk.ac.ebi.atlas.experimentpage.baseline.FilterFactorMenuBuilder.java
protected Set<Factor> filterRemainingFactors(Factor factor, Set<Factor> allFactors) { SortedSet<Factor> coOccurringFactors = experimentalFactors.getCoOccurringFactors(factor); Set<Factor> remaining = Sets.newHashSet(coOccurringFactors); remaining.retainAll(allFactors); return remaining; }
From source file:org.apache.bigtop.datagenerators.locations.LocationReader.java
public ImmutableList<Location> readData() throws FileNotFoundException { ImmutableMap<String, Double> incomes = readIncomeData(getResource(LocationConstants.INCOMES_FILE)); ImmutableMap<String, Long> populations = readPopulationData(getResource(LocationConstants.POPULATION_FILE)); ImmutableMap<String, ZipcodeLocationRecord> coordinates = readCoordinates( getResource(LocationConstants.COORDINATES_FILE)); Set<String> zipcodeSubset = new HashSet<String>(incomes.keySet()); zipcodeSubset.retainAll(populations.keySet()); zipcodeSubset.retainAll(coordinates.keySet()); List<Location> table = new Vector<Location>(); for (String zipcode : zipcodeSubset) { Location record = new Location(zipcode, coordinates.get(zipcode).coordinates, coordinates.get(zipcode).city, coordinates.get(zipcode).state, incomes.get(zipcode), populations.get(zipcode)); table.add(record);//from www . j av a 2 s.c o m } return ImmutableList.copyOf(table); }
From source file:org.dkpro.similarity.algorithms.structure.PosNGramJaccardMeasure.java
protected double getNormalizedSimilarity(Set<List<String>> suspiciousNGrams, Set<List<String>> originalNGrams) { // Compare using the Jaccard similarity coefficient (Manning & Schtze, 1999) Set<List<String>> commonNGrams = new HashSet<List<String>>(); commonNGrams.addAll(suspiciousNGrams); commonNGrams.retainAll(originalNGrams); Set<List<String>> unionNGrams = new HashSet<List<String>>(); unionNGrams.addAll(suspiciousNGrams); unionNGrams.addAll(originalNGrams);// w ww .ja v a 2 s . co m double norm = unionNGrams.size(); double sim = 0.0; if (norm > 0.0) { sim = commonNGrams.size() / norm; } return sim; }
From source file:org.n52.web.ctrl.ParameterController.java
private Collection<String> checkForOverridingData(Map<String, Object> data, Map<String, Object> dataToAdd) { Map<String, Object> currentData = new HashMap<>(data); Set<String> overridableKeys = currentData.keySet(); overridableKeys.retainAll(dataToAdd.keySet()); return overridableKeys; }
From source file:org.apache.bigtop.bigpetstore.datagenerator.generators.locations.ZipcodeReader.java
public ImmutableList<Location> readData() throws FileNotFoundException { ImmutableMap<String, Double> incomes = readIncomeData(this.zipcodeIncomesFile); ImmutableMap<String, Long> populations = readPopulationData(this.zipcodePopulationFile); ImmutableMap<String, ZipcodeLocationRecord> coordinates = readCoordinates(this.zipcodeCoordinatesFile); Set<String> zipcodeSubset = new HashSet<String>(incomes.keySet()); zipcodeSubset.retainAll(populations.keySet()); zipcodeSubset.retainAll(coordinates.keySet()); List<Location> table = new Vector<Location>(); for (String zipcode : zipcodeSubset) { Location record = new Location(zipcode, coordinates.get(zipcode).coordinates, coordinates.get(zipcode).city, coordinates.get(zipcode).state, incomes.get(zipcode), populations.get(zipcode)); table.add(record);//from w w w. java2 s . c o m } return ImmutableList.copyOf(table); }
From source file:org.apache.bigtop.bigpetstore.datagenerator.datareaders.ZipcodeReader.java
public ImmutableList<ZipcodeRecord> readData() throws FileNotFoundException { ImmutableMap<String, Double> incomes = readIncomeData(this.zipcodeIncomesFile); ImmutableMap<String, Long> populations = readPopulationData(this.zipcodePopulationFile); ImmutableMap<String, ZipcodeLocationRecord> coordinates = readCoordinates(this.zipcodeCoordinatesFile); Set<String> zipcodeSubset = new HashSet<String>(incomes.keySet()); zipcodeSubset.retainAll(populations.keySet()); zipcodeSubset.retainAll(coordinates.keySet()); List<ZipcodeRecord> table = new Vector<ZipcodeRecord>(); for (String zipcode : zipcodeSubset) { ZipcodeRecord record = new ZipcodeRecord(zipcode, coordinates.get(zipcode).coordinates, coordinates.get(zipcode).city, coordinates.get(zipcode).state, incomes.get(zipcode), populations.get(zipcode)); table.add(record);/*from w w w .ja va 2 s . c om*/ } return ImmutableList.copyOf(table); }
From source file:no.back.springextensions.RelaxedPlaceHolderConfigurer.java
@SuppressWarnings("unchecked") @Override/*from w ww . j a va2s . c om*/ protected void loadProperties(Properties props) throws IOException { verifyEnvironment(); logger.info("CouchDB loadProperties() with active environment: " + environment); Database db = dbFactory.hostname(hostname).port(port).database(database).username(username) .password(password).initialize(); // Currently we simply emit all documents from properties database with a custom view. // TODO add option for specifying design views ViewResult<Map> result = db.queryAdHocView(Map.class, "{ \"map\" : \"function(doc) { emit(doc._id, doc);} \"}", null, new JSONParser()); if (result != null) { logger.info("Amount of properties collected from CouchDB: " + result.getTotalRows()); for (ValueRow<Map> row : result.getRows()) { Set<String> keys = row.getValue().keySet(); keys.retainAll(Arrays.asList(new String[] { environment })); // skipping // return // value for (String key : keys) { String value = (String) row.getValue().get(key); props.put(row.getId(), value); } } } }
From source file:org.metaborg.intellij.idea.languages.DefaultLanguageProjectService.java
/** * {@inheritDoc}/* ww w . j a va 2 s . co m*/ */ @Override public Set<LanguageDialect> getCandidateImpls(@Nullable final Iterable<? extends ILanguageImpl> languages, @Nullable final IProject project, @Nullable final FileObject file) { if (languages == null) return getCandidateImpls(this.languageService.getAllImpls(), project, file); final Set<LanguageDialect> candidates = new HashSet<>(); if (file != null) { // Find all implementations that the file identifies to. for (final ILanguageImpl impl : languages) { if (this.identifierService.identify(file, impl)) { candidates.add(new LanguageDialect(impl, null)); } } } else if (project != null) { // Find all implementations that the project supports. final Set<ILanguageImpl> input = Sets.newHashSet(activeImpls(project)); input.retainAll(Lists.newArrayList(languages)); for (final ILanguageImpl impl : input) { candidates.add(new LanguageDialect(impl, null)); } } else { // Find all implementations. for (final ILanguageImpl impl : languages) { candidates.add(new LanguageDialect(impl, null)); } } return candidates; }