List of usage examples for com.google.common.collect SetMultimap keySet
Set<K> keySet();
From source file:com.siemens.sw360.portal.portlets.FossologyAwarePortlet.java
protected Map<Release, String> getReleaseStringMap(String projectId, User user) throws TException { ProjectService.Iface client = thriftClients.makeProjectClient(); Project project = client.getProjectById(projectId, user); SetMultimap<String, Project> releaseIdsToProject = releaseIdToProjects(project, user); List<Release> releasesById = thriftClients.makeComponentClient() .getFullReleasesById(releaseIdsToProject.keySet(), user); Map<Release, String> releaseStringMap = new HashMap<>(); for (Release release : releasesById) { Set<String> projectNames = new HashSet<>(); for (Project project1 : releaseIdsToProject.get(release.getId())) { projectNames.add(printName(project1)); if (projectNames.size() > 3) { projectNames.add("..."); break; }/* w w w .j ava 2 s. c o m*/ } String commaSeparated = Joiner.on(", ").join(projectNames); releaseStringMap.put(release, commaSeparated); } return releaseStringMap; }
From source file:org.jetbrains.jet.lang.resolve.calls.smartcasts.DelegatingDataFlowInfo.java
@NotNull @Override// w ww . j a v a 2s . co m public DataFlowInfo or(@NotNull DataFlowInfo otherInfo) { if (otherInfo == EMPTY) return EMPTY; if (this == EMPTY) return EMPTY; if (this == otherInfo) return this; assert otherInfo instanceof DelegatingDataFlowInfo : "Unknown DataFlowInfo type: " + otherInfo; DelegatingDataFlowInfo other = (DelegatingDataFlowInfo) otherInfo; Map<DataFlowValue, Nullability> nullabilityMapBuilder = Maps.newHashMap(); for (Map.Entry<DataFlowValue, Nullability> entry : other.getCompleteNullabilityInfo().entrySet()) { DataFlowValue key = entry.getKey(); Nullability otherFlags = entry.getValue(); Nullability thisFlags = getNullability(key); nullabilityMapBuilder.put(key, thisFlags.or(otherFlags)); } SetMultimap<DataFlowValue, JetType> myTypeInfo = getCompleteTypeInfo(); SetMultimap<DataFlowValue, JetType> otherTypeInfo = other.getCompleteTypeInfo(); SetMultimap<DataFlowValue, JetType> newTypeInfo = newTypeInfo(); for (DataFlowValue key : Sets.intersection(myTypeInfo.keySet(), otherTypeInfo.keySet())) { Set<JetType> thisTypes = myTypeInfo.get(key); Set<JetType> otherTypes = otherTypeInfo.get(key); newTypeInfo.putAll(key, Sets.intersection(thisTypes, otherTypes)); } if (nullabilityMapBuilder.isEmpty() && newTypeInfo.isEmpty()) { return EMPTY; } return new DelegatingDataFlowInfo(null, ImmutableMap.copyOf(nullabilityMapBuilder), newTypeInfo); }
From source file:fr.openwide.core.jpa.security.hierarchy.PermissionHierarchyImpl.java
private SetMultimap<Permission, Permission> buildClosures( SetMultimap<Permission, Permission> oneStepRelations) { SetMultimap<Permission, Permission> closures = HashMultimap.create(); // iterate over all higher permissions from permissionsAcceptableInOneStepMap Iterator<Permission> permissionIterator = oneStepRelations.keySet().iterator(); while (permissionIterator.hasNext()) { Permission permission = (Permission) permissionIterator.next(); Set<Permission> permissionsToVisitSet = new HashSet<Permission>(); if (oneStepRelations.containsKey(permission)) { permissionsToVisitSet.addAll(oneStepRelations.get(permission)); }//from www . ja va2s . c o m Set<Permission> visitedPermissionsSet = new HashSet<Permission>(); while (!permissionsToVisitSet.isEmpty()) { // take a permission from the permissionsToVisit set Permission aPermission = (Permission) permissionsToVisitSet.iterator().next(); permissionsToVisitSet.remove(aPermission); visitedPermissionsSet.add(aPermission); if (closures.containsKey(aPermission)) { Set<Permission> newClosure = (Set<Permission>) closures.get(aPermission); // definition of a cycle: you can reach the permission you are starting from if (permissionsToVisitSet.contains(permission) || visitedPermissionsSet.contains(permission)) { throw new CycleInPermissionHierarchyException(); } else { // no cycle permissionsToVisitSet.addAll(newClosure); } } } closures.putAll(permission, visitedPermissionsSet); } return closures; }
From source file:org.sleuthkit.autopsy.timeline.db.EventDB.java
/** * merge the events in the given list if they are within the same period * General algorithm is as follows:/*from w w w . j a va 2 s. c om*/ * * 1) sort them into a map from (type, description)-> List<aggevent> * 2) for each key in map, merge the events and accumulate them in a list to * return * * @param timeUnitLength * @param preMergedEvents * * @return */ static private List<EventStripe> mergeClustersToStripes(Period timeUnitLength, List<EventCluster> preMergedEvents) { //effectively map from type to (map from description to events) Map<EventType, SetMultimap<String, EventCluster>> typeMap = new HashMap<>(); for (EventCluster aggregateEvent : preMergedEvents) { typeMap.computeIfAbsent(aggregateEvent.getEventType(), eventType -> HashMultimap.create()) .put(aggregateEvent.getDescription(), aggregateEvent); } //result list to return ArrayList<EventCluster> aggEvents = new ArrayList<>(); //For each (type, description) key, merge agg events for (SetMultimap<String, EventCluster> descrMap : typeMap.values()) { //for each description ... for (String descr : descrMap.keySet()) { //run through the sorted events, merging together adjacent events Iterator<EventCluster> iterator = descrMap.get(descr).stream() .sorted(Comparator.comparing(event -> event.getSpan().getStartMillis())).iterator(); EventCluster current = iterator.next(); while (iterator.hasNext()) { EventCluster next = iterator.next(); Interval gap = current.getSpan().gap(next.getSpan()); //if they overlap or gap is less one quarter timeUnitLength //TODO: 1/4 factor is arbitrary. review! -jm if (gap == null || gap.toDuration() .getMillis() <= timeUnitLength.toDurationFrom(gap.getStart()).getMillis() / 4) { //merge them current = EventCluster.merge(current, next); } else { //done merging into current, set next as new current aggEvents.add(current); current = next; } } aggEvents.add(current); } } //merge clusters to stripes Map<ImmutablePair<EventType, String>, EventStripe> stripeDescMap = new HashMap<>(); for (EventCluster eventCluster : aggEvents) { stripeDescMap.merge(ImmutablePair.of(eventCluster.getEventType(), eventCluster.getDescription()), new EventStripe(eventCluster), EventStripe::merge); } return stripeDescMap.values().stream().sorted(Comparator.comparing(EventStripe::getStartMillis)) .collect(Collectors.toList()); }
From source file:com.palantir.atlasdb.keyvalue.impl.TableSplittingKeyValueService.java
@Override public void truncateTables(Set<String> tableNames) { SetMultimap<KeyValueService, String> tablesToTruncateByKvs = HashMultimap.create(); for (String tableName : tableNames) { tablesToTruncateByKvs.put(getDelegate(tableName), tableName); }// ww w.ja v a 2s . c om for (KeyValueService kvs : tablesToTruncateByKvs.keySet()) { kvs.truncateTables(tablesToTruncateByKvs.get(kvs)); } }
From source file:org.apache.brooklyn.feed.http.HttpFeed.java
@Override protected void preStart() { SetMultimap<HttpPollIdentifier, HttpPollConfig<?>> polls = getConfig(POLLS); for (final HttpPollIdentifier pollInfo : polls.keySet()) { // Though HttpClients are thread safe and can take advantage of connection pooling // and authentication caching, the httpcomponents documentation says: // "While HttpClient instances are thread safe and can be shared between multiple // threads of execution, it is highly recommended that each thread maintains its // own dedicated instance of HttpContext. // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html final HttpClient httpClient = createHttpClient(pollInfo); Set<HttpPollConfig<?>> configs = polls.get(pollInfo); long minPeriod = Integer.MAX_VALUE; Set<AttributePollHandler<? super HttpToolResponse>> handlers = Sets.newLinkedHashSet(); for (HttpPollConfig<?> config : configs) { handlers.add(new AttributePollHandler<HttpToolResponse>(config, entity, this)); if (config.getPeriod() > 0) minPeriod = Math.min(minPeriod, config.getPeriod()); }/*ww w . j a v a 2 s .c o m*/ Callable<HttpToolResponse> pollJob; if (pollInfo.method.equals("get")) { pollJob = new Callable<HttpToolResponse>() { public HttpToolResponse call() throws Exception { if (log.isTraceEnabled()) log.trace("http polling for {} sensors at {}", entity, pollInfo); return HttpTool.httpGet(httpClient, pollInfo.uriProvider.get(), pollInfo.headers); } }; } else if (pollInfo.method.equals("post")) { pollJob = new Callable<HttpToolResponse>() { public HttpToolResponse call() throws Exception { if (log.isTraceEnabled()) log.trace("http polling for {} sensors at {}", entity, pollInfo); return HttpTool.httpPost(httpClient, pollInfo.uriProvider.get(), pollInfo.headers, pollInfo.body); } }; } else if (pollInfo.method.equals("head")) { pollJob = new Callable<HttpToolResponse>() { public HttpToolResponse call() throws Exception { if (log.isTraceEnabled()) log.trace("http polling for {} sensors at {}", entity, pollInfo); return HttpTool.httpHead(httpClient, pollInfo.uriProvider.get(), pollInfo.headers); } }; } else { throw new IllegalStateException("Unexpected http method: " + pollInfo.method); } getPoller().scheduleAtFixedRate(pollJob, new DelegatingPollHandler<HttpToolResponse>(handlers), minPeriod); } }
From source file:tiger.ComponentGeneratorProcessor.java
/** * Checks if there are duplicated bindings for the a key. *//*from w w w . j ava 2s . c o m*/ private void checkDuplicateBindings(Collection<NewDependencyInfo> deps) { SetMultimap<NewBindingKey, NewDependencyInfo> map = NewDependencyCollector.collectionToMultimap(deps); for (NewBindingKey key : map.keySet()) { Set<NewDependencyInfo> dependencies = map.get(key); if (dependencies.size() == 1) { continue; } for (NewDependencyInfo info : dependencies) { if (info.isUnique()) { messager.printMessage(Kind.ERROR, String.format( "Key %s has multiple bindings including unique type one(s). Bindings found: %s", key, dependencies)); break; } } } }
From source file:eu.esdihumboldt.hale.ui.cst.debug.metadata.internal.TreeGraphMLProvider.java
/** * @see eu.esdihumboldt.hale.ui.cst.debug.metadata.internal.TreeGraphProvider#generateGraph() *///from w ww . ja va 2 s.c o m @Override public Graph generateGraph() { tree.accept(graphVisitor); SetMultimap<String, String> connections = graphVisitor.getAllConnections(); Set<String> ids = graphVisitor.getAllIds(); TinkerGraph graph = new TinkerGraph(); // add nodes to the graph for (String key : ids) { TransformationNode node = graphVisitor.getNode(key); Vertex vertex = graph.addVertex(key); setVertexProperty(node, vertex); } for (String key : connections.keySet()) { for (String value : connections.get(key)) { graph.addEdge(null, graph.getVertex(key), graph.getVertex(value), " "); } } return graph; }
From source file:org.eclipse.sw360.portal.portlets.FossologyAwarePortlet.java
protected Map<Release, ProjectNamesWithMainlineStatesTuple> getProjectsNamesWithMainlineStatesByRelease( Project project, User user) throws TException { SetMultimap<String, ProjectWithReleaseRelationTuple> releaseIdsToProject = releaseIdToProjects(project, user);//from www . j av a 2s . co m List<Release> releasesById = thriftClients.makeComponentClient() .getFullReleasesById(releaseIdsToProject.keySet(), user); Map<Release, ProjectNamesWithMainlineStatesTuple> projectNamesWithMainlineStatesByRelease = new HashMap<>(); for (Release release : releasesById) { List<String> projectNames = new ArrayList<>(); List<String> mainlineStates = new ArrayList<>(); for (ProjectWithReleaseRelationTuple projectWithReleaseRelation : releaseIdsToProject .get(release.getId())) { projectNames.add(printName(projectWithReleaseRelation.getProject())); mainlineStates.add( ThriftEnumUtils.enumToString(projectWithReleaseRelation.getRelation().getMainlineState())); if (projectNames.size() > 3) { projectNames.add("..."); mainlineStates.add("..."); break; } } projectNamesWithMainlineStatesByRelease.put(release, new ProjectNamesWithMainlineStatesTuple( joinStrings(projectNames), joinStrings(mainlineStates))); } return projectNamesWithMainlineStatesByRelease; }
From source file:org.eclipse.gef4.mvc.examples.logo.parts.FXGeometricCurvePart.java
@SuppressWarnings("serial") public ITransactionalOperation chainModelChanges(final ITransactionalOperation updateVisualOperation) { if (updateVisualOperation == null) { return null; }/*from w w w . j a v a 2 s.co m*/ // determine old and new points final FXGeometricCurve curve = getContent(); final List<Point> oldWayPoints = curve.getWayPointsCopy(); final List<Point> newWayPoints = getVisual().getWayPoints(); // create model operation final ITransactionalOperation updateModelOperation = new ChangeWayPointsOperation("Update Model", curve, oldWayPoints, newWayPoints); // determine current content anchorages AbstractFXGeometricElement<?> sourceContentAnchorage = getAnchorageContent(getVisual().getStartAnchor()); AbstractFXGeometricElement<?> targetContentAnchorage = getAnchorageContent(getVisual().getEndAnchor()); // create anchorage operations, start with detaching all anchorages ContentPolicy<Node> contentPolicy = this.getAdapter(new TypeToken<ContentPolicy<Node>>() { }); contentPolicy.init(); SetMultimap<IVisualPart<Node, ? extends Node>, String> anchorages = HashMultimap.create(getAnchorages()); for (IVisualPart<Node, ? extends Node> anchorage : anchorages.keySet()) { if (anchorage instanceof IContentPart) { for (String role : anchorages.get(anchorage)) { Object contentAnchorage = ((IContentPart<Node, ? extends Node>) anchorage).getContent(); if (role.equals("START")) { if (contentAnchorage != sourceContentAnchorage) { // it changed => detach contentPolicy.detachFromContentAnchorage(contentAnchorage, role); } else { // no change => keep it sourceContentAnchorage = null; } } else if (role.equals("END")) { if (contentAnchorage != targetContentAnchorage) { // it changed => detach contentPolicy.detachFromContentAnchorage(contentAnchorage, role); } else { // no change => keep it targetContentAnchorage = null; } } } } } final ITransactionalOperation detachOperation = contentPolicy.commit(); // then attach source and target (if available) contentPolicy.init(); if (sourceContentAnchorage != null) { contentPolicy.attachToContentAnchorage(sourceContentAnchorage, "START"); } if (targetContentAnchorage != null) { contentPolicy.attachToContentAnchorage(targetContentAnchorage, "END"); } final ITransactionalOperation attachOperation = contentPolicy.commit(); // compose operations return new ForwardUndoCompositeOperation(updateVisualOperation.getLabel()) { { add(updateVisualOperation); add(updateModelOperation); if (detachOperation != null || attachOperation != null) { add(new ReverseUndoCompositeOperation("Change Anchorages") { { if (detachOperation != null) { add(detachOperation); } if (attachOperation != null) { add(attachOperation); } } }); } } }; }