List of usage examples for com.google.common.collect ImmutableMap entrySet
public final ImmutableSet<Entry<K, V>> entrySet()
From source file:com.facebook.buck.core.build.engine.manifest.ManifestUtil.java
public static Manifest fromMap(RuleKey key, ImmutableMap<RuleKey, ImmutableMap<String, HashCode>> map) { Manifest manifest = new Manifest(key); for (Entry<RuleKey, ImmutableMap<String, HashCode>> entry : map.entrySet()) { int entryHashIndex = 0; int[] entryHashIndices = new int[entry.getValue().size()]; for (Entry<String, HashCode> innerEntry : entry.getValue().entrySet()) { entryHashIndices[entryHashIndex++] = manifest.addHash(innerEntry.getKey(), innerEntry.getValue()); }//from w w w .j av a 2s . co m manifest.entries.add(new Pair<RuleKey, int[]>(entry.getKey(), entryHashIndices)); } return manifest; }
From source file:net.oneandone.troilus.Optionals.java
/** * @param map the map (could include optional values) * @return the map which optional wrapped values *///from w ww.j ava 2 s. com public static ImmutableMap<String, Optional<Object>> toGuavaOptional(ImmutableMap<String, Object> map) { Map<String, Optional<Object>> result = Maps.newHashMap(); for (Entry<String, Object> entry : map.entrySet()) { result.put(entry.getKey(), toGuavaOptional(entry.getValue())); } return ImmutableMap.copyOf(result); }
From source file:com.facebook.buck.cli.EnvironmentFilter.java
/** * Given a map (environment variable name: environment variable * value) pairs, returns a map without the variables which we should * not pass to child processes (buck.py, javac, etc.) * * Keeping the environment map clean helps us avoid jettisoning the * parser cache, as we have to rebuild it any time the environment * changes./*from w w w . j ava2 s . co m*/ */ public static ImmutableMap<String, String> filteredEnvironment(ImmutableMap<String, String> environment) { ImmutableMap.Builder<String, String> filteredEnvironmentBuilder = ImmutableMap.builder(); for (Map.Entry<String, String> envEntry : environment.entrySet()) { String key = envEntry.getKey(); if (!ENV_TO_REMOVE.contains(key)) { if (Platform.detect() == Platform.WINDOWS) { // Windows environment variables are case insensitive. While an ImmutableMap will throw // if we get duplicate key, we don't have to worry about this for Windows. filteredEnvironmentBuilder.put(key.toUpperCase(Locale.US), envEntry.getValue()); } else { filteredEnvironmentBuilder.put(envEntry); } } } return filteredEnvironmentBuilder.build(); }
From source file:com.facebook.buck.distributed.DistributedBuildCellIndexer.java
private static BuildJobStateBuckConfig dumpConfig(BuckConfig buckConfig) { BuildJobStateBuckConfig jobState = new BuildJobStateBuckConfig(); jobState.setUserEnvironment(buckConfig.getEnvironment()); Map<String, List<OrderedStringMapEntry>> rawConfig = Maps.transformValues( buckConfig.getRawConfigForDistBuild(), new Function<ImmutableMap<String, String>, List<OrderedStringMapEntry>>() { @Override/*w ww .j a va2 s.c om*/ public List<OrderedStringMapEntry> apply(ImmutableMap<String, String> input) { List<OrderedStringMapEntry> result = new ArrayList<>(); for (Map.Entry<String, String> entry : input.entrySet()) { result.add(new OrderedStringMapEntry(entry.getKey(), entry.getValue())); } return result; } }); jobState.setRawBuckConfig(rawConfig); jobState.setArchitecture(buckConfig.getArchitecture().name()); jobState.setPlatform(buckConfig.getPlatform().name()); return jobState; }
From source file:com.foudroyantfactotum.tool.structure.utility.PartBlockState.java
public static PartBlockState of(IBlockState b, String s) { final Collection<IProperty<?>> defaultProp = b.getPropertyKeys(); final ImmutableMap.Builder<IProperty, Comparable> builderDef = ImmutableMap.builder(); final Set<IProperty> properties = new HashSet<>(defaultProp); for (final String singleFullState : s.split(",")) { if (!singleFullState.contains(":")) { throw new StructureDefinitionBuilder.StructureDefinitionError("Missing property divider"); }/* w w w .ja v a 2 s. c o m*/ final String propName = singleFullState.split(":")[0]; final String propVal = singleFullState.split(":")[1]; boolean hasFoundProp = false; for (final IProperty prop : defaultProp) { if (prop.getName().equalsIgnoreCase(propName)) { boolean hasFoundVal = false; for (final Comparable val : (Collection<Comparable>) prop.getAllowedValues()) { if (val.toString().equalsIgnoreCase(propVal)) { builderDef.put(prop, val); properties.remove(prop); hasFoundVal = true; break; } } if (!hasFoundVal) { throw new StructureDefinitionBuilder.StructureDefinitionError("Property value missing: '" + prop.getName() + "' value missing: '" + propVal + "' in '" + prop.getAllowedValues() + "' on '" + b.getBlock().getUnlocalizedName() + "' with property: '" + b.getPropertyKeys()); } hasFoundProp = true; break; } } if (!hasFoundProp) { throw new StructureDefinitionBuilder.StructureDefinitionError( "Missing property: '" + propName + "' value: '" + propVal + "' on block: '" + b.getBlock().getUnlocalizedName() + "' with property: '" + b.getPropertyKeys()); } } final ImmutableMap<IProperty, Comparable> definitive = builderDef.build(); for (Map.Entry<IProperty, Comparable> entry : definitive.entrySet()) { b = b.withProperty(entry.getKey(), entry.getValue()); } return new PartBlockState(builderDef.build(), ImmutableList.copyOf(properties), b); }
From source file:com.facebook.buck.rules.DefaultCellPathResolver.java
private static void constructFullMapping(ImmutableMap.Builder<RelativeCellName, Path> result, Set<Path> pathStack, RelativeCellName parentCellPath, DefaultCellPathResolver parentStub) { ImmutableMap<String, Path> partialMapping = parentStub.getPartialMapping(); for (Map.Entry<String, Path> entry : partialMapping.entrySet()) { Path cellRoot = entry.getValue().normalize(); try {/* w ww.ja v a2 s . co m*/ cellRoot = cellRoot.toRealPath().normalize(); } catch (IOException e) { LOG.warn("cellroot [" + cellRoot + "] does not exist in filesystem"); } // Do not recurse into previously visited Cell roots. It's OK for cell references to form // cycles as long as the targets don't form a cycle. // We intentionally allow for the map to contain entries whose Config objects can't be // created. These are still technically reachable and will not cause problems as long as none // of the BuildTargets in the build reference them. if (pathStack.contains(cellRoot)) { continue; } pathStack.add(cellRoot); RelativeCellName relativeCellName = parentCellPath.withAppendedComponent(entry.getKey()); result.put(relativeCellName, cellRoot); Config config; try { // We don't support overriding repositories from the command line so creating the config // with no overrides is OK. config = Configs.createDefaultConfig(cellRoot); } catch (IOException e) { LOG.debug(e, "Error when constructing cell, skipping path %s", cellRoot); continue; } constructFullMapping(result, pathStack, relativeCellName, new DefaultCellPathResolver(cellRoot, config)); pathStack.remove(cellRoot); } }
From source file:com.facebook.buck.rules.macros.MacroHandler.java
private static ImmutableMap<String, MacroExpander> addOutputToFileExpanders( ImmutableMap<String, MacroExpander> source) { ImmutableMap.Builder<String, MacroExpander> builder = ImmutableMap.builder(); for (Map.Entry<String, MacroExpander> entry : source.entrySet()) { builder.put(entry.getKey(), entry.getValue()); builder.put("@" + entry.getKey(), new OutputToFileExpander(entry.getValue())); }/*from w ww .j a v a 2 s. co m*/ return builder.build(); }
From source file:eu.eubrazilcc.lvl.storage.mongodb.MongoDBHelper.java
public static BasicDBObject toProjection(final @Nullable ImmutableMap<String, Boolean> projection) { BasicDBObject obj = null;/*from ww w.j a v a2 s . co m*/ if (projection != null && !projection.isEmpty()) { obj = new BasicDBObject(); final ImmutableSet<Entry<String, Boolean>> entrySet = projection.entrySet(); final boolean action = entrySet.iterator().next().getValue(); for (final Entry<String, Boolean> entry : entrySet) { String field = null; checkState(action == entry.getValue(), "A projection cannot contain both include and exclude specifications"); checkState(isNotBlank(field = trimToNull(entry.getKey())), "Uninitialized field"); obj.append(field, action ? 1 : 0); } } return obj; }
From source file:org.springframework.ide.eclipse.boot.templates.BootJavaContext.java
private static <T> Map<String, Predicate<T>> negate(ImmutableMap<String, Predicate<T>> base) { ImmutableMap.Builder<String, Predicate<T>> builder = ImmutableMap.builder(); builder.putAll(base);//from w w w . j a va 2s .co m for (Entry<String, Predicate<T>> e : base.entrySet()) { String name = e.getKey(); if (!name.startsWith("!")) { builder.put("!" + name, e.getValue().negate()); } } return builder.build(); }
From source file:com.facebook.buck.cxx.ByteBufferReplacer.java
/** * Build a replacer using the given map of paths to replacement paths, using {@code charset} * to convert to underlying byte arrays. If the replacement paths are not long enough, use * the given path separator to fill.//from w ww . j a v a 2 s .co m */ public static ByteBufferReplacer fromPaths(ImmutableMap<Path, Path> paths, char separator, Charset charset) { ImmutableMap.Builder<byte[], byte[]> replacements = ImmutableMap.builder(); for (Map.Entry<Path, Path> entry : paths.entrySet()) { String original = entry.getKey().toString(); String replacement = entry.getValue().toString(); // If the replacement string is too small, keep adding the path separator until it's long // enough. while (getBytes(original, charset).length > getBytes(replacement, charset).length) { replacement += separator; } // Depending on what was passed in, or the character encoding, we can end up with a // replacement string that is too long, which we can't recover from. Preconditions .checkArgument(getBytes(original, charset).length == getBytes(replacement, charset).length); replacements.put(getBytes(original, charset), getBytes(replacement, charset)); } return new ByteBufferReplacer(replacements.build()); }