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.smartparam.repository.memory.InMemoryParamRepository.java
public void clearExcept(String... parameterNames) { final Set<String> parametersToKeep = Sets.newHashSet(parameterNames); Map<String, InMemoryParameter> entriesToKeep = ImmutableMap .copyOf(Maps.filterKeys(repository, new Predicate<String>() { @Override/*from w w w. j a v a 2 s. c o m*/ public boolean apply(String input) { return parametersToKeep.contains(input); } })); repository.clear(); repository.putAll(entriesToKeep); }
From source file:com.google.devtools.build.lib.exec.apple.XCodeLocalEnvProvider.java
@Override public Map<String, String> rewriteLocalEnv(Map<String, String> env, Path execRoot, Path tmpDir, String productName) throws IOException { boolean containsXcodeVersion = env.containsKey(AppleConfiguration.XCODE_VERSION_ENV_NAME); boolean containsAppleSdkVersion = env.containsKey(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME); ImmutableMap.Builder<String, String> newEnvBuilder = ImmutableMap.builder(); newEnvBuilder.putAll(Maps.filterKeys(env, k -> !k.equals("TMPDIR"))); newEnvBuilder.put("TMPDIR", tmpDir.getPathString()); if (!containsXcodeVersion && !containsAppleSdkVersion) { return newEnvBuilder.build(); }//from www. j av a2s. c o m // Empty developer dir indicates to use the system default. // TODO(bazel-team): Bazel's view of the xcode version and developer dir should be explicitly // set for build hermeticity. String developerDir = ""; if (containsXcodeVersion) { String version = env.get(AppleConfiguration.XCODE_VERSION_ENV_NAME); developerDir = getDeveloperDir(execRoot, DottedVersion.fromString(version), productName); newEnvBuilder.put("DEVELOPER_DIR", developerDir); } if (containsAppleSdkVersion) { // The Apple platform is needed to select the appropriate SDK. if (!env.containsKey(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME)) { throw new IOException("Could not resolve apple platform for determining SDK"); } String iosSdkVersion = env.get(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME); String appleSdkPlatform = env.get(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME); newEnvBuilder.put("SDKROOT", getSdkRoot(execRoot, developerDir, iosSdkVersion, appleSdkPlatform, productName)); } return newEnvBuilder.build(); }
From source file:com.mgmtp.perfload.core.common.util.PropertiesUtils.java
public static Map<String, String> getSubMap(final PropertiesMap properties, final String keyPrefix) { final String prefix = keyPrefix.endsWith(".") ? keyPrefix : keyPrefix + "."; Map<String, String> map = Maps.filterKeys(properties, new Predicate<String>() { @Override//from w w w .j a v a 2s .com public boolean apply(final String input) { return input.startsWith(prefix); } }); Map<String, String> result = newHashMapWithExpectedSize(map.size()); for (Entry<String, String> entry : map.entrySet()) { result.put(substringAfter(entry.getKey(), prefix), entry.getValue()); } return result; }
From source file:com.facebook.presto.tpch.TpchIndexResolver.java
@Override public ConnectorResolvedIndex resolveIndex(ConnectorTableHandle tableHandle, Set<ConnectorColumnHandle> indexableColumns, TupleDomain<ConnectorColumnHandle> tupleDomain) { checkArgument(tableHandle instanceof TpchTableHandle, "tableHandle is not an instance of TpchTableHandle: %s", tableHandle); TpchTableHandle tpchTableHandle = (TpchTableHandle) tableHandle; // Keep the fixed values that don't overlap with the indexableColumns // Note: technically we could more efficiently utilize the overlapped columns, but this way is simpler for now Map<ConnectorColumnHandle, Comparable<?>> fixedValues = Maps.filterKeys(tupleDomain.extractFixedValues(), not(in(indexableColumns)));/*from w ww . j a v a 2 s . c o m*/ // determine all columns available for index lookup ImmutableSet.Builder<String> builder = ImmutableSet.builder(); builder.addAll(transform(indexableColumns, columnNameGetter())); builder.addAll(transform(fixedValues.keySet(), columnNameGetter())); Set<String> lookupColumnNames = builder.build(); // do we have an index? if (!indexedData.getIndexedTable(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames).isPresent()) { return null; } TupleDomain<ConnectorColumnHandle> filteredTupleDomain = tupleDomain; if (!tupleDomain.isNone()) { filteredTupleDomain = TupleDomain .withColumnDomains(Maps.filterKeys(tupleDomain.getDomains(), not(in(fixedValues.keySet())))); } return new ConnectorResolvedIndex(new TpchIndexHandle(connectorId, tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames, TupleDomain.withFixedValues(fixedValues)), filteredTupleDomain); }
From source file:com.linkedin.bowser.core.grammar.AbstractNQLQueryBuilder.java
public Map<String, NQLObject> getLocalSymbolMap() { return Maps.newHashMap(Maps.filterKeys(_symbolMap, new Predicate<String>() { @Override//from w w w.j a va 2s .c o m public boolean apply(String key) { return _localSymbols.contains(key); } })); }
From source file:org.n52.iceland.util.activation.Activatables.java
public static <K, T> Map<K, T> deactivatedMap(Map<K, T> map, ActivationProvider<? super K> provider) { return Maps.filterKeys(map, Predicates.not(asPredicate(provider))); }
From source file:no.ssb.vtl.script.operations.union.UnionOperation.java
private void checkDataStructures(DataStructure baseDataStructure, DataStructure nextDataStructure) { // Identifiers and attribute should be equals in name, role and type. Set<String> requiredNames = nonAttributeNames(baseDataStructure); Set<String> providedNames = nonAttributeNames(nextDataStructure); checkArgument(requiredNames.equals(providedNames), "dataset was incompatible with the required data structure, missing: %s, unexpected %s", Sets.difference(requiredNames, providedNames), Sets.difference(providedNames, requiredNames)); Map<String, Component.Role> requiredRoles = Maps.filterKeys(baseDataStructure.getRoles(), requiredNames::contains);/* w w w .j av a 2s . com*/ Map<String, Component.Role> providedRoles = Maps.filterKeys(nextDataStructure.getRoles(), requiredNames::contains); checkArgument(requiredRoles.equals(providedRoles), "dataset was incompatible with the required data structure, missing: %s, unexpected %s", Sets.difference(requiredRoles.entrySet(), providedRoles.entrySet()), Sets.difference(providedRoles.entrySet(), requiredRoles.entrySet())); Map<String, Class<?>> requiredTypes = Maps.filterKeys(baseDataStructure.getTypes(), requiredNames::contains); Map<String, Class<?>> providedTypes = Maps.filterKeys(nextDataStructure.getTypes(), requiredNames::contains); checkArgument(requiredTypes.equals(providedTypes), "dataset was incompatible with the required data structure, missing: %s, unexpected %s", Sets.difference(requiredTypes.entrySet(), providedTypes.entrySet()), Sets.difference(providedTypes.entrySet(), requiredTypes.entrySet())); }
From source file:com.palantir.atlasdb.keyvalue.impl.RowResults.java
public static <T> Function<RowResult<T>, RowResult<T>> createFilterColumns(final Predicate<byte[]> keepColumn) { return new Function<RowResult<T>, RowResult<T>>() { @Override//from w ww. j av a2 s . co m public RowResult<T> apply(RowResult<T> row) { return RowResult.create(row.getRowName(), Maps.filterKeys(row.getColumns(), keepColumn)); } }; }
From source file:ai.grakn.graql.internal.reasoner.query.QueryAnswers.java
/** * filter answers by constraining the variable set to the provided one * @param vars set of variable names//from w w w . ja v a2 s.c om * @return filtered answers */ public QueryAnswers filterVars(Set<Var> vars) { return new QueryAnswers(this.stream().map(result -> Maps.filterKeys(result.map(), vars::contains)) .map(QueryAnswer::new).collect(Collectors.toSet())); }
From source file:io.druid.storage.oss.OssDataSegmentMover.java
@Override public DataSegment move(DataSegment segment, Map<String, Object> targetLoadSpec) throws SegmentLoadingException { Map<String, Object> loadSpec = segment.getLoadSpec(); String srcBucket = MapUtils.getString(loadSpec, "bucket"); String srcKey = MapUtils.getString(loadSpec, "key"); String srcDescPath = OssUtils.descriptorPathForSegmentPath(srcKey); final String dstBucket = MapUtils.getString(targetLoadSpec, "bucket"); final String dstKey = MapUtils.getString(targetLoadSpec, "baseKey"); final String targetOssPath = OssUtils.constructSegmentPath(dstKey, segment); String targetOssDescriptorPath = OssUtils.descriptorPathForSegmentPath(targetOssPath); if (dstBucket.isEmpty()) { throw new SegmentLoadingException("target oss bucket is not specified"); }//from w w w.j a va 2 s . c o m if (targetOssPath.isEmpty()) { throw new SegmentLoadingException("target oss key is not specified"); } safeMove(srcBucket, srcKey, dstBucket, targetOssPath); safeMove(srcBucket, srcDescPath, dstBucket, targetOssDescriptorPath); return segment.withLoadSpec( ImmutableMap.<String, Object>builder().putAll(Maps.filterKeys(loadSpec, new Predicate<String>() { @Override public boolean apply(String input) { return !(input.equals("bucket") || input.equals("key")); } })).put("bucket", dstBucket).put("key", targetOssPath).build()); }