List of usage examples for com.google.common.collect Maps filterKeys
@CheckReturnValue public static <K, V> BiMap<K, V> filterKeys(BiMap<K, V> unfiltered, final Predicate<? super K> keyPredicate)
From source file:org.apache.cassandra.thrift.CassandraServer.java
private void validateSchemaAgreement() throws SchemaDisagreementException { // unreachable hosts don't count towards disagreement Map<String, List<String>> versions = Maps.filterKeys(StorageProxy.describeSchemaVersions(), Predicates.not(Predicates.equalTo(StorageProxy.UNREACHABLE))); if (versions.size() > 1) throw new SchemaDisagreementException(); }
From source file:com.google.enterprise.connector.instantiator.ConnectorCoordinatorImpl.java
/** * Removes non-persistable "google" properties from the Configuration. *///from w w w. java 2s.c o m private Configuration removeGoogleProperties(Configuration config) { // Make a copy of the map with google* entries removed. Map<String, String> newConfig = Maps.newHashMap(Maps.filterKeys(config.getMap(), new Predicate<String>() { public boolean apply(String input) { return !PropertiesUtils.GOOGLE_NONPERSISTABLE_PROPERTIES.contains(input); } })); return new Configuration(newConfig, config); }
From source file:gr.forth.ics.swkm.model2.importer.AbstractStore.java
private void updateExistingLabels(ImportContext context) throws SQLException { UpdatedLabels updatedLabels = context.updatedLabels; Map<Interval, Interval> oldIntervalToNew = Maps.newHashMap(); Map<Interval, RdfType> oldIntervalToType = Maps.newHashMap(); final SetMultimap<RdfType, Interval> typeToOldInterval = HashMultimap.create(); //Two cases:/* w w w. j a v a 2s. c om*/ //1) Nodes for which we have their URI. for (Uri oldResource : updatedLabels.getOldLabels().getResourcesWithPredefinedLabels()) { RdfType type = context.model.mapResource(oldResource).type(); Label oldLabel = updatedLabels.getOldLabels().predefinedLabelOf(oldResource); //Do we have a new label for this URI? Label newLabel = updatedLabels.getNewLabels(type).get(oldResource); if (newLabel != null) { oldIntervalToNew.put(oldLabel.getTreeLabel(), newLabel.getTreeLabel()); oldIntervalToType.put(oldLabel.getTreeLabel(), type); typeToOldInterval.put(type, oldLabel.getTreeLabel()); } } //2) Nodes for which we only know their old tree interval: all of them need to be updated for (RdfType type : EnumSet.of(RdfType.CLASS, RdfType.METACLASS, RdfType.PROPERTY, RdfType.METAPROPERTY)) { Map<Interval, Label> map = updatedLabels.getUpdatedLabelsByInterval(type); for (Entry<Interval, Label> entry : map.entrySet()) { Interval oldLabel = entry.getKey(); Label newLabel = entry.getValue(); oldIntervalToNew.put(oldLabel, newLabel.getTreeLabel()); oldIntervalToType.put(oldLabel, type); typeToOldInterval.put(type, oldLabel); } } for (final RdfType type : EnumSet.of(RdfType.CLASS, RdfType.METACLASS, RdfType.PROPERTY, RdfType.METAPROPERTY)) { Predicate<Interval> predicate = new Predicate<Interval>() { public boolean apply(Interval interval) { return typeToOldInterval.get(type).contains(interval); } }; Map<Interval, Interval> filtered = Maps.filterKeys(oldIntervalToNew, predicate); if (!filtered.isEmpty()) { updateResourceLabels(filtered, type); } } }
From source file:com.opengamma.engine.view.worker.SingleThreadViewProcessWorker.java
private CompiledViewDefinitionWithGraphs initialiseMarketDataManipulation( CompiledViewDefinitionWithGraphs compiledViewDefinition, ComputationTargetResolver.AtVersionCorrection resolver) { if (_marketDataSelectionGraphManipulator.hasManipulationsDefined()) { s_logger.info("Initialising market data manipulation"); Map<DependencyGraph, Map<DistinctMarketDataSelector, Set<ValueSpecification>>> selectionsByGraph = new HashMap<>(); Map<DependencyGraph, Map<DistinctMarketDataSelector, FunctionParameters>> functionParamsByGraph = new HashMap<>(); for (DependencyGraphExplorer graphExplorer : compiledViewDefinition.getDependencyGraphExplorers()) { DependencyGraph graph = graphExplorer.getWholeGraph(); final Map<DistinctMarketDataSelector, Set<ValueSpecification>> selectorMapping = _marketDataSelectionGraphManipulator .modifyDependencyGraph(graph, resolver); if (!selectorMapping.isEmpty()) { selectionsByGraph.put(graph, selectorMapping); Map<DistinctMarketDataSelector, FunctionParameters> params = _specificMarketDataSelectors .get(graph.getCalculationConfigurationName()); // _specificMarketDataSelectors has an entry for each graph, so no null check required if (!params.isEmpty()) { // Filter the function params so that we only have entries for active selectors Map<DistinctMarketDataSelector, FunctionParameters> filteredParams = Maps.filterKeys(params, new Predicate<DistinctMarketDataSelector>() { @Override public boolean apply(DistinctMarketDataSelector selector) { return selectorMapping.containsKey(selector); }/* www. ja v a2 s. c om*/ }); functionParamsByGraph.put(graph, filteredParams); } } } if (!selectionsByGraph.isEmpty()) { s_logger.info( "Adding in market data manipulation selections: [{}] and preset function parameters: [{}]", selectionsByGraph, functionParamsByGraph); return compiledViewDefinition.withMarketDataManipulationSelections(selectionsByGraph, functionParamsByGraph); } else { s_logger.info("No market data manipulation selectors matched - no manipulation to be done"); } } return compiledViewDefinition; }