List of usage examples for com.google.common.collect ImmutableMap get
V get(Object key);
From source file:org.jetbrains.jet.plugin.quickfix.MigrateTuplesInProjectFix.java
private void replaceTupleComponentCalls(JetFile file, final BindingContext context) { for (JetDeclaration declaration : file.getDeclarations()) { declaration.acceptChildren(new JetVisitorVoid() { @Override/* w ww. j ava2s . c o m*/ public void visitSimpleNameExpression(JetSimpleNameExpression expression) { DeclarationDescriptor referenceTarget = context.get(BindingContext.REFERENCE_TARGET, expression); if (referenceTarget == null) return; DeclarationDescriptor containingDeclaration = referenceTarget.getContainingDeclaration(); if (containingDeclaration == null) return; ImmutableSet<ClassDescriptor> supportedTupleClasses = ImmutableSet .of(KotlinBuiltIns.getInstance().getTuple(2), KotlinBuiltIns.getInstance().getTuple(3)); //noinspection SuspiciousMethodCalls if (!supportedTupleClasses.contains(containingDeclaration)) return; ImmutableMap<String, String> supportedComponents = ImmutableMap.<String, String>builder() .put("_1", "first").put("_2", "second").put("_3", "third").build(); String newName = supportedComponents.get(expression.getReferencedName()); if (newName == null) return; expression.replace(JetPsiFactory.createExpression(expression.getProject(), newName)); } @Override public void visitElement(PsiElement element) { element.acceptChildren(this); } }); } }
From source file:com.facebook.buck.halide.HalideBuckConfig.java
public String getHalideTargetForPlatform(CxxPlatform cxxPlatform) { String flavorName = cxxPlatform.getFlavor().toString(); ImmutableMap<String, String> targetMap = getHalideTargetMap(); if (!targetMap.containsKey(flavorName)) { throw new HumanReadableException("No halide target found for platform: '%s'\n" + "Add one in .buckconfig in the halide section.\n" + "\n" + "Example:\n" + "\n" + "[halide]" + "\n" + "target_%s = x86-64-osx-user_context", flavorName, flavorName); }// w w w. j ava2 s . c o m return targetMap.get(flavorName); }
From source file:com.facebook.buck.io.ExecutableFinder.java
private ImmutableSet<Path> getPaths(ImmutableMap<String, String> env) { ImmutableSet.Builder<Path> paths = ImmutableSet.builder(); // Add the empty path so that when we iterate over it, we can check for the suffixed version of // a given path, be it absolute or not. paths.add(Paths.get("")); String pathEnv = env.get("PATH"); if (pathEnv != null) { pathEnv = pathEnv.trim();/* w ww. ja va 2 s .co m*/ paths.addAll(StreamSupport .stream(Splitter.on(pathSeparator).omitEmptyStrings().split(pathEnv).spliterator(), false) .map(Paths::get).iterator()); } if (platform == Platform.MACOS) { Path osXPaths = Paths.get("/etc/paths"); if (Files.exists(osXPaths)) { try { paths.addAll(Files.readAllLines(osXPaths, Charset.defaultCharset()).stream().map(Paths::get) .iterator()); } catch (IOException e) { LOG.warn("Unable to read mac-specific paths. Skipping"); } } } return paths.build(); }
From source file:com.facebook.buck.cxx.CxxBinaryDescription.java
public ImmutableSortedSet<Flavor> addImplicitFlavorsForRuleTypes(ImmutableSortedSet<Flavor> argDefaultFlavors, BuildRuleType... types) {//ww w . ja va 2 s.co m Optional<Flavor> platformFlavor = getCxxPlatforms().getFlavor(argDefaultFlavors); for (BuildRuleType type : types) { ImmutableMap<String, Flavor> libraryDefaults = cxxBuckConfig.getDefaultFlavorsForRuleType(type); if (!platformFlavor.isPresent()) { platformFlavor = Optional.ofNullable(libraryDefaults.get(CxxBuckConfig.DEFAULT_FLAVOR_PLATFORM)); } } if (platformFlavor.isPresent()) { return ImmutableSortedSet.of(platformFlavor.get()); } else { // To avoid changing the output path of binaries built without a flavor, // we'll default to no flavor, which implicitly builds the default platform. return ImmutableSortedSet.of(); } }
From source file:org.estatio.dom.geography.Countries.java
@Programmatic public List<Country> countriesFor(final Iterable<String> countryCodes) { List<Country> available = Lists.newArrayList(); final ImmutableMap<String, Country> countryByCode = Maps.uniqueIndex(allCountries(), new Function<Country, String>() { @Override//from w ww . j av a2 s. c o m public String apply(final Country input) { return input.getName(); } }); for (String countryCodeForUser : countryCodes) { available.add(countryByCode.get(countryCodeForUser)); } return available; }
From source file:org.apache.beam.runners.dataflow.worker.BeamFnMapTaskExecutorFactory.java
/** Returns a map from PTransform id to side input reader. */ private static ImmutableMap<String, SideInputReader> buildPTransformIdToSideInputReadersMap( DataflowExecutionContext executionContext, RegisterRequestNode registerRequestNode, ImmutableMap<String, DataflowOperationContext> ptransformIdToOperationContexts) { ImmutableMap.Builder<String, SideInputReader> ptransformIdToSideInputReaders = ImmutableMap.builder(); for (Map.Entry<String, Iterable<PCollectionView<?>>> ptransformIdToPCollectionView : registerRequestNode .getPTransformIdToPCollectionViewMap().entrySet()) { try {// w ww . j av a2 s. co m ptransformIdToSideInputReaders.put(ptransformIdToPCollectionView.getKey(), executionContext.getSideInputReader( // Note that the side input infos will only be populated for a batch pipeline registerRequestNode.getPTransformIdToSideInputInfoMap() .get(ptransformIdToPCollectionView.getKey()), ptransformIdToPCollectionView.getValue(), ptransformIdToOperationContexts.get(ptransformIdToPCollectionView.getKey()))); } catch (Exception e) { throw Throwables.propagate(e); } } return ptransformIdToSideInputReaders.build(); }
From source file:com.qcadoo.mes.productionPerShift.dates.ProgressDatesService.java
private void setupDatesFor(final Collection<Entity> progressesForDays, final OrderDates orderDates) { ImmutableMap<ProgressType, RealizationDays> realizationDays = resolveRealizationDaysFor(orderDates, progressesForDays);//ww w . j a v a 2 s. c om for (Entity progressForDay : progressesForDays) { DayAndDates dayAndDates = realizationDays.get(ProgressType.of(progressForDay)) .getDatesFor(progressForDay); setUpProgressForDayEntity(progressForDay, dayAndDates); progressForDay.getDataDefinition().save(progressForDay); } }
From source file:com.facebook.buck.distributed.DistributedBuildTargetGraphCodec.java
public TargetGraph createTargetGraph(BuildJobStateTargetGraph remoteTargetGraph) throws IOException, InterruptedException { ImmutableMap.Builder<Integer, Cell> cellBuilder = ImmutableMap.builder(); // TODO(marcinkosiba): Sort out the story around Cells. for (Map.Entry<Integer, String> remoteFileSystemRoot : remoteTargetGraph.getFileSystemRoots().entrySet()) { Path remoteFilesystemRoot = Files.createTempDirectory( rootFilesystem.resolve(rootFilesystem.getBuckPaths().getBuckOut()), "remote_"); ProjectFilesystem projectFilesystem = new ProjectFilesystem(remoteFilesystemRoot); Cell cell = rootCell.createCellForDistributedBuild(console, clock, projectFilesystem, rootCell.getBuckConfig()); cellBuilder.put(remoteFileSystemRoot.getKey(), cell); }/* w w w . ja v a 2s . co m*/ ImmutableMap<Integer, Cell> cells = cellBuilder.build(); ImmutableMap.Builder<BuildTarget, TargetNode<?>> targetNodeIndexBuilder = ImmutableMap.builder(); for (BuildJobStateTargetNode remoteNode : remoteTargetGraph.getNodes()) { Cell cell = Preconditions.checkNotNull(cells.get(remoteNode.getFileSystemRootIndex())); ProjectFilesystem projectFilesystem = cell.getFilesystem(); BuildTarget target = decodeBuildTarget(remoteNode.getBuildTarget(), cell); @SuppressWarnings("unchecked") Map<String, Object> rawNode = objectMapper.readValue(remoteNode.getRawNode(), Map.class); Path buildFilePath = projectFilesystem.resolve(target.getBasePath()).resolve(cell.getBuildFileName()); TargetNode<?> targetNode = parserTargetNodeFactory.createTargetNode(cell, buildFilePath, target, rawNode); targetNodeIndexBuilder.put(targetNode.getBuildTarget(), targetNode); } ImmutableMap<BuildTarget, TargetNode<?>> targetNodeIndex = targetNodeIndexBuilder.build(); MutableDirectedGraph<TargetNode<?>> mutableTargetGraph = new MutableDirectedGraph<>(); for (TargetNode<?> targetNode : targetNodeIndex.values()) { mutableTargetGraph.addNode(targetNode); for (BuildTarget dep : targetNode.getDeps()) { mutableTargetGraph.addEdge(targetNode, Preconditions.checkNotNull(targetNodeIndex.get(dep))); } } return new TargetGraph(mutableTargetGraph, targetNodeIndex); }
From source file:com.clearclouds.driver.monitor.jvm.DeadlockAnalyzer.java
private Set<LinkedHashSet<ThreadInfo>> calculateCycles(ImmutableMap<Long, ThreadInfo> threadInfoMap) { Set<LinkedHashSet<ThreadInfo>> cycles = new HashSet<>(); for (Map.Entry<Long, ThreadInfo> entry : threadInfoMap.entrySet()) { LinkedHashSet<ThreadInfo> cycle = new LinkedHashSet<>(); for (ThreadInfo t = entry.getValue(); !cycle.contains(t); t = threadInfoMap .get(Long.valueOf(t.getLockOwnerId()))) cycle.add(t);/* ww w. j a va2 s . c om*/ if (!cycles.contains(cycle)) cycles.add(cycle); } return cycles; }
From source file:com.google.devtools.build.lib.rules.android.DexArchiveProvider.java
public Function<Artifact, Artifact> archivesForDexopts(ImmutableSet<String> dexopts) { final ImmutableMap<Artifact, Artifact> dexArchivesForDexopts = dexArchives.row(dexopts); return new Function<Artifact, Artifact>() { /** Maps Jars to available dex archives and returns the given Jar otherwise. */ @Override/* w ww. j a va2s. c o m*/ @Nullable public Artifact apply(@Nullable Artifact jar) { Artifact dexArchive = dexArchivesForDexopts.get(jar); return dexArchive != null ? dexArchive : jar; // return null iff input == null } }; }