List of usage examples for com.google.common.collect ImmutableMap get
V get(Object key);
From source file:dagger.internal.codegen.ProducerFactoryGenerator.java
/** Returns a list of dependencies that are generated asynchronously. */ private static ImmutableList<DependencyRequest> asyncDependencies(Binding binding) { final ImmutableMap<DependencyRequest, FrameworkDependency> frameworkDependencies = binding .dependenciesToFrameworkDependenciesMap(); return FluentIterable.from(binding.dependencies()).filter(dependency -> isAsyncDependency(dependency) && frameworkDependencies.get(dependency).frameworkClass().equals(Producer.class)).toList(); }
From source file:com.bigfatgun.fixjures.Strategies.java
/** * This source strategy does a simple lookup of type and name in a map that stores fixture data in raw byte arrays. A * defensive copy is made of the map argument, so only the fixtures in the map at the time this method is invoked can * be created.//from ww w. ja va 2s . c o m * * @param mem map that holds fixture data in memory * @return new source strategy */ public static SourceStrategy newInMemoryStrategy(final Map<? extends Class<?>, Map<String, String>> mem) { final ImmutableMap<Class<?>, Map<String, String>> copy = ImmutableMap.copyOf(mem); return new SourceStrategy() { public ReadableByteChannel findStream(final Class<?> type, final String name) throws IOException { assert type != null : "Type cannot be null."; assert name != null : "Name cannot be null."; if (!copy.containsKey(type)) { throw new IOException("Data for " + type + " not found."); } else if (!copy.get(type).containsKey(name)) { throw new IOException("Data for " + type.getName() + " named " + name + " not found."); } else { final byte[] bytes = copy.get(type).get(name).getBytes(Charsets.UTF_8); return Channels.newChannel(new ByteArrayInputStream(bytes)); } } }; }
From source file:com.facebook.buck.jvm.java.DefaultClassUsageFileReader.java
public static ImmutableList<SourcePath> loadFromFile(ProjectFilesystem projectFilesystem, Path classUsageFilePath, ImmutableSortedSet<BuildRule> deps) { final ImmutableMap<Path, SourcePath> jarAbsolutePathToAbiJarSourcePath = buildJarToAbiJarMap(deps); final ImmutableList.Builder<SourcePath> builder = ImmutableList.builder(); try {// ww w.java 2s .c om final ImmutableSet<Map.Entry<String, ImmutableList<String>>> classUsageEntries = loadClassUsageMap( classUsageFilePath).entrySet(); for (Map.Entry<String, ImmutableList<String>> jarUsedClassesEntry : classUsageEntries) { Path jarAbsolutePath = projectFilesystem.resolve(Paths.get(jarUsedClassesEntry.getKey())); SourcePath abiJarSourcePath = jarAbsolutePathToAbiJarSourcePath.get(jarAbsolutePath); if (abiJarSourcePath == null) { // This indicates a dependency that wasn't among the deps of the rule; i.e., // it came from the build environment (JDK, Android SDK, etc.) continue; } ImmutableList<String> classAbsolutePaths = jarUsedClassesEntry.getValue(); for (String classAbsolutePath : classAbsolutePaths) { builder.add(new ArchiveMemberSourcePath(abiJarSourcePath, Paths.get(classAbsolutePath))); } } } catch (IOException e) { throw new HumanReadableException(e, "Failed to load class usage files from %s:\n%s", classUsageFilePath, e.getLocalizedMessage()); } return builder.build(); }
From source file:com.google.polymer.JsRenamer.java
/** * Forwards renames to Polymer-relevant properties in the specified object map. * @param renameMap A mapping from symbol to renamed symbol. * @param objectMap A map of keys as property string names to values as nodes. *//*from w ww . j a v a 2 s . co m*/ private static void renameObjectMap(ImmutableMap<String, String> renameMap, ImmutableMap<String, Node> objectMap) { // Rename 'computed' and 'observer' property description references. Node propertiesNode = objectMap.get("properties"); if ((propertiesNode != null) && propertiesNode.isObjectLit()) { ImmutableMap<String, Node> propertiesMap = convertObjectLitNodeToMap(propertiesNode); for (Node propertyDescriptorNode : propertiesMap.values()) { if (propertyDescriptorNode.isObjectLit()) { ImmutableMap<String, Node> propertyDescriptorMap = convertObjectLitNodeToMap( propertyDescriptorNode); renamePolymerJsStringNode(renameMap, propertyDescriptorMap.get("computed")); renamePolymerJsStringNode(renameMap, propertyDescriptorMap.get("observer")); } } } // Rename all JavaScript-like expressions in the 'observers' array. Node observersNode = objectMap.get("observers"); if ((observersNode != null) && observersNode.isArrayLit()) { for (Node observerItem : observersNode.children()) { renamePolymerJsStringNode(renameMap, observerItem); } } // Rename all JavaScript-like expressions in the listeners descriptor. Node listenersNode = objectMap.get("listeners"); if ((listenersNode != null) && listenersNode.isObjectLit()) { ImmutableMap<String, Node> listenersMap = convertObjectLitNodeToMap(listenersNode); for (Node listenerDescriptorNode : listenersMap.values()) { renamePolymerJsStringNode(renameMap, listenerDescriptorNode); } } // Rename the keyBindings string to method string map using in Polymer.IronA11yKeysBehavior. Node keyBindingsNode = objectMap.get("keyBindings"); if ((keyBindingsNode != null) && keyBindingsNode.isObjectLit()) { renameKeyBindingsNode(renameMap, keyBindingsNode); } if (renameMap.containsKey("keyBindings")) { Node renamedKeyBindingsNode = objectMap.get(renameMap.get("keyBindings")); if ((renamedKeyBindingsNode != null) && renamedKeyBindingsNode.isObjectLit()) { renameKeyBindingsNode(renameMap, renamedKeyBindingsNode); } } }
From source file:grakn.core.graql.gremlin.TraversalPlanner.java
private static Arborescence<Node> computeArborescence(Set<Fragment> connectedFragments, ImmutableMap<NodeId, Node> nodes, TransactionOLTP tx) { final Map<Node, Double> nodesWithFixedCost = new HashMap<>(); connectedFragments.forEach(fragment -> { if (fragment.hasFixedFragmentCost()) { NodeId startNodeId = Iterators.getOnlyElement(fragment.getNodes().iterator()).getNodeId(); Node startNode = nodes.get(startNodeId); nodesWithFixedCost.put(startNode, getLogInstanceCount(tx, fragment)); startNode.setFixedFragmentCost(fragment.fragmentCost()); }// www .ja va 2s . c om }); // update cost of reaching subtypes from an indexed supertyp updateFixedCostSubsReachableByIndex(nodes, nodesWithFixedCost, connectedFragments); // fragments that represent Janus edges final Set<Fragment> edgeFragmentSet = new HashSet<>(); // save the fragments corresponding to edges, and updates some costs if we can via shard count for (Fragment fragment : connectedFragments) { if (fragment.end() != null) { edgeFragmentSet.add(fragment); // update the cost of an `InIsa` Fragment if we have some estimated cost if (fragment instanceof InIsaFragment) { Node type = nodes.get(NodeId.of(NodeId.Type.VAR, fragment.start())); if (nodesWithFixedCost.containsKey(type) && nodesWithFixedCost.get(type) > 0) { fragment.setAccurateFragmentCost(nodesWithFixedCost.get(type)); } } } } // convert fragments to a connected graph Set<Weighted<DirectedEdge>> weightedGraph = buildWeightedGraph(nodes, edgeFragmentSet); if (!weightedGraph.isEmpty()) { // sparse graph for better performance SparseWeightedGraph sparseWeightedGraph = SparseWeightedGraph.from(weightedGraph); Set<Node> startingNodes = chooseStartingNodeSet(connectedFragments, nodes, sparseWeightedGraph, tx); // find the minimum spanning tree for each root // then get the tree with minimum weight Arborescence<Node> arborescence = startingNodes.stream() .map(node -> ChuLiuEdmonds.getMaxArborescence(sparseWeightedGraph, node)) .max(Comparator.comparingDouble(tree -> tree.weight)) .map(arborescenceInside -> arborescenceInside.val).orElse(Arborescence.empty()); return arborescence; } else { return null; } }
From source file:com.google.polymer.HtmlRenamer.java
private static void renameAllAttributeKeys(ImmutableMap<String, String> renameMap, Element element) { Attributes attributes = element.attributes(); for (Attribute attribute : attributes) { String key = attribute.getKey(); // Polymer events are referenced as strings. As a result they do not participate in renaming. // Additionally, it is not valid to have a Polymer property start with "on". if (!key.startsWith("on-")) { String renamedProperty = renameMap.get(CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, key)); if (renamedProperty != null) { attribute.setKey(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, renamedProperty)); }/*from ww w . j a v a2 s.c om*/ } } }
From source file:com.google.idea.blaze.base.sync.projectstructure.ContentEntryEditor.java
public static void createContentEntries(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, ModifiableRootModel modifiableRootModel) { ImportRoots importRoots = ImportRoots.builder(workspaceRoot, Blaze.getBuildSystem(project)) .add(projectViewSet).build(); Collection<WorkspacePath> rootDirectories = importRoots.rootDirectories(); Collection<WorkspacePath> excludeDirectories = importRoots.excludeDirectories(); Multimap<WorkspacePath, WorkspacePath> excludesByRootDirectory = sortExcludesByRootDirectory( rootDirectories, excludeDirectories); SourceTestConfig testConfig = new SourceTestConfig(projectViewSet); SourceFolderProvider provider = SourceFolderProvider.getSourceFolderProvider(blazeProjectData); List<ContentEntry> contentEntries = Lists.newArrayList(); for (WorkspacePath rootDirectory : rootDirectories) { File root = workspaceRoot.fileForPath(rootDirectory); ContentEntry contentEntry = modifiableRootModel.addContentEntry(pathToUrl(root.getPath())); contentEntries.add(contentEntry); for (WorkspacePath exclude : excludesByRootDirectory.get(rootDirectory)) { File excludeFolder = workspaceRoot.fileForPath(exclude); contentEntry.addExcludeFolder(pathToIdeaUrl(excludeFolder)); }// w w w .j a v a 2 s. c om ImmutableMap<VirtualFile, SourceFolder> sourceFolders = provider.initializeSourceFolders(contentEntry); VirtualFile rootFile = getVirtualFile(root); if (rootFile == null) { IssueOutput .warn(String.format("Could not find directory %s. Your 'test_sources' project view " + "attribute will not have any effect. Please resync.", workspaceRoot)) .submit(context); continue; } SourceFolder rootSource = sourceFolders.get(rootFile); walkFileSystem(workspaceRoot, testConfig, excludesByRootDirectory.get(rootDirectory), contentEntry, provider, sourceFolders, rootSource, rootFile); } }
From source file:com.facebook.buck.features.project.intellij.IjModuleGraphFactory.java
private static ImmutableSet<IjProjectElement> getProjectElementFromBuildTargets(TargetGraph targetGraph, IjLibraryFactory libraryFactory, ImmutableMap<BuildTarget, IjModule> rulesToModules, IjModule module, Stream<BuildTarget> buildTargetStream) { return buildTargetStream.filter(input -> { // The exported deps closure can contain references back to targets contained // in the module, so filter those out. return !module.getTargets().contains(input); }).flatMap(depTarget -> {//from w ww .ja v a 2s . co m List<IjProjectElement> elements = new ArrayList<>(); IjModule depModule = rulesToModules.get(depTarget); if (depModule != null) { elements.add(depModule); } if (depModule == null || depModule.getNonSourceBuildTargets().contains(depTarget)) { // all BuildTarget's are merged into IJModule // if a BuildTarget is not built from Java sources, it will also be added as a // library TargetNode<?> targetNode = targetGraph.get(depTarget); elements.add(libraryFactory.getLibrary(targetNode).orElse(null)); } return elements.stream(); }).filter(Objects::nonNull).collect(ImmutableSet.toImmutableSet()); }
From source file:dagger.internal.codegen.Util.java
private static CodeBlock createCodeBlock(DependencyRequest request, ImmutableMap<BindingKey, FrameworkField> map) { FrameworkField field = map.get(request.bindingKey()); TypeName type = request.kind() == DependencyRequest.Kind.INSTANCE ? field.type().typeArguments.get(0) : field.type();//from ww w . j a va2 s . c om return CodeBlock.of("$T $L", type, field.name()); }
From source file:com.facebook.buck.core.cell.impl.DistributedCellProviderFactory.java
public static CellProvider create(DistBuildCellParams rootCell, ImmutableMap<Path, DistBuildCellParams> cellParams) { Map<String, Path> cellPaths = cellParams.values().stream().filter(p -> p.getCanonicalName().isPresent()) .collect(Collectors.toMap(p -> p.getCanonicalName().get(), p -> p.getFilesystem().getRootPath())); ImmutableSet<String> declaredCellNames = ImmutableSet.copyOf(cellPaths.keySet()); Path rootCellPath = rootCell.getFilesystem().getRootPath(); DefaultCellPathResolver rootCellResolver = DefaultCellPathResolver.of(rootCellPath, cellPaths); return new CellProvider(cellProvider -> CacheLoader.from(cellPath -> { DistBuildCellParams cellParam = Preconditions.checkNotNull(cellParams.get(cellPath), "This should only be called for secondary cells."); Path currentCellRoot = cellParam.getFilesystem().getRootPath(); Preconditions.checkState(!currentCellRoot.equals(rootCellPath)); CellPathResolver currentCellResolver = rootCellResolver; // The CellPathResolverView is required because it makes the // [RootPath<->CanonicalName] resolver methods non-symmetrical to handle the // fact//from w w w . ja v a 2s .co m // that relative main cell from inside a secondary cell resolves actually to // secondary cell. If the DefaultCellPathResolver is used, then it would return // a BuildTarget as if it belonged to the main cell. currentCellResolver = new CellPathResolverView(rootCellResolver, declaredCellNames, currentCellRoot); BuckConfig configWithResolver = cellParam.getConfig().withCellPathResolver(currentCellResolver); RuleKeyConfiguration ruleKeyConfiguration = ConfigRuleKeyConfigurationFactory.create(configWithResolver, cellParam.getBuckModuleManager()); ToolchainProvider toolchainProvider = new DefaultToolchainProvider(cellParam.getPluginManager(), cellParam.getEnvironment(), configWithResolver, cellParam.getFilesystem(), cellParam.getProcessExecutor(), cellParam.getExecutableFinder(), ruleKeyConfiguration); return ImmutableCell.of(cellParams.keySet(), // Distributed builds don't care about cell names, use a sentinel value that // will show up if it actually does care about them. cellParam.getCanonicalName(), WatchmanFactory.NULL_WATCHMAN, cellProvider, toolchainProvider, ruleKeyConfiguration, cellParam.getFilesystem(), configWithResolver); }), cellProvider -> RootCellFactory.create(cellProvider, rootCellResolver, rootCell.getFilesystem(), rootCell.getBuckModuleManager(), rootCell.getPluginManager(), rootCell.getConfig(), rootCell.getEnvironment(), rootCell.getProcessExecutor(), rootCell.getExecutableFinder(), WatchmanFactory.NULL_WATCHMAN)); }