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:org.javersion.object.types.BasicObjectType.java
public static BasicObjectType of(TypeDescriptor type, String alias, @Nullable Set<String> fieldNames) { Map<String, FieldDescriptor> fields = type.getFields(); if (fields != null) { fields = Maps.filterEntries(fields, entry -> fieldNames.contains(entry.getKey())); }//from ww w .ja va 2s . com return of(type, alias, new ObjectCreator(type), null, fields); }
From source file:es.usc.citius.composit.core.matcher.graph.AbstractMatchGraph.java
protected Map<E, T> filter(final Map<E, T> map, final T type, final TypeSelector selector) { // First get all from matchTable and then filter using the selector return Maps.filterEntries(map, new Predicate<Map.Entry<E, T>>() { @Override/* ww w . jav a 2 s .c o m*/ public boolean apply(Map.Entry<E, T> input) { switch (selector) { case AT_LEAST: // The match type is at least as good as the provided one. // Example: Match at least subsumes: accepts exact, plugin and subsumes return input.getValue().compareTo(type) <= 0; case AT_MOST: return input.getValue().compareTo(type) >= 0; default: return input.getValue().equals(type); } } }); }
From source file:org.ow2.sirocco.cloudmanager.api.openstack.server.utils.MapHelper.java
/** * Replace the values of the orignal map entries with the replace ones, add missing ones and remove the ones which are not defined in the replace map. * * @param original// ww w. j a v a 2 s.c o m * @param replace * @return */ public static Map<String, String> replaceMap(final Map<String, String> original, final Map<String, String> replace) { if (replace == null || replace.size() == 0) { return Maps.newHashMap(); } // first, remove entries which are not defined in the replace map Map<String, String> filter = Maps.filterEntries(original, new Predicate<Map.Entry<String, String>>() { @Override public boolean apply(java.util.Map.Entry<String, String> input) { return replace.get(input.getKey()) != null; } }); // then update the values of the filtered map Map<String, String> updated = Maps.transformEntries(filter, new Maps.EntryTransformer<String, String, String>() { @Override public String transformEntry(String key, String value) { if (replace.get(key) != null) { return replace.get(key); } else { return value; } } }); // then add the entries from the replace map which are not in the updated map Map<String, String> result = Maps.newHashMap(updated); result.putAll(Maps.difference(updated, replace).entriesOnlyOnRight()); return result; }
From source file:org.gradle.launcher.cli.converter.LayoutToPropertiesConverter.java
public Map<String, String> convert(BuildLayoutParameters layout, Map<String, String> properties) { configureFromBuildDir(layout.getSearchDir(), layout.getSearchUpwards(), properties); configureFromGradleUserHome(layout.getGradleUserHomeDir(), properties); properties.putAll(Maps.filterEntries((Map) System.getProperties(), new Predicate<Map.Entry<?, ?>>() { public boolean apply(Map.Entry<?, ?> input) { return input.getKey() instanceof Serializable && (input.getValue() instanceof Serializable || input.getValue() == null); }/*from w w w .j a va2 s. c o m*/ })); return properties; }
From source file:net.sf.lucis.core.Highlight.java
private static ImmutableMap<String, Integer> filter(Map<String, Integer> fields) { if (fields == null || fields.isEmpty()) { return ImmutableMap.of(); }/* w ww . j av a2s . co m*/ return ImmutableMap.copyOf(Maps.filterEntries(fields, FILTER)); }
From source file:com.github.tomakehurst.wiremock.recording.ScenarioProcessor.java
public void putRepeatedRequestsInScenarios(List<StubMapping> stubMappings) { ImmutableListMultimap<RequestPattern, StubMapping> stubsGroupedByRequest = Multimaps.index(stubMappings, new Function<StubMapping, RequestPattern>() { @Override//from w w w. j a v a2 s . c o m public RequestPattern apply(StubMapping mapping) { return mapping.getRequest(); } }); Map<RequestPattern, Collection<StubMapping>> groupsWithMoreThanOneStub = Maps.filterEntries( stubsGroupedByRequest.asMap(), new Predicate<Map.Entry<RequestPattern, Collection<StubMapping>>>() { @Override public boolean apply(Map.Entry<RequestPattern, Collection<StubMapping>> input) { return input.getValue().size() > 1; } }); for (Map.Entry<RequestPattern, Collection<StubMapping>> entry : groupsWithMoreThanOneStub.entrySet()) { putStubsInScenario(ImmutableList.copyOf(entry.getValue())); } }
From source file:io.prestosql.sql.planner.iterative.rule.PruneIndexSourceColumns.java
@Override protected Optional<PlanNode> pushDownProjectOff(PlanNodeIdAllocator idAllocator, IndexSourceNode indexSourceNode, Set<Symbol> referencedOutputs) { Set<Symbol> prunedLookupSymbols = indexSourceNode.getLookupSymbols().stream() .filter(referencedOutputs::contains).collect(toImmutableSet()); Map<Symbol, ColumnHandle> prunedAssignments = Maps.filterEntries(indexSourceNode.getAssignments(), entry -> referencedOutputs.contains(entry.getKey()) || tupleDomainReferencesColumnHandle( indexSourceNode.getCurrentConstraint(), entry.getValue())); List<Symbol> prunedOutputList = indexSourceNode.getOutputSymbols().stream() .filter(referencedOutputs::contains).collect(toImmutableList()); return Optional.of(new IndexSourceNode(indexSourceNode.getId(), indexSourceNode.getIndexHandle(), indexSourceNode.getTableHandle(), indexSourceNode.getLayout(), prunedLookupSymbols, prunedOutputList, prunedAssignments, indexSourceNode.getCurrentConstraint())); }
From source file:com.facebook.buck.util.cache.WatchedFileHashCache.java
/** * Called when file change events are posted to the file change EventBus to invalidate cached * build rules if required. {@link Path}s contained within events must all be relative to the * {@link ProjectFilesystem} root.//from w ww .j a va2 s . c o m */ @Subscribe public synchronized void onFileSystemChange(WatchEvent<?> event) { if (WatchEvents.isPathChangeEvent(event)) { // Path event, remove the path from the cache as it has been changed, added or deleted. final Path path = ((Path) event.context()).normalize(); LOG.verbose("Invalidating %s", path); 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; } // 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(); LOG.verbose("Paths to invalidate: %s", pathsToInvalidate); for (Path pathToInvalidate : pathsToInvalidate) { invalidateResolved(pathToInvalidate); } } else { // Non-path change event, likely an overflow due to many change events: invalidate everything. LOG.debug("Invalidating all"); invalidateAll(); } }
From source file:org.apache.brooklyn.util.core.xstream.ImmutableMapConverter.java
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Map<?, ?> map = Maps.newLinkedHashMap(); populateMap(reader, context, map);/*from www. j av a2 s .co m*/ return ImmutableMap.copyOf(Maps.filterEntries(map, new Predicate<Map.Entry<?, ?>>() { @Override public boolean apply(Entry<?, ?> input) { return input != null && input.getKey() != null && input.getValue() != null; } })); }
From source file:org.gradle.language.base.internal.model.DefaultVariantsMetaData.java
private DefaultVariantsMetaData(Map<String, Object> variantCoordinates, Map<String, ModelType<?>> variantAxisTypes) { this.variantCoordinates = variantCoordinates; this.allVariantAxes = variantCoordinates.keySet(); this.nonNullVariantAxes = ImmutableSet .copyOf(Maps.filterEntries(variantCoordinates, new Predicate<Map.Entry<String, Object>>() { @Override//from w w w. jav a2 s. co m public boolean apply(Map.Entry<String, Object> input) { return input.getValue() != null; } }).keySet()); this.variantAxisTypes = variantAxisTypes; }