List of usage examples for com.google.common.base Functions forMap
public static <K, V> Function<K, V> forMap(Map<K, ? extends V> map, @Nullable V defaultValue)
From source file:com.google.cloud.dataflow.sdk.util.CombiningOutputBuffer.java
@Override public OutputT extract(OutputBuffer.Context<K, W> c) throws IOException { Iterable<AccumT> accums = FluentIterable.from(c.sourceWindows()) .transform(Functions.forMap(inMemoryBuffer, null)).filter(Predicates.notNull()) .append(c.readBuffers(accumTag, c.sourceWindows())); AccumT result = Iterables.isEmpty(accums) ? null : combineFn.mergeAccumulators(c.key(), accums); clear(c);//from www .j a va 2 s . c o m inMemoryBuffer.put(c.window(), result); return result == null ? null : combineFn.extractOutput(c.key(), result); }
From source file:org.caleydo.vis.lineup.model.MultiCategoricalRankColumnModel.java
public MultiCategoricalRankColumnModel(IGLRenderer header, final Function<IRow, Set<CATEGORY_TYPE>> data, Map<CATEGORY_TYPE, String> metaData, Color color, Color bgColor, String labelNA) { this(header, data, Functions.forMap(metaData, null), metaData.keySet(), color, bgColor, labelNA); }
From source file:com.isotrol.impe3.idx.DefaultNodeRepositoriesService.java
public DefaultNodeRepositoriesService(@Nullable List<SinglePortalQueryable> singles, @Nullable List<AggregatedPortalQueryable> aggregated) { if (singles == null) { singles = ImmutableList.of();//from ww w . j av a 2s . co m } if (aggregated == null) { aggregated = ImmutableList.of(); } if (singles.isEmpty() && aggregated.isEmpty()) { this.repositories = ImmutableMap.of(); this.descriptions = ImmutableMap.of(); this.repoF = new Function<String, NodeRepository>() { public NodeRepository apply(String input) { return EMPTY; } }; } else { final Map<String, NodeRepository> map = Maps.newHashMap(); final Map<String, String> desc = Maps.newHashMap(); for (SinglePortalQueryable indexer : singles) { checkNotNull(indexer, "Null single indexer provided"); final String name = indexer.getName(); checkNotNull(name, "Null single indexer name provided"); checkArgument(!map.containsKey(name), "Duplicate indexer [%s]", name); final NodeRepository nr = new NodeRepositoryImpl(indexer.getQueryable()); map.put(name, nr); desc.put(name, indexer.getDescription()); } for (AggregatedPortalQueryable indexer : aggregated) { checkNotNull(indexer, "Null aggregated indexer provided"); final String name = indexer.getName(); checkNotNull(name, "Null aggregated indexer name provided"); checkArgument(!map.containsKey(name), "Duplicate indexer [%s]", name); final NodeRepository nr = new NodeRepositoryImpl(indexer.getQueryable()); map.put(name, nr); desc.put(name, indexer.getDescription()); } this.repositories = ImmutableMap.copyOf(map); this.descriptions = ImmutableMap.copyOf(desc); this.repoF = Functions.forMap(repositories, EMPTY); } }
From source file:com.android.tools.idea.wizard.ModuleListModel.java
private Multimap<ModuleToImport, ModuleToImport> computeRequiredModules(Set<ModuleToImport> modules) { Map<String, ModuleToImport> namesToModules = Maps.newHashMapWithExpectedSize(modules.size()); // We only care about modules we are actually going to import. for (ModuleToImport module : modules) { namesToModules.put(module.name, module); }/*ww w. j a v a 2 s.c om*/ Multimap<ModuleToImport, ModuleToImport> requiredModules = LinkedListMultimap.create(); Queue<ModuleToImport> queue = Lists.newLinkedList(); for (ModuleToImport module : modules) { if (Objects.equal(module, myPrimaryModule) || !isUnselected(module, false)) { queue.add(module); } } while (!queue.isEmpty()) { ModuleToImport moduleToImport = queue.remove(); for (ModuleToImport dep : Iterables.transform(moduleToImport.getDependencies(), Functions.forMap(namesToModules, null))) { if (dep != null) { if (!requiredModules.containsKey(dep)) { queue.add(dep); } requiredModules.put(dep, moduleToImport); } } } return requiredModules; }
From source file:com.isotrol.impe3.pms.core.obj.DevicePagesObject.java
private Iterable<PageObject> exportedTemplates(Iterable<PageObject> pages) throws PMSException { final List<PageObject> templates = Lists.newArrayList(pages); if (templates.size() > 1) { final Map<PageObject, Integer> om = calculateTplLevel(ImmutableSet.copyOf(templates), templates.get(0), Maps.<PageObject, Integer>newHashMap()); Collections.sort(templates, Ordering.natural().onResultOf(Functions.forMap(om, 0))); }/*from w w w . j a va2 s . c o m*/ return templates; }
From source file:org.apache.kylin.query.util.ConvertToComputedColumn.java
static ImmutableSortedMap<String, String> getMapSortedByValue(Map<String, String> computedColumns) { if (computedColumns == null || computedColumns.isEmpty()) { return null; }// www . j a v a 2s .c o m Ordering<String> ordering = Ordering.from(new Comparator<String>() { @Override public int compare(String o1, String o2) { return Integer.compare(o1.replaceAll("\\s*", "").length(), o2.replaceAll("\\s*", "").length()); } }).reverse().nullsLast().onResultOf(Functions.forMap(computedColumns, null)).compound(Ordering.natural()); return ImmutableSortedMap.copyOf(computedColumns, ordering); }
From source file:org.sosy_lab.cpachecker.cpa.arg.ARGStatistics.java
private void exportARG(final ARGState rootState, final Predicate<Pair<ARGState, ARGState>> isTargetPathEdge) { SetMultimap<ARGState, ARGState> relevantSuccessorRelation = ARGUtils.projectARG(rootState, ARGUtils.CHILDREN_OF_STATE, ARGUtils.RELEVANT_STATE); Function<ARGState, Collection<ARGState>> relevantSuccessorFunction = Functions .forMap(relevantSuccessorRelation.asMap(), ImmutableSet.<ARGState>of()); if (argFile != null) { try (Writer w = Files.openOutputFile(argFile)) { ARGToDotWriter.write(w, rootState, ARGUtils.CHILDREN_OF_STATE, Predicates.alwaysTrue(), isTargetPathEdge);/*from ww w. j a va 2s . c om*/ } catch (IOException e) { cpa.getLogger().logUserException(Level.WARNING, e, "Could not write ARG to file"); } } if (simplifiedArgFile != null) { try (Writer w = Files.openOutputFile(simplifiedArgFile)) { ARGToDotWriter.write(w, rootState, relevantSuccessorFunction, Predicates.alwaysTrue(), Predicates.alwaysFalse()); } catch (IOException e) { cpa.getLogger().logUserException(Level.WARNING, e, "Could not write ARG to file"); } } assert (refinementGraphUnderlyingWriter == null) == (refinementGraphWriter == null); if (refinementGraphUnderlyingWriter != null) { try (Writer w = refinementGraphUnderlyingWriter) { // for auto-closing refinementGraphWriter.writeSubgraph(rootState, relevantSuccessorFunction, Predicates.alwaysTrue(), Predicates.alwaysFalse()); refinementGraphWriter.finish(); } catch (IOException e) { cpa.getLogger().logUserException(Level.WARNING, e, "Could not write refinement graph to file"); } } }
From source file:com.google.devtools.build.lib.rules.cpp.CppCompileActionBuilder.java
private Iterable<IncludeScannable> getLipoScannables(NestedSet<Artifact> realMandatoryInputs) { return lipoScannableMap == null ? ImmutableList.<IncludeScannable>of() : Iterables.filter(Iterables.transform( Iterables.filter(/*from w w w .j av a 2s .com*/ FileType.filter(realMandatoryInputs, CppFileTypes.C_SOURCE, CppFileTypes.CPP_SOURCE, CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR), Predicates.not(Predicates.equalTo(getSourceFile()))), Functions.forMap(lipoScannableMap, null)), Predicates.notNull()); }
From source file:org.apache.aurora.scheduler.storage.mem.MemTaskStore.java
private Iterable<Task> fromIdIndex(Iterable<String> taskIds) { return FluentIterable.from(taskIds).transform(Functions.forMap(tasks, null)).filter(Predicates.notNull()) .toList();/*from w w w. j a v a2s .c om*/ }
From source file:edu.buaa.satla.analysis.core.arg.ARGReachedSet.java
private void dumpSubgraph(ARGState e) { if (cpa == null) { return;/*ww w. jav a 2s .c o m*/ } ARGToDotWriter refinementGraph = cpa.getRefinementGraphWriter(); if (refinementGraph == null) { return; } SetMultimap<ARGState, ARGState> successors = ARGUtils.projectARG(e, ARGUtils.CHILDREN_OF_STATE, ARGUtils.RELEVANT_STATE); SetMultimap<ARGState, ARGState> predecessors = ARGUtils.projectARG(e, ARGUtils.PARENTS_OF_STATE, ARGUtils.RELEVANT_STATE); try { refinementGraph.enterSubgraph("cluster_" + refinementNumber, "Refinement " + refinementNumber); refinementGraph.writeSubgraph(e, Functions.forMap(successors.asMap(), ImmutableSet.<ARGState>of()), Predicates.alwaysTrue(), Predicates.alwaysFalse()); refinementGraph.leaveSubgraph(); for (ARGState predecessor : predecessors.get(e)) { // insert edge from predecessor to e in global graph refinementGraph.writeEdge(predecessor, e); } } catch (IOException ex) { cpa.getLogger().logUserException(Level.WARNING, ex, "Could not write refinement graph to file"); } }