List of usage examples for com.google.common.collect Maps filterEntries
@CheckReturnValue public static <K, V> BiMap<K, V> filterEntries(BiMap<K, V> unfiltered, Predicate<? super Entry<K, V>> entryPredicate)
From source file:fr.aliacom.obm.common.calendar.loader.filter.EventsByIdFilter.java
@Override public Map<EventObmId, Event> filter(Map<EventObmId, Event> events) { return Maps.filterEntries(events, new Predicate<Map.Entry<EventObmId, Event>>() { @Override/*from w w w . j av a 2 s .c o m*/ public boolean apply(Entry<EventObmId, Event> input) { return !idsToFilter.contains(input.getKey().getObmId()); } }); }
From source file:com.facebook.buck.util.PatternsMatcher.java
/** * @return a view of the given map where all non-matching keys are removed. *///from ww w . jav a2s.c om public <V> Map<String, V> filterMatchingMapKeys(final Map<String, V> entries) { if (!hasPatterns) { return entries; } return Maps.filterEntries(entries, entry -> matches(entry.getKey())); }
From source file:io.druid.server.StatusResource.java
@GET @Path("/properties") @ResourceFilters(ConfigResourceFilter.class) @Produces(MediaType.APPLICATION_JSON)// w w w .j ava2 s .com public Map<String, String> getProperties() { Map<String, String> allProperties = Maps.fromProperties(properties); Set<String> hidderProperties = druidServerConfig.getHiddenProperties(); return Maps.filterEntries(allProperties, (entry) -> !hidderProperties.contains(entry.getKey())); }
From source file:org.summer.dsl.xbase.lib.MapExtensions.java
/** * <p>// w ww . ja va 2 s. c o m * Returns a filtered live view on top of the original map. Changes to one affect the other. * </p> * * <p> * The mapping is done lazily. That is, subsequent access of the values in the map will repeatedly apply the * transformation. Characteristics of the original map, such as iteration order, are left intact. Changes in the * original map are reflected in the result map. The results supports removal if the original map supports removal. * </p> * * @param original * the original map. May not be <code>null</code>. * @param predicate * the predicate. May not be <code>null</code>. * @return a filtered view on top of the original map. Never <code>null</code>. */ public static <K, V> Map<K, V> filter(Map<K, V> original, final Function2<? super K, ? super V, Boolean> predicate) { if (predicate == null) throw new NullPointerException("predicate"); return Maps.filterEntries(original, new Predicate<Map.Entry<K, V>>() { public boolean apply(Map.Entry<K, V> input) { Boolean result = predicate.apply(input.getKey(), input.getValue()); return result.booleanValue(); } }); }
From source file:org.eclipse.xtext.xbase.lib.MapExtensions.java
/** * <p>//from w w w. ja va 2 s. com * Returns a filtered live view on top of the original map. Changes to one affect the other. * </p> * * <p> * The mapping is done lazily. That is, subsequent access of the values in the map will repeatedly apply the * transformation. Characteristics of the original map, such as iteration order, are left intact. Changes in the * original map are reflected in the result map. The results supports removal if the original map supports removal. * </p> * * @param original * the original map. May not be <code>null</code>. * @param predicate * the predicate. May not be <code>null</code>. * @return a filtered view on top of the original map. Never <code>null</code>. */ public static <K, V> Map<K, V> filter(Map<K, V> original, final Function2<? super K, ? super V, Boolean> predicate) { if (predicate == null) throw new NullPointerException("predicate"); return Maps.filterEntries(original, new Predicate<Map.Entry<K, V>>() { @Override public boolean apply(Map.Entry<K, V> input) { Boolean result = predicate.apply(input.getKey(), input.getValue()); return result.booleanValue(); } }); }
From source file:com.metamx.emitter.service.ServiceMetricEvent.java
@Override @JsonValue/* w w w .j a va 2 s .c o m*/ public Map<String, Object> toMap() { return ImmutableMap.<String, Object>builder().put("feed", getFeed()) .put("timestamp", createdTime.toString()).put("service", service).put("host", host) .put("metric", metric).put("value", value) .putAll(Maps.filterEntries(userDims, new Predicate<Map.Entry<String, Object>>() { @Override public boolean apply(Map.Entry<String, Object> input) { return input.getKey() != null; } })).build(); }
From source file:com.facebook.presto.sql.planner.iterative.rule.PruneIndexSourceColumns.java
@Override public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator, Session session) { ProjectNode parent = (ProjectNode) node; PlanNode source = lookup.resolve(parent.getSource()); if (!(source instanceof IndexSourceNode)) { return Optional.empty(); }// ww w . j ava 2 s . c o m IndexSourceNode indexSourceNode = (IndexSourceNode) source; Optional<Set<Symbol>> prunedIndexSourceOutputs = pruneInputs(indexSourceNode.getOutputSymbols(), parent.getAssignments().getExpressions()); if (!prunedIndexSourceOutputs.isPresent()) { return Optional.empty(); } Set<Symbol> newLookupSymbols = indexSourceNode.getLookupSymbols().stream() .filter(prunedIndexSourceOutputs.get()::contains).collect(toImmutableSet()); Map<Symbol, ColumnHandle> newAssignments = Maps.filterEntries(indexSourceNode.getAssignments(), entry -> prunedIndexSourceOutputs.get().contains(entry.getKey()) || tupleDomainReferencesColumnHandle(indexSourceNode.getEffectiveTupleDomain(), entry.getValue())); List<Symbol> prunedIndexSourceOutputList = indexSourceNode.getOutputSymbols().stream() .filter(prunedIndexSourceOutputs.get()::contains).collect(toImmutableList()); return Optional.of(parent.replaceChildren( ImmutableList.of(new IndexSourceNode(indexSourceNode.getId(), indexSourceNode.getIndexHandle(), indexSourceNode.getTableHandle(), indexSourceNode.getLayout(), newLookupSymbols, prunedIndexSourceOutputList, newAssignments, indexSourceNode.getEffectiveTupleDomain())))); }
From source file:com.facebook.buck.util.cache.LoadingCacheFileHashCache.java
@Override public void invalidateWithParents(Path path) { long start = System.nanoTime(); Iterable<Path> pathsToInvalidate = Maps.filterEntries(loadingCache.asMap(), entry -> { Preconditions.checkNotNull(entry); // If we get a invalidation for a file which is a prefix of our current one, this // means the invalidation is of a symlink which points to a directory (since events // won't be triggered for directories). We don't fully support symlinks, however, // we do support some limited flows that use them to point to read-only storage // (e.g. the `project.read_only_paths`). For these limited flows to work correctly, // we invalidate. if (entry.getKey().startsWith(path)) { return true; }//from w w w .j a va 2 s .c om // Otherwise, we want to invalidate the entry if the path matches it. We also // invalidate any directories that contain this entry, so use the following // comparison to capture both these scenarios. if (path.startsWith(entry.getKey())) { return true; } return false; }).keySet(); for (Path pathToInvalidate : pathsToInvalidate) { invalidate(pathToInvalidate); } cacheInvalidationAggregatedNanoTime += System.nanoTime() - start; numberOfInvalidations++; }
From source file:io.druid.java.util.emitter.service.ServiceMetricEvent.java
@Override @JsonValue/*from w ww .j a va2 s. c o m*/ public Map<String, Object> toMap() { return ImmutableMap.<String, Object>builder().put("feed", getFeed()) .put("timestamp", createdTime.toString()).putAll(serviceDims).put("metric", metric) .put("value", value) .putAll(Maps.filterEntries(userDims, new Predicate<Map.Entry<String, Object>>() { @Override public boolean apply(Map.Entry<String, Object> input) { return input.getKey() != null; } })).build(); }
From source file:com.facebook.buck.parser.SymlinkCache.java
public void registerInputsUnderSymlinks(Cell currentCell, Cell targetCell, Path buildFile, TargetNode<?> node) throws IOException { Map<Path, Path> newSymlinksEncountered = inputFilesUnderSymlink(node.getInputs(), node.getFilesystem()); Optional<ImmutableList<Path>> readOnlyPaths = targetCell.getBuckConfig().getView(ParserConfig.class) .getReadOnlyPaths();//from w w w . j a v a 2s . c o m if (readOnlyPaths.isPresent() && currentCell != null) { newSymlinksEncountered = Maps.filterEntries(newSymlinksEncountered, entry -> { for (Path readOnlyPath : readOnlyPaths.get()) { if (entry.getKey().startsWith(readOnlyPath)) { LOG.debug("Target %s contains input files under a path which contains a symbolic " + "link (%s). It will be cached because it belongs under %s, a " + "read-only path white listed in .buckconfig. under [project] " + "read_only_paths", node.getBuildTarget(), entry, readOnlyPath); return false; } } return true; }); } if (newSymlinksEncountered.isEmpty()) { return; } AllowSymlinks allowSymlinks = Objects .requireNonNull(cellSymlinkAllowability.get(node.getBuildTarget().getCellPath())); if (allowSymlinks == ParserConfig.AllowSymlinks.FORBID) { throw new HumanReadableException( "Target %s contains input files under a path which contains a symbolic link " + "(%s). To resolve this, use separate rules and declare dependencies instead of " + "using symbolic links.\n" + "If the symlink points to a read-only filesystem, you can specify it in the " + "project.read_only_paths .buckconfig setting. Buck will assume files under that " + "path will never change.", node.getBuildTarget(), newSymlinksEncountered); } // If we're not explicitly forbidding symlinks, either warn to the console or the log file // depending on the config setting. String msg = String .format("Disabling parser cache for target %s, because one or more input files are under a " + "symbolic link (%s). This will severely impact the time spent in parsing! To " + "resolve this, use separate rules and declare dependencies instead of using " + "symbolic links.", node.getBuildTarget(), newSymlinksEncountered); if (allowSymlinks == ParserConfig.AllowSymlinks.WARN) { eventBus.post(ConsoleEvent.warning(msg)); } else { LOG.warn(msg); } eventBus.post(ParsingEvent.symlinkInvalidation(buildFile.toString())); buildInputPathsUnderSymlink.add(buildFile); }