List of usage examples for com.google.common.collect Multimaps index
public static <K, V> ImmutableListMultimap<K, V> index(Iterator<V> values, Function<? super V, K> keyFunction)
From source file:org.tomitribe.beryllium.mocks.CallsSteps.java
@Given("^The call to external service should be:$") public void theCallToExternalServiceShouldBe(final DataTable data) throws Throwable { final Multimap<Call, Call> calls = Multimaps.index(data.asList(Call.class), new com.google.common.base.Function<Call, Call>() { @Override//from w ww .j a va 2 s .c om public Call apply(Call call) { return new Call(call.getMethod(), call.getUrl(), -1, null); } }); for (final Map.Entry<Call, Collection<Call>> groupedCalls : calls.asMap().entrySet()) { final List<Action> actions = new ArrayList<>(groupedCalls.getValue().size()); for (Call call : groupedCalls.getValue()) { actions.add(composite(status(HttpStatus.getHttpStatus(call.getStatusCode())), resourceContent(Thread .currentThread().getContextClassLoader().getResource("fixtures/" + call.getFilename())))); } final Call key = groupedCalls.getKey(); stubHttp.match(key.getHttpMethod(), key.buildQueryParams()).then(sequential(actions)); } }
From source file:com.b2international.snowowl.snomed.datastore.converter.InactivationExpander.java
void expand(List<T> results, Set<String> componentIds) { if (componentIds.isEmpty()) { return;/*from www. j a va 2 s . c o m*/ } final List<String> refSetIds = newArrayList(); for (final AssociationType associationType : AssociationType.values()) { refSetIds.add(associationType.getConceptId()); } refSetIds.add(inactivationIndicatorId); final SnomedReferenceSetMembers members = SnomedRequests.prepareSearchMember().all() .filterByRefSet(refSetIds).filterByReferencedComponent(componentIds).filterByActive(true).build() .execute(context); if (members.getItems().isEmpty()) { return; } final Multimap<String, SnomedReferenceSetMember> membersByReferencedComponentId = Multimaps.index(members, new Function<SnomedReferenceSetMember, String>() { @Override public String apply(SnomedReferenceSetMember input) { return input.getReferencedComponent().getId(); } }); for (T result : results) { final Collection<SnomedReferenceSetMember> referringMembers = membersByReferencedComponentId .get(result.getId()); final List<SnomedReferenceSetMember> associationMembers = newArrayList(); final List<SnomedReferenceSetMember> inactivationMembers = newArrayList(); for (SnomedReferenceSetMember referringMember : referringMembers) { if (SnomedRefSetType.ASSOCIATION.equals(referringMember.type())) { associationMembers.add(referringMember); } else if (SnomedRefSetType.ATTRIBUTE_VALUE.equals(referringMember.type())) { inactivationMembers.add(referringMember); } } if (!inactivationMembers.isEmpty()) { final String valueId = (String) Iterables.getFirst(inactivationMembers, null).getProperties() .get(SnomedRf2Headers.FIELD_VALUE_ID); setInactivationIndicator(result, valueId); } Multimap<AssociationType, String> associationTargets = HashMultimap.create(); for (SnomedReferenceSetMember associationMember : associationMembers) { AssociationType type = AssociationType.getByConceptId(associationMember.getReferenceSetId()); final SnomedCoreComponent target = (SnomedCoreComponent) associationMember.getProperties() .get(SnomedRf2Headers.FIELD_TARGET_COMPONENT); associationTargets.put(type, target.getId()); } if (!associationTargets.isEmpty()) { setAssociationTargets(result, associationTargets); } } }
From source file:com.arcbees.bourseje.server.services.VoteService.java
private Map<Long, Collection<VoteItem>> groupByCandidateId(List<VoteItem> votes) { return Multimaps.index(votes, new Function<VoteItem, Long>() { @Override/*from ww w. j a va2s. c om*/ public Long apply(VoteItem voteItem) { return voteItem.getCandidateId(); } }).asMap(); }
From source file:com.viadeo.kasper.core.id.AbstractByTypeConverter.java
@Override public Map<ID, ID> convert(final Collection<ID> ids) { final ListMultimap<String, ID> idsByType = Multimaps.index(ids, new Function<ID, String>() { @Override//from ww w . j av a2 s .c om public java.lang.String apply(ID input) { return checkNotNull(input).getType(); } }); final Map<ID, ID> convertResults = Maps.newHashMapWithExpectedSize(ids.size()); for (final String type : idsByType.keySet()) { convertResults.putAll(doConvert(type, idsByType.get(type))); } return convertResults; }
From source file:com.mogujie.instantrun.IntSwitch.java
private void visitClassifier(GeneratorAdapter mv, Set<String> strings) { visitInt();/*from w w w. jav a 2 s . c o m*/ Multimap<Integer, String> buckets = Multimaps.index(strings, HASH_METHOD); List<Map.Entry<Integer, Collection<String>>> sorted = Ordering.natural() .onResultOf(new Function<Map.Entry<Integer, Collection<String>>, Integer>() { @Override public Integer apply(Map.Entry<Integer, Collection<String>> entry) { return entry.getKey(); } }).immutableSortedCopy(buckets.asMap().entrySet()); int sortedHashes[] = new int[sorted.size()]; List<String> sortedCases[] = new List[sorted.size()]; int index = 0; for (Map.Entry<Integer, Collection<String>> entry : sorted) { sortedHashes[index] = entry.getKey(); sortedCases[index] = Lists.newCopyOnWriteArrayList(entry.getValue()); index++; } // Label for each hash and for default. Label labels[] = new Label[sorted.size()]; Label defaultLabel = new Label(); for (int i = 0; i < sorted.size(); ++i) { labels[i] = new Label(); } // Create a switch that dispatches to each label from the hash code of mv.visitLookupSwitchInsn(defaultLabel, sortedHashes, labels); // Create the cases. for (int i = 0; i < sorted.size(); ++i) { mv.visitLabel(labels[i]); visitx(mv, sortedCases[i]); } mv.visitLabel(defaultLabel); visitDefault(); }
From source file:com.qcadoo.mes.basic.shift.ShiftTimetableExceptions.java
private ImmutableMultimap<TimetableExceptionType, DateRange> getExceptions(final Entity shift) { List<Entity> timetableExceptionEntities = shift.getHasManyField(ShiftFields.TIMETABLE_EXCEPTIONS); return ImmutableMultimap.copyOf(Multimaps .transformValues(Multimaps.index(timetableExceptionEntities, EXTRACT_TYPE), EXTRACT_DATE_RANGE)); }
From source file:org.obm.push.handler.SearchHandler.java
@Inject protected SearchHandler(Set<ISearchSource> searchSources, SearchProtocol searchProtocol, WBXMLTools wbxmlTools, DOMDumper domDumper) {/*from w w w.j a v a2 s. c o m*/ super(wbxmlTools, domDumper); this.protocol = searchProtocol; this.sources = Multimaps.index(searchSources, new Function<ISearchSource, StoreName>() { @Override public StoreName apply(ISearchSource input) { return input.getStoreName(); } }); }
From source file:net.sourceforge.atunes.kernel.modules.radio.RadioBrowserDialogController.java
protected void show(final List<IRadio> radios) { ImmutableListMultimap<String, IRadio> labelsAndRadios = Multimaps.index(radios, new Function<IRadio, String>() { @Override//from w ww . j a va2 s. com public String apply(final IRadio input) { if (input != null && input.getLabel() != null) { return input.getLabel(); } return ""; } }); List<String> labels = new ArrayList<String>(labelsAndRadios.keySet()); Collections.sort(labels, new DefaultComparator(this.collator)); DefaultListModel listModel = new DefaultListModel(); for (String label : labels) { listModel.addElement(label); } getComponentControlled().getList().setModel(listModel); getComponentControlled().getTable().setModel(new RadioBrowserTableModel(labelsAndRadios)); getComponentControlled().setVisible(true); }
From source file:org.jclouds.joyent.sdc.v6_5.compute.functions.OrphanedGroupsByDatacenterId.java
public Multimap<String, String> apply(Set<? extends NodeMetadata> deadNodes) { Iterable<? extends NodeMetadata> nodesWithGroup = filter(deadNodes, NodePredicates.hasGroup()); Set<DatacenterAndName> datacenterAndGroupNames = ImmutableSet .copyOf(filter(transform(nodesWithGroup, new Function<NodeMetadata, DatacenterAndName>() { @Override//from ww w .ja v a2 s .c o m public DatacenterAndName apply(NodeMetadata input) { String datacenterId = input.getLocation().getId(); return DatacenterAndName.fromDatacenterAndName(datacenterId, input.getGroup()); } }), allNodesInGroupTerminated)); Multimap<String, String> datacenterToDatacenterAndGroupNames = Multimaps.transformValues( Multimaps.index(datacenterAndGroupNames, DatacenterAndName.DATACENTER_FUNCTION), DatacenterAndName.NAME_FUNCTION); return datacenterToDatacenterAndGroupNames; }
From source file:edu.harvard.med.screensaver.db.datafetcher.TupleDataFetcher.java
/** * @param keys if null, fetches all entities for the root entity type (subject * to normal column criteria)//w w w .java 2 s. c o m */ protected Map<K, Tuple<K>> doFetchData(Set<K> keys) { // collate properties into groups of PropertyPaths having same RelationshipPath; // this will allow us to execute one query for each group of properties that are from the same entity type Multimap<RelationshipPath<E>, PropertyPath<E>> pathGroups = Multimaps.index(getProperties(), new Function<PropertyPath<E>, RelationshipPath<E>>() { public RelationshipPath<E> apply(PropertyPath<E> p) { return p.getAncestryPath(); } }); Map<K, Tuple<K>> tuples = Maps.newHashMapWithExpectedSize(keys.size()); for (Collection<PropertyPath<E>> propertyPaths : pathGroups.asMap().values()) { List<PropertyPath<E>> orderedPropertyPaths = Lists.newArrayList(propertyPaths); if (log.isDebugEnabled()) { log.debug("fetching " + keys.size() + " values for properties " + orderedPropertyPaths); } List<Object[]> result = _dao.runQuery(buildQueryForProperty(orderedPropertyPaths, keys)); packageResultIntoTuples(tuples, orderedPropertyPaths, result); } return tuples; }