List of usage examples for com.google.common.collect ListMultimap asMap
@Override Map<K, Collection<V>> asMap();
Note: The returned map's values are guaranteed to be of type List .
From source file:com.google.api.server.spi.MethodHierarchyReader.java
/** * Returns {@link ListMultimap#asMap multimap.asMap()}, with its type * corrected from {@code Map<K, Collection<V>>} to {@code Map<K, List<V>>}. *///w w w . j a v a2 s . c o m // Copied from com.google.common.collect.Multimaps. We can't use the actual method from // that class as appengine build magic gives us an older version of guava that doesn't yet have // this method. // TODO: Switch to Multimaps.asMap() once it becomes available in appengine. @SuppressWarnings("unchecked") // safe by specification of ListMultimap.asMap() private static <K, V> Map<K, List<V>> asMap(ListMultimap<K, V> multimap) { return (Map<K, List<V>>) (Map<K, ?>) multimap.asMap(); }
From source file:no.ssb.vtl.script.operations.FoldOperation.java
/** * Check that all of the given columns are of the same type * * @return the type of all the columns./* ww w . j a va 2s . c om*/ * @throws IllegalArgumentException if columns are not of the same type. */ private static Class<?> checkColumnType(DataStructure structure, ImmutableSet<String> columns) { ListMultimap<Class<?>, String> classes = ArrayListMultimap.create(); for (String element : columns) { classes.put(structure.get(element).getType(), element); } checkArgument(classes.asMap().size() == 1, "all element(s) [%s] are not of the same type [%s]", columns, classes); return classes.keys().iterator().next(); }
From source file:org.optaplanner.core.impl.heuristic.selector.SelectorTestUtils.java
public static ValueSelector mockValueSelectorForEntity(GenuineVariableDescriptor variableDescriptor, ListMultimap<Object, Object> entityToValues) { ValueSelector valueSelector = mock(ValueSelector.class); when(valueSelector.getVariableDescriptor()).thenReturn(variableDescriptor); for (Map.Entry<Object, Collection<Object>> entry : entityToValues.asMap().entrySet()) { Object entity = entry.getKey(); final List<Object> valueList = (List<Object>) entry.getValue(); when(valueSelector.getSize(entity)).thenAnswer(new Answer<Long>() { public Long answer(InvocationOnMock invocation) { return (long) valueList.size(); }//from ww w .j a v a 2s .c o m }); when(valueSelector.iterator(entity)).thenAnswer(new Answer<Iterator<Object>>() { public Iterator<Object> answer(InvocationOnMock invocation) { return valueList.iterator(); } }); when(valueSelector.getSize(entity)).thenReturn((long) valueList.size()); } when(valueSelector.isCountable()).thenReturn(true); when(valueSelector.isNeverEnding()).thenReturn(false); return valueSelector; }
From source file:de.bund.bfr.knime.pmmlite.views.ViewUtils.java
public static Map<String, PmmUnit> getMostCommonUnits(Collection<Plotable> plotables) { ListMultimap<String, PmmUnit> units = ArrayListMultimap.create(); for (Plotable plotable : plotables) { for (Map.Entry<String, PmmUnit> entry : plotable.getUnits().entrySet()) { units.put(entry.getKey(), entry.getValue()); }//ww w . ja v a2 s . c om } Map<String, PmmUnit> mostCommon = new LinkedHashMap<>(); for (Map.Entry<String, Collection<PmmUnit>> entry : units.asMap().entrySet()) { mostCommon.put(entry.getKey(), PmmUtils.getMaxCounted(entry.getValue())); } return mostCommon; }
From source file:ru.org.linux.tag.TagPageController.java
private static <T> ImmutableList<ImmutableMap<String, List<T>>> split(ListMultimap<String, T> topics) { if (topics.isEmpty()) { return ImmutableList.of(); }/*from www . ja va2 s. c o m*/ int split = topics.size() / 2 + (topics.size() % 2); ImmutableMap.Builder<String, List<T>> first = ImmutableMap.builder(); ImmutableMap.Builder<String, List<T>> second = ImmutableMap.builder(); int total = 0; for (Map.Entry<String, Collection<T>> entry : topics.asMap().entrySet()) { int currentSize = entry.getValue().size(); if (total + (currentSize / 2) <= split) { first.put(entry.getKey(), ImmutableList.copyOf(entry.getValue())); } else { second.put(entry.getKey(), ImmutableList.copyOf(entry.getValue())); } total += currentSize; } return ImmutableList.of(first.build(), second.build()); }
From source file:org.apache.isis.core.metamodel.services.ServicesInjectorDefault.java
private static void validate(List<Object> serviceList) { for (Object service : serviceList) { final Method[] methods = service.getClass().getMethods(); for (Method method : methods) { validatePostConstructMethods(service, method); validatePreDestroyMethods(service, method); }// w ww .j a v a 2 s .c o m } ListMultimap<String, Object> servicesById = ArrayListMultimap.create(); for (Object service : serviceList) { String id = ServiceUtil.id(service); servicesById.put(id, service); } for (Map.Entry<String, Collection<Object>> servicesForId : servicesById.asMap().entrySet()) { String serviceId = servicesForId.getKey(); Collection<Object> services = servicesForId.getValue(); if (services.size() > 1) { throw new IllegalStateException(String.format( "Service ids must be unique; serviceId '%s' is declared by domain services %s", serviceId, classNamesFor(services))); } } }
From source file:com.google.gerrit.server.notedb.NoteDbUpdateManager.java
private static <U extends AbstractChangeUpdate> void addUpdates(ListMultimap<String, U> all, OpenRepo or) throws OrmException, IOException { for (Map.Entry<String, Collection<U>> e : all.asMap().entrySet()) { String refName = e.getKey(); Collection<U> updates = e.getValue(); ObjectId old = or.cmds.get(refName).orElse(ObjectId.zeroId()); // Only actually write to the ref if one of the updates explicitly allows // us to do so, i.e. it is known to represent a new change. This avoids // writing partial change meta if the change hasn't been backfilled yet. if (!allowWrite(updates, old)) { continue; }/*from w w w .j a va 2s . c o m*/ ObjectId curr = old; for (U u : updates) { ObjectId next = u.apply(or.rw, or.tempIns, curr); if (next == null) { continue; } curr = next; } if (!old.equals(curr)) { or.cmds.add(new ReceiveCommand(old, curr, refName)); } } }
From source file:org.apache.isis.core.metamodel.services.ServicesInjector.java
private static void validate(List<Object> serviceList) { ListMultimap<String, Object> servicesById = ArrayListMultimap.create(); for (Object service : serviceList) { String id = ServiceUtil.id(service); servicesById.put(id, service);/*w w w . j a va2 s . c o m*/ } for (Map.Entry<String, Collection<Object>> servicesForId : servicesById.asMap().entrySet()) { String serviceId = servicesForId.getKey(); Collection<Object> services = servicesForId.getValue(); if (services.size() > 1) { throw new IllegalStateException(String.format( "Service ids must be unique; serviceId '%s' is declared by domain services %s", serviceId, classNamesFor(services))); } } }
From source file:de.bund.bfr.knime.pmmlite.core.PmmUtils.java
public static Map<String, PmmUnit> getMostCommonUnits(Collection<TimeSeries> data) { ListMultimap<String, PmmUnit> units = ArrayListMultimap.create(); for (TimeSeries series : data) { units.put(PmmUtils.TIME, series.getTimeUnit()); units.put(PmmUtils.CONCENTRATION, series.getConcentrationUnit()); for (Condition cond : series.getConditions()) { units.put(cond.getName(), cond.getUnit()); }/*from w w w . j a va 2 s . c om*/ } Map<String, PmmUnit> mostCommon = new LinkedHashMap<>(); for (Map.Entry<String, Collection<PmmUnit>> entry : units.asMap().entrySet()) { mostCommon.put(entry.getKey(), PmmUtils.getMaxCounted(entry.getValue())); } return mostCommon; }
From source file:org.mskcc.cbio.portal.mut_diagram.Pileup.java
/** * Return a list of pileups for the specified list of mutations. The list of * pileups may be empty but will not be null. * * @param mutations list of mutations, must not be null * @return a list of pileups for the specified list of mutations *///from ww w . jav a 2s . c o m public static List<Pileup> pileup(final List<ExtendedMutation> mutations) { checkNotNull(mutations, "mutations must not be null"); List<Pileup> pileups = Lists.newArrayList(); SetMultimap<Integer, String> labels = HashMultimap.create(); ListMultimap<Integer, ExtendedMutation> mutationsByLocation = ArrayListMultimap.create(); for (ExtendedMutation mutation : mutations) { String label = mutation.getProteinChange(); if (label != null) { try { int location = Integer.valueOf(label.replaceAll("[A-Za-z\\.*]+", "")); labels.put(location, label); mutationsByLocation.put(location, mutation); } catch (NumberFormatException e) { logger.warn("ignoring extended mutation " + label + ", no location information"); } } } for (Map.Entry<Integer, Collection<ExtendedMutation>> entry : mutationsByLocation.asMap().entrySet()) { int location = entry.getKey(); Set<String> locationLabels = labels.get(location); List<String> sortedLocationLabels = new ArrayList<String>(); sortedLocationLabels.addAll(locationLabels); Collections.sort(sortedLocationLabels); String label = Joiner.on("/").join(sortedLocationLabels); int missenseCount = 0; Set<String> caseIds = Sets.newHashSet(); for (ExtendedMutation mutation : entry.getValue()) { caseIds.add(mutation.getSampleId() + ":" + mutation.getProteinChange()); if (mutation.getMutationType() != null && mutation.getMutationType().toLowerCase().contains("missense")) { missenseCount++; } } pileups.add(new Pileup(label, location, caseIds.size(), missenseCount)); } return ImmutableList.copyOf(pileups); }