List of usage examples for com.google.common.collect Multimap put
boolean put(@Nullable K key, @Nullable V value);
From source file:org.sonar.server.permission.ws.template.TemplateGroupsAction.java
private static WsPermissions.WsGroupsResponse buildResponse(List<GroupDto> groups, List<PermissionTemplateGroupDto> groupPermissions, Paging paging) { Multimap<Integer, String> permissionsByGroupId = TreeMultimap.create(); groupPermissions.forEach(groupPermission -> permissionsByGroupId.put(groupPermission.getGroupId(), groupPermission.getPermission())); WsPermissions.WsGroupsResponse.Builder response = WsPermissions.WsGroupsResponse.newBuilder(); groups.forEach(group -> {//from ww w . ja va 2 s . co m WsPermissions.Group.Builder wsGroup = response.addGroupsBuilder().setName(group.getName()); if (group.getId() != 0) { wsGroup.setId(String.valueOf(group.getId())); } setNullable(group.getDescription(), wsGroup::setDescription); wsGroup.addAllPermissions(permissionsByGroupId.get(group.getId())); }); response.getPagingBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize()) .setTotal(paging.total()); return response.build(); }
From source file:org.sonar.plugins.core.issue.tracking.HashedSequence.java
public static <S extends Sequence> HashedSequence<S> wrap(S base, SequenceComparator<S> cmp) { int size = base.length(); int[] hashes = new int[size]; Multimap<Integer, Integer> linesByHash = LinkedHashMultimap.create(); for (int i = 0; i < size; i++) { hashes[i] = cmp.hash(base, i);//from w w w . j a va 2 s .c o m // indices in array are shifted one line before linesByHash.put(hashes[i], i + 1); } return new HashedSequence<S>(base, hashes, linesByHash); }
From source file:com.tinspx.util.net.RequestBody.java
public static RequestBody of(ByteSource source, String... headers) { checkArgument(headers.length % 2 == 0, "headers list is odd (%s)", headers.length); Multimap<String, String> map = LinkedListMultimap.create(headers.length / 2); for (int i = 0; i < headers.length; i += 2) { map.put(headers[i], headers[i + 1]); }//from w w w .j ava 2s . co m return of(source, map, false); }
From source file:com.google.idea.blaze.base.run.testmap.FilteredTargetMap.java
private static Multimap<File, TargetKey> createRootsMap(ArtifactLocationDecoder artifactLocationDecoder, Collection<TargetIdeInfo> targets) { Multimap<File, TargetKey> result = ArrayListMultimap.create(); for (TargetIdeInfo target : targets) { for (ArtifactLocation source : target.sources) { result.put(artifactLocationDecoder.decode(source), target.key); }//from www.j a v a2 s .c om } return result; }
From source file:org.polarsys.reqcycle.traceability.utils.EngineUtils.java
public static Multimap<Reachable, Link> toFollowingMap(Iterator<Pair<Link, Reachable>> resultOfEngine) { Multimap<Reachable, Link> result = HashMultimap.create(); while (resultOfEngine.hasNext()) { Pair<Link, Reachable> next = resultOfEngine.next(); Reachable source = next.getFirst().getSources().iterator().next(); result.put(source, next.getFirst()); }// w w w . j a v a 2s . c om return result; }
From source file:org.sonar.server.permission.ws.GroupsAction.java
private static WsGroupsResponse buildResponse(List<GroupDto> groups, List<GroupPermissionDto> groupPermissions, Paging paging) {// w ww .ja v a 2 s . c o m Multimap<Integer, String> permissionsByGroupId = TreeMultimap.create(); groupPermissions.forEach(groupPermission -> permissionsByGroupId.put(groupPermission.getGroupId(), groupPermission.getRole())); WsGroupsResponse.Builder response = WsGroupsResponse.newBuilder(); groups.forEach(group -> { Group.Builder wsGroup = response.addGroupsBuilder().setName(group.getName()); if (group.getId() != 0) { wsGroup.setId(String.valueOf(group.getId())); } setNullable(group.getDescription(), wsGroup::setDescription); wsGroup.addAllPermissions(permissionsByGroupId.get(group.getId())); }); response.getPagingBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize()) .setTotal(paging.total()); return response.build(); }
From source file:org.sonar.server.permission.ws.UsersAction.java
private static UsersWsResponse buildResponse(List<UserDto> users, List<UserPermissionDto> userPermissions, Paging paging) {/*from w w w .jav a 2 s . co m*/ Multimap<Integer, String> permissionsByUserId = TreeMultimap.create(); userPermissions.forEach(userPermission -> permissionsByUserId.put(userPermission.getUserId(), userPermission.getPermission())); UsersWsResponse.Builder response = UsersWsResponse.newBuilder(); users.forEach(user -> { WsPermissions.User.Builder userResponse = response.addUsersBuilder().setLogin(user.getLogin()) .addAllPermissions(permissionsByUserId.get(user.getId())); setNullable(user.getEmail(), userResponse::setEmail); setNullable(user.getName(), userResponse::setName); }); response.getPagingBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize()) .setTotal(paging.total()).build(); return response.build(); }
From source file:io.takari.maven.plugins.compile.jdt.classpath.Classpath.java
private static Multimap<String, ClasspathEntry> newPackageIndex(List<ClasspathEntry> entries) { Multimap<String, ClasspathEntry> classpath = LinkedHashMultimap.create(); for (ClasspathEntry entry : entries) { for (String packageName : entry.getPackageNames()) { classpath.put(packageName, entry); }/* ww w .ja v a2 s . c o m*/ } return ImmutableMultimap.copyOf(classpath); // preserves order }
From source file:org.jclouds.http.utils.ModifyRequest.java
@SuppressWarnings("unchecked") public static <R extends HttpRequest> R addQueryParam(R request, String key, Iterable<?> values, UriBuilder builder, char... skips) { builder.uri(request.getEndpoint());/* w w w. j a v a2 s.c om*/ Multimap<String, String> map = parseQueryToMap(request.getEndpoint().getQuery()); for (Object o : values) map.put(key, o.toString()); builder.replaceQuery(makeQueryLine(map, null, skips)); return (R) request.toBuilder().endpoint(builder.build()).build(); }
From source file:co.cask.cdap.data2.metadata.lineage.LineageCollapser.java
/** * Collapse {@link Relation}s based on {@link CollapseType} * @param relations lineage relations/*from w w w .j a v a2 s . co m*/ * @param collapseTypes fields to collapse relations on * @return collapsed relations */ public static Set<CollapsedRelation> collapseRelations(Iterable<Relation> relations, Set<CollapseType> collapseTypes) { Set<CollapsedRelation> collapsedRelations = new HashSet<>(); Multimap<CollapseKey, Relation> multimap = HashMultimap.create(); for (Relation relation : relations) { multimap.put(getCollapseKey(relation, collapseTypes), relation); } LOG.trace("Collapsed relations: {}", multimap.asMap()); for (Map.Entry<CollapseKey, Collection<Relation>> collapsedEntry : multimap.asMap().entrySet()) { Id.NamespacedId data = collapsedEntry.getKey().data; Id.Program program = collapsedEntry.getKey().program; Set<AccessType> accessTypes = new HashSet<>(); Set<RunId> runs = new HashSet<>(); Set<Id.NamespacedId> components = new HashSet<>(); for (Relation relation : collapsedEntry.getValue()) { accessTypes.add(relation.getAccess()); runs.add(relation.getRun()); components.addAll(relation.getComponents()); } collapsedRelations.add(toCollapsedRelation(data, program, accessTypes, runs, components)); } return collapsedRelations; }