List of usage examples for com.google.common.collect ArrayListMultimap create
public static <K, V> ArrayListMultimap<K, V> create()
From source file:com.haulmont.timesheets.gui.approve.BulkTimeEntriesApprove.java
@Override public void init(Map<String, Object> params) { super.init(params); if (securityAssistant.isSuperUser()) { timeEntriesDs.setQuery("select e from ts$TimeEntry e " + "where e.date >= :component$dateFrom and e.date <= :component$dateTo"); }//from w w w . j av a 2 s .co m timeEntriesTable.getColumn("overtime") .setAggregation(ComponentsHelper.createAggregationInfo( projectsService.getEntityMetaPropertyPath(TimeEntry.class, "overtime"), new TimeEntryOvertimeAggregation())); timeEntriesDs.addCollectionChangeListener(e -> { Multimap<Map<String, Object>, TimeEntry> map = ArrayListMultimap.create(); for (TimeEntry item : timeEntriesDs.getItems()) { Map<String, Object> key = new TreeMap<>(); key.put("user", item.getUser()); key.put("date", item.getDate()); map.put(key, item); } for (Map.Entry<Map<String, Object>, Collection<TimeEntry>> entry : map.asMap().entrySet()) { BigDecimal thisDaysSummary = BigDecimal.ZERO; for (TimeEntry timeEntry : entry.getValue()) { thisDaysSummary = thisDaysSummary.add(timeEntry.getTimeInHours()); } for (TimeEntry timeEntry : entry.getValue()) { BigDecimal planHoursForDay = workdaysTools.isWorkday(timeEntry.getDate()) ? workTimeConfigBean.getWorkHourForDay() : BigDecimal.ZERO; BigDecimal overtime = thisDaysSummary.subtract(planHoursForDay); timeEntry.setOvertimeInHours(overtime); } } }); Date previousMonth = DateUtils.addMonths(timeSource.currentTimestamp(), -1); dateFrom.setValue(DateUtils.truncate(previousMonth, Calendar.MONTH)); dateTo.setValue(DateUtils.addDays(DateUtils.truncate(timeSource.currentTimestamp(), Calendar.MONTH), -1)); approve.addAction(new AbstractAction("approveAll") { @Override public void actionPerform(Component component) { setStatus(timeEntriesDs.getItems(), TimeEntryStatus.APPROVED); } }); approve.addAction(new AbstractAction("approveSelected") { @Override public void actionPerform(Component component) { setStatus(timeEntriesTable.getSelected(), TimeEntryStatus.APPROVED); } }); reject.addAction(new AbstractAction("rejectAll") { @Override public void actionPerform(Component component) { setStatus(timeEntriesDs.getItems(), TimeEntryStatus.REJECTED); } }); reject.addAction(new AbstractAction("rejectSelected") { @Override public void actionPerform(Component component) { setStatus(timeEntriesTable.getSelected(), TimeEntryStatus.REJECTED); } }); status.setOptionsList(Arrays.asList(TimeEntryStatus.values())); user.setOptionsList( projectsService.getManagedUsers(userSession.getCurrentOrSubstitutedUser(), View.MINIMAL)); }
From source file:org.sonar.core.issue.tracking.Tracker.java
private void match(Tracking<RAW, BASE> tracking, SearchKeyFactory factory) { if (tracking.isComplete()) { return;/* w ww . j a va2 s.c o m*/ } Multimap<SearchKey, BASE> baseSearch = ArrayListMultimap.create(); for (BASE base : tracking.getUnmatchedBases()) { baseSearch.put(factory.create(base), base); } for (RAW raw : tracking.getUnmatchedRaws()) { SearchKey rawKey = factory.create(raw); Collection<BASE> bases = baseSearch.get(rawKey); if (!bases.isEmpty()) { // TODO taking the first one. Could be improved if there are more than 2 issues on the same line. // Message could be checked to take the best one. BASE match = bases.iterator().next(); tracking.match(raw, match); baseSearch.remove(rawKey, match); } } }
From source file:org.dishevelled.iconbundle.tango.examples.TangoTreeModel.java
/** * Create a new tango tree model.//from w ww. jav a2s .c o m */ public TangoTreeModel() { root = new Identifiable() { /** @see Identifiable */ public String getName() { return "Tango Project"; } public IconBundle getIconBundle() { return TangoProject.FOLDER; } }; multimap = ArrayListMultimap.create(); initializeMultimap(); contexts = new ArrayList<Context>(multimap.size()); initializeContexts(); }
From source file:fr.obeo.emf.specimen.SpecimenGenerator.java
public List<EObject> generate(ResourceSet resourceSet) { List<EObject> ret = newArrayList(); ListMultimap<EClass, EObject> indexByKind = ArrayListMultimap.create(); currentDepth = 0;/* w w w.ja v a2s . c o m*/ currentMaxDepth = 0; for (EClass eClass : c.possibleRootEClasses()) { currentMaxDepth = c.getDepthDistributionFor(eClass).sample(); int nbInstance = c.getRootDistributionFor(eClass).sample(); for (int i = 0; i < nbInstance; i++) { System.out.println("Generating root " + eClass.getName() + " " + i + "/" + nbInstance); Optional<EObject> generateEObject = generateEObject(eClass, indexByKind); if (generateEObject.isPresent()) { ret.add(generateEObject.get()); } } } System.out.println("Generating XRef"); for (EObject eObjectRoot : ret) { TreeIterator<EObject> eAllContents = eObjectRoot.eAllContents(); while (eAllContents.hasNext()) { EObject eObject = eAllContents.next(); generateCrossReferences(eObject, indexByKind); } } Map<EClass, Integer> resourcesSize = newHashMap(); for (EClass eClass : c.possibleRootEClasses()) { setNextResourceSizeForType(resourcesSize, eClass); } System.out.println("Generating resources"); for (EObject eObjectRoot : ret) { TreeIterator<EObject> eAllContents = eObjectRoot.eAllContents(); createResource(resourceSet, resourcesSize, eAllContents, eObjectRoot, ret); while (eAllContents.hasNext()) { EObject eObject = eAllContents.next(); createResource(resourceSet, resourcesSize, eAllContents, eObject, ret); } } System.out.println("#EObject=" + ImmutableSet.copyOf(indexByKind.values()).size()); System.out.println("#Resource=" + resourceSet.getResources().size()); for (Map.Entry<EClass, Collection<EObject>> entry : indexByKind.asMap().entrySet()) { EClass eClass = entry.getKey(); System.out.println("#" + eClass.getEPackage().getNsURI() + "::" + entry.getKey().getName() + "=" + entry.getValue().size()); } return ret; }
From source file:org.rf.ide.core.testdata.model.search.keyword.KeywordSearcher.java
public <T> ListMultimap<String, T> findKeywords(final Map<String, Collection<T>> accessibleKeywords, final Collection<T> keywords, final Extractor<T> extractor, final String usageName, final boolean stopIfOneWasMatching) { final ListMultimap<String, T> foundByMatch = ArrayListMultimap.create(); if (stopIfOneWasMatching) { final Collection<T> collection = accessibleKeywords .get(QualifiedKeywordName.unifyDefinition(usageName)); if (collection != null && collection.size() == 1) { foundByMatch.putAll(QualifiedKeywordName.unifyDefinition(usageName), collection); return foundByMatch; }/*from w w w . ja v a2 s. c o m*/ } final List<String> possibleNameCombination = getNamesToCheck(usageName); for (final T keyword : keywords) { final String alias = extractor.alias(keyword).toLowerCase(); final String sourceName = extractor.sourceName(keyword).toLowerCase(); final String fileNameWithoutExtension = getFileNameWithoutExtension(extractor, keyword); final String keywordName = QualifiedKeywordName.unifyDefinition(extractor.keywordName(keyword)) .toLowerCase(); final boolean isEmbeddedKeywordName = EmbeddedKeywordNamesSupport.hasEmbeddedArguments(keywordName); for (String nameCombination : possibleNameCombination) { if (!isEmbeddedKeywordName) { nameCombination = QualifiedKeywordName.unifyDefinition(nameCombination); } if (matchNameDirectlyOrAsEmbeddedName(foundByMatch, keyword, keywordName, null, isEmbeddedKeywordName, nameCombination)) { if (stopIfOneWasMatching) { break; } else { continue; } } final KeywordScope scope = extractor.scope(keyword); final boolean isLibraryWithAlias = (scope == KeywordScope.REF_LIBRARY || scope == KeywordScope.STD_LIBRARY) && !alias.isEmpty(); if (!alias.isEmpty()) { if (matchNameDirectlyOrAsEmbeddedName(foundByMatch, keyword, keywordName, alias, isEmbeddedKeywordName, nameCombination)) { if (stopIfOneWasMatching) { break; } else { continue; } } } if (!isLibraryWithAlias && !sourceName.isEmpty()) { if (matchNameDirectlyOrAsEmbeddedName(foundByMatch, keyword, keywordName, sourceName, isEmbeddedKeywordName, nameCombination)) { if (stopIfOneWasMatching) { break; } else { continue; } } } if (!fileNameWithoutExtension.isEmpty() && !sourceName.equals(fileNameWithoutExtension) && !alias.equals(fileNameWithoutExtension)) { if (matchNameDirectlyOrAsEmbeddedName(foundByMatch, keyword, keywordName, fileNameWithoutExtension, isEmbeddedKeywordName, nameCombination)) { if (stopIfOneWasMatching) { break; } else { continue; } } } } } return foundByMatch; }
From source file:com.github.wnameless.smartcard.CardReader.java
/** * Returns a Multimap<CardTerminal, ResponseAPDU> after executing a set * of CommandAPDU on all Smartcard readers. * //from ww w . ja va2 s. c o m * @param commands * a List of CommandAPDU * @return ListMultimap<CardTerminal, ResponseAPDU> */ public ListMultimap<CardTerminal, ResponseAPDU> read(List<CommandAPDU> commands) { ListMultimap<CardTerminal, ResponseAPDU> responses = ArrayListMultimap.create(); for (CardTerminal terminal : getCardTerminals()) { responses.putAll(terminal, getResponse(terminal, commands)); } return responses; }
From source file:org.renjin.maven.PackageDescription.java
public static PackageDescription fromString(String contents) throws IOException { PackageDescription d = new PackageDescription(); d.properties = ArrayListMultimap.create(); List<String> lines = CharStreams.readLines(new StringReader(contents)); String key = null;//from ww w . j a v a 2s. c o m StringBuilder value = new StringBuilder(); for (String line : lines) { if (line.length() > 0) { if (Character.isWhitespace(line.codePointAt(0))) { if (key == null) { throw new IllegalArgumentException("Expected key at line '" + line + "'"); } value.append(" ").append(line.trim()); } else { if (key != null) { d.properties.put(key, value.toString()); value.setLength(0); } int colon = line.indexOf(':'); if (colon == -1) { throw new IllegalArgumentException( "Expected line in format key: value, found '" + line + "'"); } key = line.substring(0, colon); value.append(line.substring(colon + 1).trim()); } } } if (key != null) { d.properties.put(key, value.toString()); } return d; }
From source file:me.lucko.luckperms.common.caching.type.MetaAccumulator.java
public MetaAccumulator(@NonNull MetaStack prefixStack, @NonNull MetaStack suffixStack) { this.meta = ArrayListMultimap.create(); this.prefixes = new TreeMap<>(Comparator.reverseOrder()); this.suffixes = new TreeMap<>(Comparator.reverseOrder()); this.prefixStack = prefixStack; this.suffixStack = suffixStack; }
From source file:org.sonar.java.checks.OverwrittenKeyCheck.java
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return;/*from w ww . ja v a 2 s . c o m*/ } ListMultimap<CollectionAndKey, Tree> usedKeys = ArrayListMultimap.create(); for (StatementTree statementTree : ((BlockTree) tree).body()) { CollectionAndKey mapPut = isMapPut(statementTree); if (mapPut != null) { usedKeys.put(mapPut, mapPut.keyTree); } else { CollectionAndKey arrayAssignment = isArrayAssignment(statementTree); if (arrayAssignment != null) { if (arrayAssignment.collectionOnRHS()) { usedKeys.clear(); } usedKeys.put(arrayAssignment, arrayAssignment.keyTree); } else { // sequence of setting collection values is interrupted reportOverwrittenKeys(usedKeys); usedKeys.clear(); } } } reportOverwrittenKeys(usedKeys); }
From source file:org.obiba.onyx.quartz.editor.locale.LocaleProperties.java
public void addElementLabels(IQuestionnaireElement element, Locale locale, String key, String value, boolean replaceIfExists) { Assert.notNull(element);/*from w w w. j a v a 2 s. co m*/ Assert.notNull(locale); ListMultimap<Locale, KeyValue> labels = elementLabels.get(element); if (labels == null) { labels = ArrayListMultimap.create(); elementLabels.put(element, labels); } KeyValue existing = getKeyValue(element, locale, key); if (existing == null) { labels.put(locale, new KeyValue(key, value)); } else if (replaceIfExists) { existing.setValue(value); } }