List of usage examples for com.google.common.collect Multimap replaceValues
Collection<V> replaceValues(@Nullable K key, Iterable<? extends V> values);
From source file:org.jclouds.aws.filters.FormSigner.java
public HttpRequest filter(HttpRequest request) throws HttpException { checkNotNull(request.getFirstHeaderOrNull(HttpHeaders.HOST), "request is not ready to sign; host not present"); Multimap<String, String> decodedParams = queryParser() .apply(request.getPayload().getRawContent().toString()); decodedParams.replaceValues(VERSION, ImmutableSet.of(apiVersion)); addSigningParams(decodedParams);/* w ww .j a v a 2 s .c om*/ validateParams(decodedParams); String stringToSign = createStringToSign(request, decodedParams); String signature = sign(stringToSign); addSignature(decodedParams, signature); request = setPayload(request, decodedParams); utils.logRequest(signatureLog, request, "<<"); return request; }
From source file:org.apache.shindig.gadgets.http.HttpResponse.java
/** * Tries to find a valid date from the input headers. * * @return The value of the date header, in milliseconds, or -1 if no Date could be determined. *///ww w . j a va 2 s. c o m private static long getAndUpdateDate(Multimap<String, String> headers) { // Validate the Date header. Must conform to the HTTP date format. long timestamp = -1; long currentTime = getTimeSource().currentTimeMillis(); Collection<String> dates = headers.get("Date"); if (!dates.isEmpty()) { Date d = DateUtil.parseRfc1123Date(dates.iterator().next()); if (d != null) { timestamp = d.getTime(); if (Math.abs(currentTime - timestamp) > responseDateDriftLimit) { // Do not trust the date from response if it is too old (server time out of sync) timestamp = -1; } } } if (timestamp == -1) { timestamp = currentTime; headers.replaceValues("Date", ImmutableList.of(DateUtil.formatRfc1123Date(timestamp))); } return timestamp; }
From source file:org.terasology.config.InputConfig.java
/** * Sets the inputs for a given bind, replacing any previous inputs * @param packageName//from www . ja va 2s. c om * @param bindName * @param inputs */ public void setInputs(String packageName, String bindName, Input... inputs) { Multimap<String, Input> packageMap = getPackageMap(packageName); if (inputs.length == 0) { packageMap.removeAll(bindName); packageMap.put(bindName, new Input()); } else { packageMap.replaceValues(bindName, Arrays.asList(inputs)); } }
From source file:org.jclouds.aws.filters.FormSigner.java
@VisibleForTesting void addSigningParams(Multimap<String, String> params) { params.removeAll(SIGNATURE);/*ww w .j a va 2 s . c o m*/ params.removeAll(SECURITY_TOKEN); Credentials current = creds.get(); if (current instanceof SessionCredentials) { params.put(SECURITY_TOKEN, SessionCredentials.class.cast(current).getSessionToken()); } params.replaceValues(SIGNATURE_METHOD, ImmutableList.of("HmacSHA256")); params.replaceValues(SIGNATURE_VERSION, ImmutableList.of("2")); params.replaceValues(TIMESTAMP, ImmutableList.of(dateService.get())); params.replaceValues(AWS_ACCESS_KEY_ID, ImmutableList.of(creds.get().identity)); }
From source file:org.hudsonci.maven.plugin.dependencymonitor.internal.ProjectArtifactCacheImpl.java
private boolean updateArtifacts(final Multimap<AbstractProject, MavenCoordinatesDTO> collection, final AbstractProject project, final Collection<MavenCoordinatesDTO> artifacts) { assert collection != null; Collection<MavenCoordinatesDTO> removed = collection.replaceValues(project, artifacts); return CollectionsHelper.differs(artifacts, removed); }
From source file:org.spongepowered.common.registry.SpongeVillagerRegistry.java
@Override public VillagerRegistry setMutators(Career career, int level, List<TradeOfferListMutator> generators) { checkArgument(level > 0, "Career level must be at least greater than zero!"); checkNotNull(career, "Career cannot be null!"); checkNotNull(generators, "Generators cannot be null!"); Multimap<Integer, TradeOfferListMutator> multimap = this.careerGeneratorMap.get(career); if (multimap == null) { multimap = ArrayListMultimap.create(3, generators.size()); this.careerGeneratorMap.put(career, multimap); }/* w w w . j a v a 2 s . c om*/ multimap.replaceValues(level, generators); return this; }
From source file:org.jclouds.rest.internal.RestAnnotationProcessor.java
private void addConsumesIfPresentOnTypeOrMethod(Multimap<String, String> headers, Invocation invocation) { Set<String> accept = getAcceptHeaders.apply(invocation); if (!accept.isEmpty()) headers.replaceValues(ACCEPT, accept); }
From source file:org.jclouds.rest.internal.RestAnnotationProcessor.java
private void addProducesIfPresentOnTypeOrMethod(Multimap<String, String> headers, Invocation invocation) { if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(Produces.class)) { Produces header = invocation.getInvokable().getOwnerType().getRawType().getAnnotation(Produces.class); headers.replaceValues(CONTENT_TYPE, asList(header.value())); }//from w w w. j a va 2 s . c o m if (invocation.getInvokable().isAnnotationPresent(Produces.class)) { Produces header = invocation.getInvokable().getAnnotation(Produces.class); headers.replaceValues(CONTENT_TYPE, asList(header.value())); } }
From source file:org.eclipse.xtext.xbase.typesystem.conformance.TypeConformanceComputer.java
protected LightweightTypeReference getTypeParametersForSupertype( final Multimap<JvmType, LightweightTypeReference> all, JvmType rawType, ITypeReferenceOwner owner, List<LightweightTypeReference> initiallyRequested) { EClass rawTypeClass = rawType.eClass(); if (rawTypeClass == TypesPackage.Literals.JVM_GENERIC_TYPE) { // if we do not declare any parameters it is safe to return the first candidate JvmGenericType castedRawType = (JvmGenericType) rawType; if (!hasTypeParameters(castedRawType)) { return getFirstForRawType(all, rawType); }//w w w . j a v a 2 s.c o m ParameterizedTypeReference result = owner.newParameterizedTypeReference(rawType); if (!enhanceSuperType(Lists.newArrayList(all.get(rawType)), initiallyRequested, result)) { return null; } FunctionTypeReference resultAsFunctionType = result.getAsFunctionTypeReference(); if (resultAsFunctionType != null) return resultAsFunctionType; return result; } else if (rawTypeClass == TypesPackage.Literals.JVM_ARRAY_TYPE) { JvmComponentType componentType = ((JvmArrayType) rawType).getComponentType(); Multimap<JvmType, LightweightTypeReference> copiedMultimap = LinkedHashMultimap.create(all); Collection<LightweightTypeReference> originalReferences = all.get(rawType); List<LightweightTypeReference> componentReferences = Lists .newArrayListWithCapacity(originalReferences.size()); for (LightweightTypeReference originalReference : originalReferences) { addComponentType(originalReference, componentReferences); } copiedMultimap.replaceValues(componentType, componentReferences); List<LightweightTypeReference> componentRequests = Lists .newArrayListWithCapacity(initiallyRequested.size()); for (LightweightTypeReference initialRequest : initiallyRequested) { addComponentType(initialRequest, componentRequests); } LightweightTypeReference componentTypeReference = getTypeParametersForSupertype(copiedMultimap, componentType, owner, componentRequests); if (componentTypeReference != null) { return owner.newArrayTypeReference(componentTypeReference); } } return null; }
From source file:com.google.gapid.views.Formatter.java
/** * @return empty list if not a constant, single value for constants, more values, for bitfileds. *///from www.j ava 2s. c om public static Collection<Constant> findConstant(SnippetObject obj, Primitive type) { final ConstantSet constants = ConstantSet.lookup(type); if (constants == null || constants.getEntries().length == 0) { return Collections.emptyList(); } // first, try and find exact match List<Constant> byValue = constants.getByValue(obj.getObject()); if (byValue != null && byValue.size() != 0) { if (byValue.size() == 1) { // perfect, we have just 1 match return byValue; } // try and find the best match Labels labels = Labels.fromSnippets(obj.getSnippets()); Constant result = disambiguate(byValue, labels); return result == null ? Collections.emptyList() : ImmutableList.of(result); } // we can not find any exact match, // but for a number, maybe we can find a combination of constants that match (bit flags) Object value = obj.getObject(); if (!(value instanceof Number) || value instanceof Double || value instanceof Float) { return Collections.emptyList(); } long valueNumber = ((Number) value).longValue(); long leftToFind = valueNumber; Multimap<Number, Constant> resultMap = ArrayListMultimap.create(); for (Constant constant : constants.getEntries()) { long constantValue = ((Number) constant.getValue()).longValue(); if (Long.bitCount(constantValue) == 1 && (valueNumber & constantValue) != 0) { resultMap.put(constantValue, constant); leftToFind &= ~constantValue; // remove bit } } // we did not find enough flags to cover this constant if (leftToFind != 0) { return Collections.emptyList(); } // we found exactly 1 of each constant to cover the whole value if (resultMap.keySet().size() == resultMap.size()) { return resultMap.values(); } // we have more than 1 matching constant per flag to we need to disambiguate Labels labels = Labels.fromSnippets(obj.getSnippets()); for (Number key : resultMap.keySet()) { Collection<Constant> flagConstants = resultMap.get(key); if (flagConstants.size() == 1) { // perfect, we only have 1 value for this continue; } Constant con = disambiguate(flagConstants, labels); if (con != null) { // we have several values, but we found 1 to use resultMap.replaceValues(key, ImmutableList.of(con)); } else { // we have several values and we don't know what one to use return Collections.emptyList(); } } // assert all constants are disambiguated now assert resultMap.keySet().size() == resultMap.size(); return resultMap.values(); }