List of usage examples for com.google.common.collect Multimap keySet
Set<K> keySet();
From source file:org.jboss.gwt.circuit.sample.calculator.views.StatsView.java
public StatsView(final CalculatorStore store) { store.addChangeHandler(new PropagatesChange.Handler() { @Override/*from w w w. j a v a 2 s. c o m*/ public void onChange(final Action action) { Multimap<Op, Term> termsByOp = LinkedListMultimap.create(); Set<Term> terms = store.getResults().keySet(); for (Term term : terms) { termsByOp.put(term.getOp(), term); } StringBuilder message = new StringBuilder(); Set<Op> keys = termsByOp.keySet(); for (Iterator<Op> iterator = keys.iterator(); iterator.hasNext();) { Op key = iterator.next(); message.append(key.name()).append("(").append(termsByOp.get(key).size()).append(")"); if (iterator.hasNext()) { message.append(", "); } } System.out.printf("Operation stats: %s\n", message); } }); }
From source file:com.bigdata.dastor.dht.BootStrapper.java
/** get potential sources for each range, ordered by proximity (as determined by EndPointSnitch) */ Multimap<Range, InetAddress> getRangesWithSources(String table) { assert tokenMetadata.sortedTokens().size() > 0; final AbstractReplicationStrategy strat = StorageService.instance.getReplicationStrategy(table); Collection<Range> myRanges = strat.getPendingAddressRanges(tokenMetadata, token, address, table); Multimap<Range, InetAddress> myRangeAddresses = ArrayListMultimap.create(); Multimap<Range, InetAddress> rangeAddresses = strat.getRangeAddresses(tokenMetadata, table); for (Range myRange : myRanges) { for (Range range : rangeAddresses.keySet()) { if (range.contains(myRange)) { List<InetAddress> preferred = DatabaseDescriptor.getEndPointSnitch(table) .getSortedListByProximity(address, rangeAddresses.get(range)); myRangeAddresses.putAll(myRange, preferred); break; }/*from ww w . ja va 2 s.c om*/ } assert myRangeAddresses.keySet().contains(myRange); } return myRangeAddresses; }
From source file:com.synflow.cx.ui.internal.views.fsm.layout.EdgeLayout.java
private void layoutDoubleEdges(List<State> states) { for (State state : states) { Multimap<State, Transition> map = HashMultimap.create(); for (Edge edge : state.getOutgoing()) { map.put((State) edge.getTarget(), (Transition) edge); }/* w w w .j a v a2 s .co m*/ for (State target : map.keySet()) { Collection<Transition> transitions = map.get(target); if (transitions.size() >= 2) { Point l1 = state.get("location"); Point l2 = target.get("location"); int inc = BREADTH / (transitions.size() - 1); int x = (l1.x + l2.x) / 2 - BREADTH / 2 + 15; final int y = (l1.y + l2.y + 20) / 2; for (Transition transition : transitions) { List<Bendpoint> bendpoints = new ArrayList<>(); AbsoluteBendpoint bp; bp = new AbsoluteBendpoint(x, y - 5); bendpoints.add(bp); bp = new AbsoluteBendpoint(x, y + 5); bendpoints.add(bp); setBendpoints(transition, bendpoints); x += inc; } } } } }
From source file:fr.ujm.tse.lt2c.satin.rules.run.RunPRP_RNG.java
@Override protected int process(final TripleStore ts1, final TripleStore ts2, final Collection<Triple> outputTriples) { final long range = AbstractDictionary.range; final long type = AbstractDictionary.type; final int loops = 0; final Multimap<Long, Long> rangeMultiMap = ts1.getMultiMapForPredicate(range); if (rangeMultiMap != null && !rangeMultiMap.isEmpty()) { final HashMap<Long, Collection<Triple>> cachePredicates = new HashMap<>(); for (final Long p : rangeMultiMap.keySet()) { Collection<Triple> matchingTriples; if (!cachePredicates.containsKey(p)) { matchingTriples = ts2.getbyPredicate(p); cachePredicates.put(p, matchingTriples); } else { matchingTriples = cachePredicates.get(p); }//ww w . ja va 2 s . c o m for (final Triple triple : matchingTriples) { for (final Long c : rangeMultiMap.get(p)) { if (triple.getObject() >= 0) { final Triple result = new ImmutableTriple(triple.getObject(), type, c); outputTriples.add(result); } } } } } return loops; }
From source file:com.android.tools.idea.gradle.variant.view.ModuleVariantsInfoDialog.java
@NotNull private static JTree createDependenciesTree(@NotNull Module module, @NotNull AndroidModuleModel androidModel) { VariantCheckboxTreeCellRenderer renderer = new VariantCheckboxTreeCellRenderer() { @Override// ww w. ja va2 s . c o m public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value instanceof DefaultMutableTreeNode) { Object data = ((DefaultMutableTreeNode) value).getUserObject(); if (data instanceof String) { appendVariant((String) data); } else if (data instanceof DependencyTreeElement) { DependencyTreeElement dependency = (DependencyTreeElement) data; appendModule(dependency.myModule, dependency.myVariant); } } } }; //noinspection ConstantConditions CheckedTreeNode root = new CheckedTreeNode(null); AndroidProject androidProject = GradleUtil.getAndroidProject(module); assert androidProject != null; Multimap<String, DependencyTreeElement> dependenciesByVariant = HashMultimap.create(); for (Variant variant : androidProject.getVariants()) { for (AndroidLibrary library : GradleUtil.getDirectLibraryDependencies(variant, androidModel)) { String gradlePath = library.getProject(); if (gradlePath == null) { continue; } Module dependency = GradleUtil.findModuleByGradlePath(module.getProject(), gradlePath); if (dependency != null) { DependencyTreeElement element = new DependencyTreeElement(dependency, library.getProjectVariant()); dependenciesByVariant.put(variant.getName(), element); } } } // Consolidate variants. This means if "debug" and "release" have the same dependencies, we show only one node as "debug, release". List<String> variantNames = Lists.newArrayList(dependenciesByVariant.keySet()); Collections.sort(variantNames); List<String> consolidatedVariants = Lists.newArrayList(); List<String> variantsToSkip = Lists.newArrayList(); int variantCount = variantNames.size(); for (int i = 0; i < variantCount; i++) { String variant1 = variantNames.get(i); if (variantsToSkip.contains(variant1)) { continue; } Collection<DependencyTreeElement> set1 = dependenciesByVariant.get(variant1); for (int j = i + 1; j < variantCount; j++) { String variant2 = variantNames.get(j); Collection<DependencyTreeElement> set2 = dependenciesByVariant.get(variant2); if (set1.equals(set2)) { variantsToSkip.add(variant2); if (!consolidatedVariants.contains(variant1)) { consolidatedVariants.add(variant1); } consolidatedVariants.add(variant2); } } String variantName = variant1; if (!consolidatedVariants.isEmpty()) { variantName = Joiner.on(", ").join(consolidatedVariants); } DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(variantName); root.add(variantNode); List<DependencyTreeElement> dependencies = Lists.newArrayList(set1); Collections.sort(dependencies); for (DependencyTreeElement dependency : dependencies) { variantNode.add(new DefaultMutableTreeNode(dependency)); } consolidatedVariants.clear(); } CheckboxTree tree = new CheckboxTree(renderer, root); tree.setRootVisible(false); TreeUtil.expandAll(tree); return tree; }
From source file:com.streamsets.stage.destination.riak.RiakTarget.java
/** {@inheritDoc} */ @Override//w w w . j a v a 2 s . co m public void write(Batch batch) throws StageException { try { Multimap<String, Record> partitions = partitionBatch(batch); Set<String> tableNames = partitions.keySet(); for (String tableName : tableNames) { List<OnRecordErrorException> errors = recordWriters.getUnchecked(tableName) .writeBatch(partitions.get(tableName)); for (OnRecordErrorException error : errors) { handleErrorRecord(error); } } } catch (OnRecordErrorException error) { handleErrorRecord(error); } Iterator<Record> batchIterator = batch.getRecords(); List<Row> rows = new ArrayList<>(); while (batchIterator.hasNext()) { Record record = batchIterator.next(); try { List<Cell> cells = new ArrayList<>(); cells.add(new Cell("South Atlantic")); cells.add(new Cell("South Carolina")); cells.add(Cell.newTimestamp(1234567)); cells.add(new Cell("hot")); cells.add(new Cell(24.25)); rows.add(new Row(cells)); } catch (Exception e) { switch (getContext().getOnErrorRecord()) { case DISCARD: break; case TO_ERROR: getContext().toError(record, Errors.RIAK_01, e.toString()); break; case STOP_PIPELINE: throw new StageException(Errors.RIAK_01, e.toString()); default: throw new IllegalStateException( Utils.format("Unknown OnError value '{}'", getContext().getOnErrorRecord(), e)); } } } Store storeCmd = new Store.Builder(getTableNameTemplate()).withRows(rows).build(); try { client.execute(storeCmd); } catch (ExecutionException e) { // TODO e.printStackTrace(); } catch (InterruptedException e) { // TODO e.printStackTrace(); } }
From source file:org.eclipse.xtext.xtext.OverriddenValueInspector.java
private void visitFragment(RuleCall object) { Multimap<String, AbstractElement> prevAssignedFeatures = assignedFeatures; assignedFeatures = newMultimap();//from w w w. j av a2s . co m if (fragmentStack.add(object)) { try { doSwitch(object.getRule().getAlternatives()); } finally { fragmentStack.remove(object); } } Multimap<String, AbstractElement> assignedByFragment = assignedFeatures; assignedFeatures = prevAssignedFeatures; for (String feature : assignedByFragment.keySet()) checkAssignment(object, feature); }
From source file:com.facebook.buck.cxx.CxxHeaders.java
/** * @return the arguments to add to the preprocessor command line to include the given header packs * in preprocessor search path.//from w w w. j av a2 s .co m */ public static Iterable<String> getArgs(Iterable<CxxHeaders> cxxHeaderses, SourcePathResolver resolver, Optional<PathShortener> pathMinimizer, Preprocessor preprocessor) { ImmutableList.Builder<String> args = ImmutableList.builder(); // Collect the header maps and roots into buckets organized by include type, so that we can: // 1) Apply the header maps first (so that they work properly). // 2) De-duplicate redundant include paths. Multimap<CxxPreprocessables.IncludeType, String> headerMaps = LinkedHashMultimap.create(); Multimap<CxxPreprocessables.IncludeType, String> roots = LinkedHashMultimap.create(); for (CxxHeaders cxxHeaders : cxxHeaderses) { Optional<SourcePath> headerMap = cxxHeaders.getHeaderMap(); if (headerMap.isPresent()) { headerMaps.put(cxxHeaders.getIncludeType(), resolveSourcePathAndShorten(resolver, headerMap.get(), pathMinimizer).toString()); } roots.put(cxxHeaders.getIncludeType(), resolveSourcePathAndShorten(resolver, cxxHeaders.getIncludeRoot(), pathMinimizer).toString()); } // Define the include type ordering. We always add local ("-I") include paths first so that // headers match there before system ("-isystem") ones. ImmutableSet<CxxPreprocessables.IncludeType> includeTypes = ImmutableSet .of(CxxPreprocessables.IncludeType.LOCAL, CxxPreprocessables.IncludeType.SYSTEM); // Apply the header maps first, so that headers that matching there avoid falling back to // stat'ing files in the normal include roots. Preconditions.checkState(includeTypes.containsAll(headerMaps.keySet())); for (CxxPreprocessables.IncludeType includeType : includeTypes) { args.addAll(includeType.includeArgs(preprocessor, headerMaps.get(includeType))); } // Apply the regular includes last. Preconditions.checkState(includeTypes.containsAll(roots.keySet())); for (CxxPreprocessables.IncludeType includeType : includeTypes) { args.addAll(includeType.includeArgs(preprocessor, roots.get(includeType))); } return args.build(); }
From source file:fr.ujm.tse.lt2c.satin.rules.run.RunPRP_DOM.java
@Override protected int process(final TripleStore ts1, final TripleStore ts2, final Collection<Triple> outputTriples) { final long domain = AbstractDictionary.domain; final long type = AbstractDictionary.type; final int loops = 0; final Multimap<Long, Long> domainMultiMap = ts1.getMultiMapForPredicate(domain); if (domainMultiMap != null && !domainMultiMap.isEmpty()) { final HashMap<Long, Collection<Triple>> cachePredicates = new HashMap<>(); for (final Long p : domainMultiMap.keySet()) { Collection<Triple> matchingTriples; if (!cachePredicates.containsKey(p)) { matchingTriples = ts2.getbyPredicate(p); cachePredicates.put(p, matchingTriples); } else { matchingTriples = cachePredicates.get(p); }//from w ww .jav a2s . c o m for (final Triple triple : matchingTriples) { for (final Long c : domainMultiMap.get(p)) { if (triple.getSubject() >= 0) { final Triple result = new ImmutableTriple(triple.getSubject(), type, c); outputTriples.add(result); } } } } } return loops; }
From source file:org.robotframework.ide.eclipse.main.plugin.search.participants.TargetedSearch.java
public final void run(final IProgressMonitor monitor, final Multimap<IProject, LibrarySpecification> libraries, final Set<IFile> files) throws OperationCanceledException { monitor.beginTask("Searching for '" + searchPattern.getPattern() + "'", libraries.values().size() + files.size()); for (final IProject project : libraries.keySet()) { for (final LibrarySpecification librarySpecification : libraries.get(project)) { if (monitor.isCanceled()) { throw new OperationCanceledException(); }/* w w w .ja v a 2 s. c o m*/ monitor.subTask("locating matches in " + librarySpecification.getName() + " library used by '" + project.getName() + "' project"); locateMatchesInLibrarySpecification(project, librarySpecification); for (final KeywordSpecification keywordSpecification : librarySpecification.getKeywords()) { locateMatchesInKeywordSpecification(project, librarySpecification, keywordSpecification); } monitor.worked(1); } } for (final IFile file : files) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } locateMatchesInRobotFile(model.createSuiteFile(file)); monitor.worked(1); } }