List of usage examples for com.google.common.collect ImmutableMap entrySet
public final ImmutableSet<Entry<K, V>> entrySet()
From source file:com.facebook.buck.artifact_cache.ArtifactCaches.java
private static Request.Builder addHeadersToBuilder(Request.Builder builder, ImmutableMap<String, String> headers) { ImmutableSet<Map.Entry<String, String>> entries = headers.entrySet(); for (Map.Entry<String, String> header : entries) { builder.addHeader(header.getKey(), header.getValue()); }/*www . j a v a2s . c om*/ return builder; }
From source file:com.facebook.buck.apple.XcodeRuleConfiguration.java
/** * Convert from a raw json representation of the Configuration to an actual Configuration object. * * @param configurations// ww w . j ava 2 s.c o m * A map of configuration names to lists, where each each element is a layer of the * configuration. Each layer can be specified as a path to a .xcconfig file, or a dictionary of * xcode build settings. */ public static ImmutableSet<XcodeRuleConfiguration> fromRawJsonStructure( ImmutableMap<String, ImmutableList<Either<Path, ImmutableMap<String, String>>>> configurations) { ImmutableSet.Builder<XcodeRuleConfiguration> builder = ImmutableSet.builder(); for (ImmutableMap.Entry<String, ImmutableList<Either<Path, ImmutableMap<String, String>>>> entry : configurations .entrySet()) { ImmutableList.Builder<Layer> layers = ImmutableList.builder(); for (Either<Path, ImmutableMap<String, String>> value : entry.getValue()) { if (value.isLeft()) { layers.add(new Layer(value.getLeft())); } else if (value.isRight()) { layers.add(new Layer(value.getRight())); } } builder.add(new XcodeRuleConfiguration(entry.getKey(), layers.build())); } return builder.build(); }
From source file:com.facebook.buck.rules.Manifest.java
@VisibleForTesting static Manifest fromMap(ImmutableMap<RuleKey, ImmutableMap<String, HashCode>> map) { Manifest manifest = new Manifest(); for (Map.Entry<RuleKey, ImmutableMap<String, HashCode>> entry : map.entrySet()) { int entryHashIndex = 0; int[] entryHashIndices = new int[entry.getValue().size()]; for (Map.Entry<String, HashCode> innerEntry : entry.getValue().entrySet()) { entryHashIndices[entryHashIndex++] = manifest.addHash(innerEntry.getKey(), innerEntry.getValue()); }/*from www . ja v a 2 s . co m*/ manifest.entries.add(new Pair<>(entry.getKey(), entryHashIndices)); } return manifest; }
From source file:com.google.devtools.build.docgen.SkylarkDocumentationCollector.java
/** * Collects and returns all the Java objects reachable in Skylark from (and including) * firstClass with the corresponding SkylarkModule annotation. * * <p>Note that the {@link SkylarkModule} annotation for firstClass - firstModule - * is also an input parameter, because some top level Skylark built-in objects and methods * are not annotated on the class, but on a field referencing them. *//*w w w.ja va2s . c o m*/ @VisibleForTesting static void collectJavaObjects(SkylarkModule firstModule, Class<?> firstClass, Map<String, SkylarkModuleDoc> modules) { Set<Class<?>> done = new HashSet<>(); Deque<Class<?>> toProcess = new LinkedList<>(); Map<Class<?>, SkylarkModule> annotations = new HashMap<>(); toProcess.addLast(firstClass); annotations.put(firstClass, firstModule); while (!toProcess.isEmpty()) { Class<?> c = toProcess.removeFirst(); SkylarkModule annotation = annotations.get(c); done.add(c); if (!modules.containsKey(annotation.name())) { modules.put(annotation.name(), new SkylarkModuleDoc(annotation, c)); } SkylarkModuleDoc module = modules.get(annotation.name()); if (module.javaMethodsNotCollected()) { ImmutableMap<Method, SkylarkCallable> methods = FuncallExpression .collectSkylarkMethodsWithAnnotation(c); for (Map.Entry<Method, SkylarkCallable> entry : methods.entrySet()) { module.addMethod(new SkylarkJavaMethodDoc(module, entry.getKey(), entry.getValue())); } for (Map.Entry<Method, SkylarkCallable> method : methods.entrySet()) { Class<?> returnClass = method.getKey().getReturnType(); if (returnClass.isAnnotationPresent(SkylarkModule.class) && !done.contains(returnClass)) { toProcess.addLast(returnClass); annotations.put(returnClass, returnClass.getAnnotation(SkylarkModule.class)); } } } } }
From source file:com.facebook.buck.cxx.CxxFlags.java
public static ImmutableListMultimap<CxxSource.Type, String> getLanguageFlags(ImmutableList<String> flags, PatternMatchedCollection<ImmutableList<String>> platformFlags, ImmutableMap<CxxSource.Type, ImmutableList<String>> languageFlags, CxxPlatform platform) { ImmutableListMultimap.Builder<CxxSource.Type, String> langFlags = ImmutableListMultimap.builder(); langFlags.putAll(toLanguageFlags(getFlags(flags, platformFlags, platform))); for (ImmutableMap.Entry<CxxSource.Type, ImmutableList<String>> entry : languageFlags.entrySet()) { langFlags.putAll(entry.getKey(), Iterables.transform(entry.getValue(), getTranslateMacrosFn(platform))); }//from w w w . j a va 2 s . c o m return langFlags.build(); }
From source file:com.facebook.buck.cxx.NativeLinkables.java
/** * Collect all the shared libraries generated by {@link NativeLinkable}s found by transitively * traversing all unbroken dependency chains of {@link com.facebook.buck.cxx.NativeLinkable} * objects found via the passed in {@link com.facebook.buck.rules.BuildRule} roots. * * @return a mapping of library name to the library {@link SourcePath}. */// w w w .j ava 2s. c o m public static ImmutableSortedMap<String, SourcePath> getTransitiveSharedLibraries(CxxPlatform cxxPlatform, Iterable<? extends BuildRule> inputs, Predicate<Object> traverse, Predicate<Object> skip) throws NoSuchBuildTargetException { ImmutableMap<BuildTarget, NativeLinkable> roots = getNativeLinkableRoots(inputs, traverse, skip); ImmutableMap<BuildTarget, NativeLinkable> nativeLinkables = getTransitiveNativeLinkables(cxxPlatform, roots.values()); Map<String, SourcePath> libraries = new LinkedHashMap<>(); for (NativeLinkable nativeLinkable : nativeLinkables.values()) { NativeLinkable.Linkage linkage = nativeLinkable.getPreferredLinkage(cxxPlatform); if (linkage != NativeLinkable.Linkage.STATIC) { ImmutableMap<String, SourcePath> libs = nativeLinkable.getSharedLibraries(cxxPlatform); for (Map.Entry<String, SourcePath> lib : libs.entrySet()) { SourcePath prev = libraries.put(lib.getKey(), lib.getValue()); if (prev != null && !prev.equals(lib.getValue())) { throw new HumanReadableException("conflicting libraries for key %s: %s != %s", lib.getKey(), lib.getValue(), prev); } } } } return ImmutableSortedMap.copyOf(libraries); }
From source file:com.google.caliper.config.CaliperConfig.java
private static <T> ImmutableBiMap<String, Class<? extends T>> mapGroupNamesToClasses( ImmutableMap<String, String> groupProperties, Class<T> type) throws InvalidConfigurationException { BiMap<String, Class<? extends T>> namesToClasses = HashBiMap.create(); for (Entry<String, String> entry : groupProperties.entrySet()) { Matcher matcher = CLASS_PROPERTY_PATTERN.matcher(entry.getKey()); if (matcher.matches() && !entry.getValue().isEmpty()) { try { Class<?> someClass = Class.forName(entry.getValue()); checkState(type.isAssignableFrom(someClass)); @SuppressWarnings("unchecked") Class<? extends T> verifiedClass = (Class<? extends T>) someClass; namesToClasses.put(matcher.group(1), verifiedClass); } catch (ClassNotFoundException e) { throw new InvalidConfigurationException( "Cannot find result processor class: " + entry.getValue()); }//ww w.ja v a 2 s.c om } } return ImmutableBiMap.copyOf(namesToClasses); }
From source file:com.google.caliper.runner.config.CaliperConfig.java
private static <T> ImmutableBiMap<String, Class<? extends T>> mapGroupNamesToClasses( ImmutableMap<String, String> groupProperties, Class<T> type) throws InvalidConfigurationException { BiMap<String, Class<? extends T>> namesToClasses = HashBiMap.create(); for (Entry<String, String> entry : groupProperties.entrySet()) { Matcher matcher = CLASS_PROPERTY_PATTERN.matcher(entry.getKey()); if (matcher.matches() && !entry.getValue().isEmpty()) { try { Class<?> someClass = Util.loadClass(entry.getValue()); checkState(type.isAssignableFrom(someClass)); @SuppressWarnings("unchecked") Class<? extends T> verifiedClass = (Class<? extends T>) someClass; namesToClasses.put(matcher.group(1), verifiedClass); } catch (ClassNotFoundException e) { throw new InvalidConfigurationException( "Cannot find result processor class: " + entry.getValue()); }//from w ww.j a v a 2 s. co m } } return ImmutableBiMap.copyOf(namesToClasses); }
From source file:com.facebook.buck.lua.LuaUtil.java
public static ImmutableMap<String, SourcePath> toModuleMap(BuildTarget target, SourcePathResolver resolver, String parameter, String baseModule, Iterable<SourceList> inputs) { ImmutableMap.Builder<String, SourcePath> moduleNamesAndSourcePaths = ImmutableMap.builder(); for (SourceList input : inputs) { ImmutableMap<String, SourcePath> namesAndSourcePaths; if (input.getUnnamedSources().isPresent()) { namesAndSourcePaths = resolver.getSourcePathNames(target, parameter, input.getUnnamedSources().get()); } else {// w ww . j a va 2 s . c om namesAndSourcePaths = input.getNamedSources().get(); } for (ImmutableMap.Entry<String, SourcePath> entry : namesAndSourcePaths.entrySet()) { String name = entry.getKey(); if (!baseModule.isEmpty()) { name = baseModule + '/' + name; } moduleNamesAndSourcePaths.put(name, entry.getValue()); } } return moduleNamesAndSourcePaths.build(); }
From source file:google.registry.export.SyncGroupMembersAction.java
/** * Parses the results from Google Groups for each registrar, setting the dirty flag to false in * Datastore for the calls that succeeded and accumulating the errors for the calls that failed. *///from w w w. j av a 2 s .c om private static List<Throwable> getErrorsAndUpdateFlagsForSuccesses( ImmutableMap<Registrar, Optional<Throwable>> results) { final ImmutableList.Builder<Registrar> registrarsToSave = new ImmutableList.Builder<>(); List<Throwable> errors = new ArrayList<>(); for (Map.Entry<Registrar, Optional<Throwable>> result : results.entrySet()) { if (result.getValue().isPresent()) { errors.add(result.getValue().get()); } else { registrarsToSave.add(result.getKey().asBuilder().setContactsRequireSyncing(false).build()); } } ofy().transactNew(new VoidWork() { @Override public void vrun() { ofy().save().entities(registrarsToSave.build()); } }); return errors; }