List of usage examples for com.google.common.collect Multimap asMap
Map<K, Collection<V>> asMap();
From source file:org.lightjason.agentspeak.action.builtin.bool.CEqual.java
/** * compare multimap//from w w w. jav a 2s.c o m * * @param p_source source multimap * @param p_target multimap to compare * @return equality boolean flag */ private static boolean equalmultimap(@Nonnull final Multimap<?, ?> p_source, @Nonnull final Multimap<?, ?> p_target) { return Arrays.equals(p_source.asMap().keySet().toArray(), p_target.asMap().keySet().toArray()) && Arrays.equals(p_source.values().toArray(), p_target.values().toArray()); }
From source file:com.facebook.buck.cli.CommandHelper.java
public static void printJSON(CommandRunnerParams params, Multimap<String, QueryTarget> targetsAndResults) throws IOException { Multimap<String, String> targetsAndResultsNames = Multimaps.transformValues(targetsAndResults, input -> Preconditions.checkNotNull(input.toString())); params.getObjectMapper().writeValue(params.getConsole().getStdOut(), targetsAndResultsNames.asMap()); }
From source file:com.palantir.atlasdb.table.generation.ColumnValues.java
public static <T extends Persistable, V extends ColumnValue<?>> Map<Cell, byte[]> toCellValues( Multimap<T, V> map, long duration, TimeUnit durationTimeUnit) { Map<Cell, byte[]> ret = Maps.newHashMapWithExpectedSize(map.size()); for (Entry<T, Collection<V>> e : map.asMap().entrySet()) { byte[] rowName = e.getKey().persistToBytes(); for (V val : e.getValue()) { ret.put(Cell.create(rowName, val.persistColumnName(), duration, durationTimeUnit), val.persistValue()); }/*w w w . j a va 2s.c om*/ } return ret; }
From source file:es.usc.citius.composit.core.composition.search.CompositSearch.java
private static <E> Set<Set<Operation<E>>> combine(Multimap<Set<E>, Operation<E>> matchMap) { // Get the groups Set<Set<E>> sets = matchMap.asMap().keySet(); log.debug("\t\t> Performing set input cover of {}", sets); SetCoverIterator<E> sc = new SetCoverIterator<E>(sets); //sc.useParallelization(true); Set<Set<Operation<E>>> coveringSets = new HashSet<Set<Operation<E>>>(); while (sc.hasNext()) { Set<Set<E>> group = sc.next(); log.debug("\t\t\t+ Selected cover input group: {}", group); // Get the services associated to each E group List<Set<Operation<E>>> solution = new ArrayList<Set<Operation<E>>>(); for (Set<E> inputsMatched : group) { Collection<Operation<E>> ops = matchMap.get(inputsMatched); solution.add(new HashSet<Operation<E>>(ops)); }//from w ww . j a v a 2 s. c o m log.debug("\t\t\t\t- Operation groups: {}", solution); // Generate cartesian product to decompose equivalent functional services Set<List<Operation<E>>> cartesian = Sets.cartesianProduct(solution); ; for (List<Operation<E>> cartesianResult : cartesian) { coveringSets.add(new HashSet<Operation<E>>(cartesianResult)); } log.debug("\t\t\t\t- Cartesian product decomposition: {}", cartesian); } log.debug("\t\t\t- Cover sets before cartesian product decomposition {}", coveringSets); return coveringSets; }
From source file:info.gehrels.voting.web.BallotIterableDiffCalculator.java
private static <T extends Candidate> Set<Long> findDuplicateIds(Iterable<Ballot<T>> castBallots) { Set<Long> duplicateIds = new HashSet<>(); Multimap<Long, Ballot<T>> castBallotsById = asIdToBallotsMulitmap(castBallots); for (Entry<Long, Collection<Ballot<T>>> longCollectionEntry : castBallotsById.asMap().entrySet()) { if (longCollectionEntry.getValue().size() > 1) { duplicateIds.add(longCollectionEntry.getKey()); }// w ww.java 2 s .c o m } return duplicateIds; }
From source file:com.facebook.buck.cli.AuditMbrIsolationCommand.java
private static List<Entry<String, Collection<String>>> asSortedEntries(Multimap<String, String> failure) { return failure.asMap().entrySet().stream().sorted(Comparator.comparing(e -> -e.getValue().size())) .collect(Collectors.toList()); }
From source file:org.sonar.ce.taskprocessor.CeTaskProcessorRepositoryImpl.java
private static Map<String, CeTaskProcessor> indexTaskProcessors(CeTaskProcessor[] taskProcessors) { Multimap<String, CeTaskProcessor> permissiveIndex = buildPermissiveCeTaskProcessorIndex(taskProcessors); checkUniqueHandlerPerCeTaskType(permissiveIndex); return ImmutableMap.copyOf( Maps.transformValues(permissiveIndex.asMap(), CeTaskProcessorCollectionToFirstElement.INSTANCE)); }
From source file:org.tensorics.core.math.Operations.java
public static <K, V> ListMultimap<K, V> mapAll(Multimap<K, ValuePair<V>> valuePairs, BinaryOperation<V> operation) { ImmutableListMultimap.Builder<K, V> builder = ImmutableListMultimap.builder(); for (Entry<K, Collection<ValuePair<V>>> entry : valuePairs.asMap().entrySet()) { builder.putAll(entry.getKey(), performOnAll(entry.getValue(), operation)); }/*from w w w. j av a 2s . c o m*/ return builder.build(); }
From source file:eu.itesla_project.modules.rules.SecurityRuleUtil.java
public static Map<String, Map<SecurityIndexType, SecurityRuleCheckStatus>> checkRules(Network network, RulesDbClient rulesDb, String workflowId, RuleAttributeSet attributeSet, Set<SecurityIndexType> securityIndexTypes, Set<String> contingencies, double purityThreshold) { Map<HistoDbAttributeId, Object> values = IIDM2DB.extractCimValues(network, new IIDM2DB.Config(null, false)) .getSingleValueMap();/*from w ww.j a v a 2 s. c om*/ // check rules Map<String, Map<SecurityIndexType, SecurityRuleCheckStatus>> checkStatusPerContingency = new LinkedHashMap<>(); // get rules from db Collection<RuleId> ruleIds = rulesDb.listRules(workflowId, attributeSet).stream() .filter(ruleId -> securityIndexTypes.contains(ruleId.getSecurityIndexId().getSecurityIndexType()) && (contingencies == null || contingencies.contains(ruleId.getSecurityIndexId().getContingencyId()))) .collect(Collectors.toList()); // TODO filter rules that does not apply to the network // sort rules per contingency Multimap<String, RuleId> ruleIdsPerContingency = Multimaps.index(ruleIds, ruleId -> { return ruleId.getSecurityIndexId().getContingencyId(); }); for (Map.Entry<String, Collection<RuleId>> entry : ruleIdsPerContingency.asMap().entrySet()) { String contingencyId = entry.getKey(); Map<SecurityIndexType, SecurityRuleCheckStatus> checkStatus = new EnumMap<>(SecurityIndexType.class); for (SecurityIndexType securityIndexType : securityIndexTypes) { checkStatus.put(securityIndexType, SecurityRuleCheckStatus.NA); } for (RuleId ruleId : entry.getValue()) { List<SecurityRule> rules = rulesDb.getRules(workflowId, attributeSet, contingencyId, ruleId.getSecurityIndexId().getSecurityIndexType()); if (rules.size() > 0) { SecurityRule rule = rules.get(0); SecurityRuleExpression securityRuleExpression = rule.toExpression(purityThreshold); SecurityRuleCheckReport report = securityRuleExpression.check(values); SecurityRuleCheckStatus status; if (report.getMissingAttributes().isEmpty()) { status = report.isSafe() ? SecurityRuleCheckStatus.OK : SecurityRuleCheckStatus.NOK; } else { status = SecurityRuleCheckStatus.NA; } checkStatus.put(rule.getId().getSecurityIndexId().getSecurityIndexType(), status); } } checkStatusPerContingency.put(contingencyId, checkStatus); } return checkStatusPerContingency; }
From source file:de.iteratec.iteraplan.persistence.elasticeam.metamodel.IteraplanDiffClassifier.java
public static Collection<MMChange<?>> getDiffsToApply(Multimap<TypeOfDiff, MMChange<?>> classifiedDiffs) { List<MMChange<?>> result = Lists.newArrayList(); for (Entry<TypeOfDiff, Collection<MMChange<?>>> entry : classifiedDiffs.asMap().entrySet()) { if (TypeOfDiff.IGNORED.compareTo(entry.getKey()) < 0) { result.addAll(entry.getValue()); }//w w w . j a v a 2 s .c om } return result; }