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.accumulo.core.util.shell.commands.TablesCommand.java
@SuppressWarnings("unchecked") @Override/*from w w w . j av a 2s . co m*/ public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException, NamespaceNotFoundException { final String namespace = cl.hasOption(OptUtil.namespaceOpt().getOpt()) ? OptUtil.getNamespaceOpt(cl, shellState) : null; Map<String, String> tables = shellState.getConnector().tableOperations().tableIdMap(); // filter only specified namespace tables = Maps.filterKeys(tables, new Predicate<String>() { @Override public boolean apply(String tableName) { return namespace == null || Tables.qualify(tableName).getFirst().equals(namespace); } }); final boolean sortByTableId = cl.hasOption(sortByTableIdOption.getOpt()); tables = new TreeMap<String, String>((sortByTableId ? MapUtils.invertMap(tables) : tables)); Iterator<String> it = Iterators.transform(tables.entrySet().iterator(), new Function<Entry<String, String>, String>() { @Override public String apply(Map.Entry<String, String> entry) { String tableName = String.valueOf(sortByTableId ? entry.getValue() : entry.getKey()); String tableId = String.valueOf(sortByTableId ? entry.getKey() : entry.getValue()); if (namespace != null) tableName = Tables.qualify(tableName).getSecond(); if (cl.hasOption(tableIdOption.getOpt())) return String.format(NAME_AND_ID_FORMAT, tableName, tableId); else return tableName; }; }); shellState.printLines(it, !cl.hasOption(disablePaginationOpt.getOpt())); return 0; }
From source file:com.mgmtp.jfunk.data.source.BaseDataSource.java
protected Set<String> getFormDataKeys() { try {//from w w w . j a v a 2 s .c o m Map<String, String> view = Maps.filterKeys(configuration, Predicates.startsWith(JFunkConstants.FORM_DATA_PREFIX)); formDataKeys = Sets.newHashSetWithExpectedSize(view.size()); for (String key : view.keySet()) { String fixedPropsFilenameKey = key; int i = fixedPropsFilenameKey.lastIndexOf('.'); String dataKey = fixedPropsFilenameKey.substring(9, i); formDataKeys.add(dataKey); // Load fixed properties String fixedPropsFilename = configuration.get(fixedPropsFilenameKey); if (StringUtils.isNotEmpty(fixedPropsFilename)) { InputStream is = null; try { ExtendedProperties fixedProps = new ExtendedProperties(); is = configuration.openStream(fixedPropsFilename); fixedProps.load(is); for (Entry<String, String> entry : fixedProps.entrySet()) { setFixedValue(dataKey, entry.getKey(), entry.getValue()); } } finally { IOUtils.closeQuietly(is); } } } } catch (IOException ex) { throw new JFunkException("Error loading form data keys.", ex); } return formDataKeys; }
From source file:org.n52.iceland.util.activation.Activatables.java
public static <K, T> Map<K, T> activatedMap(Map<K, T> map, ActivationProvider<? super K> provider) { return Maps.filterKeys(map, asPredicate(provider)); }
From source file:org.codice.ddf.parser.xml.XmlParserConfigurator.java
@Override public ParserConfigurator addProperties(Map<String, Object> properties) { this.properties.putAll(Maps.filterKeys(properties, Predicates.notNull())); return this; }
From source file:ai.grakn.graql.internal.query.match.MatchQueryInfer.java
@Override public Stream<Map<VarName, Concept>> stream(Optional<GraknGraph> optionalGraph) { GraknGraph graph = optionalOr(optionalGraph, inner.getGraph()) .orElseThrow(() -> new IllegalStateException(ErrorMessage.NO_GRAPH.getMessage())); if (!Reasoner.hasRules(graph)) return inner.stream(optionalGraph); Iterator<Conjunction<VarAdmin>> conjIt = getPattern().getDisjunctiveNormalForm().getPatterns().iterator(); ReasonerQuery conjunctiveQuery = new ReasonerQueryImpl(conjIt.next(), graph); Stream<Map<VarName, Concept>> answerStream = conjunctiveQuery.resolve(materialise); while (conjIt.hasNext()) { conjunctiveQuery = new ReasonerQueryImpl(conjIt.next(), graph); Stream<Map<VarName, Concept>> localStream = conjunctiveQuery.resolve(materialise); answerStream = Stream.concat(answerStream, localStream); }/*from w ww . j a va 2 s .c o m*/ return answerStream.map(result -> Maps.filterKeys(result, getSelectedNames()::contains)); }
From source file:io.druid.server.lookup.cache.polling.OffHeapPollingCache.java
public OffHeapPollingCache(final Iterable<Map.Entry<K, V>> entries) { synchronized (started) { this.cacheName = String.format("cache-%s", UUID.randomUUID()); this.reverseCacheName = String.format("reverseCache-%s", UUID.randomUUID()); mapCache = DB.createHashMap(cacheName).make(); reverseCache = DB.createHashMap(reverseCacheName).make(); ImmutableSet.Builder<V> setOfValuesBuilder = ImmutableSet.builder(); for (Map.Entry<K, V> entry : entries) { mapCache.put(entry.getKey(), entry.getValue()); setOfValuesBuilder.add(entry.getValue()); }/*from w w w. ja va 2 s. c o m*/ final Set<V> setOfValues = setOfValuesBuilder.build(); reverseCache.putAll(Maps.asMap(setOfValues, new Function<V, List<K>>() { @Override public List<K> apply(final V input) { return Lists.newArrayList(Maps.filterKeys(mapCache, new Predicate<K>() { @Override public boolean apply(K key) { V retVal = mapCache.get(key); if (retVal == null) { return false; } return retVal.equals(input); } }).keySet()); } })); started.getAndSet(true); } }
From source file:com.google.caliper.runner.VmDataCollectingVisitor.java
@Override public void visit(VmPropertiesLogMessage logMessage) { vmProperties = Optional .of(ImmutableMap.copyOf(Maps.filterKeys(logMessage.properties(), PROPERTIES_TO_RETAIN))); }
From source file:org.apache.druid.server.lookup.cache.polling.OffHeapPollingCache.java
public OffHeapPollingCache(final Iterable<Map.Entry<K, V>> entries) { synchronized (started) { this.cacheName = StringUtils.format("cache-%s", UUID.randomUUID()); this.reverseCacheName = StringUtils.format("reverseCache-%s", UUID.randomUUID()); mapCache = DB.createHashMap(cacheName).make(); reverseCache = DB.createHashMap(reverseCacheName).make(); ImmutableSet.Builder<V> setOfValuesBuilder = ImmutableSet.builder(); for (Map.Entry<K, V> entry : entries) { mapCache.put(entry.getKey(), entry.getValue()); setOfValuesBuilder.add(entry.getValue()); }/* ww w. j a v a2s . co m*/ final Set<V> setOfValues = setOfValuesBuilder.build(); reverseCache.putAll(Maps.asMap(setOfValues, new Function<V, List<K>>() { @Override public List<K> apply(final V input) { return Lists.newArrayList(Maps.filterKeys(mapCache, new Predicate<K>() { @Override public boolean apply(K key) { V retVal = mapCache.get(key); if (retVal == null) { return false; } return retVal.equals(input); } }).keySet()); } })); started.getAndSet(true); } }
From source file:org.pentaho.caching.api.PentahoCacheTemplateConfiguration.java
/** * Generates a new PentahoCacheTemplateConfiguration which merges the properties in the current * Configuration with those in templateOverrides, replacing existing entries if present. *///from ww w. j av a 2 s . com public PentahoCacheTemplateConfiguration overrideProperties(final Map<String, String> templateOverrides) { Map<String, String> overriddenProperties = ImmutableMap.<String, String>builder() .putAll(Maps.filterKeys(getProperties(), new Predicate<String>() { @Override public boolean apply(String s) { return !templateOverrides.containsKey(s); } })).putAll(templateOverrides).build(); return new PentahoCacheTemplateConfiguration(getDescription(), overriddenProperties, getCacheManager()); }
From source file:com.facebook.presto.sql.planner.SubPlanBuilder.java
public SubPlan build() { Set<Symbol> dependencies = SymbolExtractor.extract(root); PlanFragment fragment = new PlanFragment(id, partitionedSource, Maps.filterKeys(allocator.getTypes(), in(dependencies)), root); return new SubPlan(fragment, children); }