List of usage examples for com.google.common.collect Multimap entries
Collection<Map.Entry<K, V>> entries();
From source file:eu.esdihumboldt.hale.common.align.model.transformation.tree.context.impl.IdentityHashMultimap.java
@Override public boolean putAll(Multimap<? extends K, ? extends V> multimap) { // FIXME can be done more efficient boolean changed = false; for (Map.Entry<? extends K, ? extends V> entry : multimap.entries()) { changed |= put(entry.getKey(), entry.getValue()); }//ww w . j av a2 s .c o m return changed; }
From source file:com.hubrick.vertx.rest.converter.MultipartHttpMessageConverter.java
private void writeParts(HttpOutputMessage httpOutputMessage, Multimap<String, Part> parts, String boundary) throws IOException { for (Map.Entry<String, Part> entry : parts.entries()) { String name = entry.getKey(); if (entry.getValue() != null) { writeBoundary(httpOutputMessage, boundary); writePart(name, entry.getValue(), httpOutputMessage); writeNewLine(httpOutputMessage); }//from www . java2s.co m } }
From source file:org.eclipse.viatra.transformation.runtime.emf.rules.eventdriven.EventDrivenTransformationRule.java
public EventDrivenTransformationRule(String name, IQuerySpecification<Matcher> precondition, Multimap<CRUDActivationStateEnum, IMatchProcessor<Match>> stateActions, ActivationLifeCycle lifeCycle, EventFilter<? super Match> filter) { this.name = name; Set<Job<Match>> jobs = Sets.newHashSet(); for (Entry<CRUDActivationStateEnum, IMatchProcessor<Match>> stateAction : stateActions.entries()) { CRUDActivationStateEnum state = stateAction.getKey(); IMatchProcessor<Match> action = stateAction.getValue(); jobs.add(Jobs.newStatelessJob(state, action)); }//from www. j a v a 2 s . c om ruleSpecification = Rules.newMatcherRuleSpecification(precondition, lifeCycle, jobs, name); this.filter = filter; }
From source file:io.datakernel.cube.LogToCubeMetadataStorageStub.java
@Override public void saveCommit(String log, Map<AggregationMetadata, String> idMap, Map<String, LogPosition> oldPositions, Map<String, LogPosition> newPositions, Multimap<AggregationMetadata, AggregationChunk.NewChunk> newChunks, CompletionCallback callback) { Map<String, LogPosition> logPositionMap = ensureLogPositions(log); logPositionMap.putAll(newPositions); callback.onComplete();/*from ww w . j ava 2 s . c o m*/ for (Map.Entry<AggregationMetadata, AggregationChunk.NewChunk> entry : newChunks.entries()) { AggregationChunk.NewChunk newChunk = entry.getValue(); String aggregationId = idMap.get(entry.getKey()); cubeMetadataStorage.doSaveChunk(aggregationId, singletonList(newChunk), callback); } }
From source file:org.apache.pulsar.broker.loadbalance.impl.WRRPlacementStrategy.java
/** * <code>//from ww w . java2s . co m * Function : getByWeightedRoundRobin * returns ResourceUnit selected by WRR algorithm based on available resource on RU * ^ * | * | * | * | | | | | * | | | | | * | Broker 2 | Broker 3 | Broker 1 | B4 | * | | | | | * +----------------+------------------------+--------------------------------+---------> * 0 20 50 90 100 * * This is weighted Round robin, we calculate weight based on availability of resources; * total availability is taken as a full range then each broker is given range based on * its resource availability, if the number generated within total range happens to be in * broker's range, that broker is selected * </code> */ public ResourceUnit findBrokerForPlacement(Multimap<Long, ResourceUnit> finalCandidates) { if (finalCandidates.isEmpty()) { return null; } log.debug("Total Final Candidates selected - [{}]", finalCandidates.size()); int totalAvailability = 0; for (Map.Entry<Long, ResourceUnit> candidateOwner : finalCandidates.entries()) { totalAvailability += candidateOwner.getKey().intValue(); } ResourceUnit selectedRU = null; if (totalAvailability <= 0) { // todo: this means all the brokers are overloaded and we can't assign this namespace to any broker // for now, pick anyone and return that one, because when we don't have ranking we put O for each broker return Iterables.get(finalCandidates.get(0L), rand.nextInt(finalCandidates.size())); } int weightedSelector = rand.nextInt(totalAvailability); log.debug("Generated Weighted Selector Number - [{}] ", weightedSelector); int weightRangeSoFar = 0; for (Map.Entry<Long, ResourceUnit> candidateOwner : finalCandidates.entries()) { weightRangeSoFar += candidateOwner.getKey(); if (weightedSelector < weightRangeSoFar) { selectedRU = candidateOwner.getValue(); log.debug(" Weighted Round Robin Selected RU - [{}]", candidateOwner.getValue().getResourceId()); break; } } return selectedRU; }
From source file:com.palantir.atlasdb.keyvalue.partition.BasicPartitionMap.java
private <ValType> Map<KeyValueService, Multimap<Cell, ValType>> getServicesForCellsMultimap(String tableName, Multimap<Cell, ValType> cellMultimap) { Map<KeyValueService, Multimap<Cell, ValType>> result = Maps.newHashMap(); for (Map.Entry<Cell, ValType> e : cellMultimap.entries()) { Set<KeyValueService> services = getServicesHavingRow(e.getKey().getRowName()); for (KeyValueService kvs : services) { if (!result.containsKey(kvs)) { result.put(kvs, HashMultimap.<Cell, ValType>create()); }//from w w w .j ava 2s . c o m assert !result.get(kvs).containsEntry(e.getKey(), e.getValue()); result.get(kvs).put(e.getKey(), e.getValue()); } } if (!cellMultimap.isEmpty()) { assert result.keySet().size() >= quorumParameters.getReplicationFactor(); } return result; }
From source file:org.apache.apex.malhar.lib.state.spillable.SpillableArrayListMultimapImpl.java
@Override public boolean putAll(Multimap<? extends K, ? extends V> multimap) { boolean changed = false; for (Map.Entry<? extends K, ? extends V> entry : multimap.entries()) { changed |= put(entry.getKey(), entry.getValue()); }//from w w w . j a v a2 s . c o m return changed; }
From source file:org.jclouds.cloudstack.filters.QuerySigner.java
@VisibleForTesting public String createStringToSign(HttpRequest request, Multimap<String, String> decodedParams) { utils.logRequest(signatureLog, request, ">>"); // encode each parameter value first, ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.naturalOrder(); for (Map.Entry<String, String> entry : decodedParams.entries()) builder.add(entry.getKey() + "=" + Strings2.urlEncode(entry.getValue())); // then, lower case the entire query string String stringToSign = Joiner.on('&').join(builder.build()).toLowerCase(); if (signatureWire.enabled()) signatureWire.output(stringToSign); return stringToSign; }
From source file:com.google.api.explorer.client.embedded.EmbeddedParameterFormPresenter.java
public void submit() { Preconditions.checkState(method != null); final RestApiRequest req = new RestApiRequest(service, method); // If the user has declared a body, set it on the request. String body = display.getBodyText(); if (!body.isEmpty()) { req.body = body;/*from ww w .j a v a2 s . co m*/ req.addHeader("Content-Type", "application/json"); } Multimap<String, String> paramValues = display.getParameterValues(); for (Map.Entry<String, String> entry : paramValues.entries()) { if (entry.getValue().isEmpty()) { continue; } req.getParamValues().put(entry.getKey(), entry.getValue()); } // Do not send the API key if the service is a public-only API. req.setUseApiKey(!ExplorerConfig.PUBLIC_ONLY_APIS.contains(service.getName())); // Set the auth header if we have a token. AuthToken oauth2Token = authManager.getToken(service); if (oauth2Token != null) { req.addHeader("Authorization", "Bearer " + oauth2Token.getAuthToken()); } display.setExecuting(true); final long start = System.currentTimeMillis(); req.send(new AsyncCallback<ApiResponse>() { @Override public void onSuccess(ApiResponse response) { display.setExecuting(false); callback.finished(req, response, start, System.currentTimeMillis()); } @Override public void onFailure(Throwable caught) { display.setExecuting(false); // TODO(jasonhall): Better error handling when request fails (i.e., // cannot communicate at all). Window.alert("An error occured: " + caught.getMessage()); } }); // This has to be after the actual send so that the API key gets initialized properly. callback.starting(req); }
From source file:org.jclouds.ecs.filters.QuerySigner.java
@VisibleForTesting public String createStringToSign(HttpRequest request, Multimap<String, String> decodedParams) { utils.logRequest(signatureLog, request, ">>"); // encode each parameter value first, ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.naturalOrder(); for (Map.Entry<String, String> entry : decodedParams.entries()) builder.add(entry.getKey() + "=" + Strings2.urlEncode(entry.getValue())); // then, lower case the entire query string String stringToSign = Joiner.on('&').join(builder.build()); if (signatureWire.enabled()) signatureWire.output(stringToSign); stringToSign = "GET&" + URLEncoder.encode("/") + "&" + URLEncoder.encode(stringToSign); System.out.println("------------------------------"); System.out.println(stringToSign); System.out.println("------------------------------"); return stringToSign; }