List of usage examples for com.google.common.collect Multimaps forMap
public static <K, V> SetMultimap<K, V> forMap(Map<K, V> map)
From source file:org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication.java
HttpRequest replaceDateHeader(HttpRequest request) { Builder<String, String> builder = ImmutableMap.builder(); String date = timeStampProvider.get(); builder.put(HttpHeaders.DATE, date); request = request.toBuilder().replaceHeaders(Multimaps.forMap(builder.build())).build(); return request; }
From source file:brooklyn.networking.cloudstack.HttpUtil.java
public static HttpToolResponse httpPost(HttpClient httpClient, URI uri, Map<String, String> headers, byte[] body) { return httpPost(httpClient, uri, Multimaps.forMap(headers), body); }
From source file:org.apache.isis.core.runtime.services.publish.PublishedObjectsDefault.java
private static <T, S> Map<T, Collection<S>> invert(final Map<S, T> valueByKey) { return new TreeMap<>( Multimaps.invertFrom(Multimaps.forMap(valueByKey), ArrayListMultimap.<T, S>create()).asMap()); }
From source file:google.registry.tools.GetSchemaTreeCommand.java
@Override public void run() throws Exception { // Get the @Parent type for each class. Map<Class<?>, Class<?>> entityToParentType = new HashMap<>(); for (Class<?> clazz : ALL_CLASSES) { entityToParentType.put(clazz, getParentType(clazz)); }//www . j a va 2 s .co m // Find super types like EppResource that are used as parents in place of actual entity types. Set<Class<?>> superclasses = new HashSet<>(); for (Class<?> clazz : ALL_CLASSES) { Class<?> parentType = entityToParentType.get(clazz); if (!ALL_CLASSES.contains(parentType) && !Object.class.equals(parentType)) { superclasses.add(parentType); } } // Find the subclasses for each superclass we just found, and map them to their superclasses. Map<Class<?>, Class<?>> subclassToSuperclass = new HashMap<>(); for (Class<?> clazz : ALL_CLASSES) { for (Class<?> superclass : superclasses) { if (superclass.isAssignableFrom(clazz)) { subclassToSuperclass.put(clazz, superclass); break; } } } // Map @EntitySubclass classes to their superclasses. for (Class<?> clazz : ALL_CLASSES) { if (clazz.isAnnotationPresent(EntitySubclass.class)) { Class<?> entityClass = clazz; while (!entityClass.isAnnotationPresent(Entity.class)) { entityClass = entityClass.getSuperclass(); } if (subclassToSuperclass.containsKey(clazz)) { subclassToSuperclass.put(entityClass, subclassToSuperclass.get(clazz)); } subclassToSuperclass.put(clazz, entityClass); } } // Build the parentage hierarchy, replacing subclasses with superclasses wherever possible. for (Class<?> clazz : ALL_CLASSES) { Class<?> superclass = clazz; while (subclassToSuperclass.containsKey(superclass)) { superclass = subclassToSuperclass.get(superclass); } hierarchy.put(entityToParentType.get(clazz), superclass == null ? clazz : superclass); } // Build up the superclass to subclass mapping. superclassToSubclasses = Multimaps.invertFrom(Multimaps.forMap(subclassToSuperclass), TreeMultimap.<Class<?>, Class<?>>create(arbitrary(), new PrintableNameOrdering())); printTree(Object.class, 0); }
From source file:org.pau.assetmanager.viewmodel.MonthlyReportViewModel.java
/** * @param annotations/*w w w .java 2 s. c om*/ * @return the multimap 'Year of Annotaion' --> 'Annotations Involved' */ private static Multimap<Integer, Annotation> getYearToAnnotationMultimapFromAnnotations( Collection<Annotation> annotations) { ImmutableMap<Annotation, Integer> annotationToYear = Maps.toMap(annotations, new Function<Annotation, Integer>() { @Override public Integer apply(Annotation input) { Calendar calendar = GregorianCalendar.getInstance(); calendar.setTime(input.getDate()); return calendar.get(Calendar.YEAR); } }); ListMultimap<Integer, Annotation> yearToAnnotationMultimap = Multimaps .invertFrom(Multimaps.forMap(annotationToYear), ArrayListMultimap.<Integer, Annotation>create()); return yearToAnnotationMultimap; }
From source file:com.spotify.helios.client.HeliosClient.java
private URI uri(final String path, final Map<String, String> query) { return uri(path, Multimaps.forMap(query)); }
From source file:com.palantir.atlasdb.schema.KvsRangeMigrator.java
protected void retryWriteToKvs(Map<Cell, byte[]> writeMap) { Multimap<Cell, Long> keys = Multimaps .forMap(Maps2.createConstantValueMap(writeMap.keySet(), migrationTimestamp)); writeKvs.delete(destTable, keys);//from w w w . jav a 2 s . co m writeKvs.put(destTable, writeMap, migrationTimestamp); }
From source file:org.jclouds.blobstore.TransientStorageStrategy.java
private Blob createUpdatedCopyOfBlobInContainer(String containerName, Blob in) { checkNotNull(in, "blob"); checkNotNull(in.getPayload(), "blob.payload"); ByteArrayPayload payload = (in.getPayload() instanceof ByteArrayPayload) ? ByteArrayPayload.class.cast(in.getPayload()) : null;//from w ww . j a v a 2 s. c o m if (payload == null) payload = (in.getPayload() instanceof DelegatingPayload) ? (DelegatingPayload.class.cast(in.getPayload()).getDelegate() instanceof ByteArrayPayload) ? ByteArrayPayload.class .cast(DelegatingPayload.class.cast(in.getPayload()).getDelegate()) : null : null; try { if (payload == null || !(payload instanceof ByteArrayPayload)) { MutableContentMetadata oldMd = in.getPayload().getContentMetadata(); ByteArrayOutputStream out = new ByteArrayOutputStream(); in.getPayload().writeTo(out); payload = (ByteArrayPayload) Payloads.calculateMD5(Payloads.newPayload(out.toByteArray())); HttpUtils.copy(oldMd, payload.getContentMetadata()); } else { if (payload.getContentMetadata().getContentMD5() == null) Payloads.calculateMD5(in); } } catch (IOException e) { Throwables.propagate(e); } Blob blob = blobFactory.create(BlobStoreUtils.copy(in.getMetadata())); blob.setPayload(payload); blob.getMetadata().setContainer(containerName); blob.getMetadata().setUri(uriBuilder(new StringBuilder("mem://").append(containerName)) .path(in.getMetadata().getName()).build()); blob.getMetadata().setLastModified(new Date()); String eTag = base16().lowerCase().encode(payload.getContentMetadata().getContentMD5()); blob.getMetadata().setETag(eTag); // Set HTTP headers to match metadata blob.getAllHeaders().replaceValues(HttpHeaders.LAST_MODIFIED, ImmutableList.of(dateService.rfc822DateFormat(blob.getMetadata().getLastModified()))); blob.getAllHeaders().replaceValues(HttpHeaders.ETAG, ImmutableList.of(eTag)); copyPayloadHeadersToBlob(payload, blob); blob.getAllHeaders().putAll(Multimaps.forMap(blob.getMetadata().getUserMetadata())); return blob; }
From source file:com.ning.http.client.RequestBuilderBase.java
public T setParameters(Map<String, String> parameters) throws IllegalArgumentException { if ((request.type != RequestType.POST) && (request.type != RequestType.PUT)) { throw new IllegalArgumentException("Request type has to POST or PUT for form parameters"); }//from w w w . ja va 2 s .c o m resetNonMultipartData(); resetMultipartData(); request.params = LinkedListMultimap.create(Multimaps.forMap(parameters)); return derived.cast(this); }
From source file:com.twitter.aurora.scheduler.http.SchedulerzJob.java
private static Map<String, SchedulingDetails> buildSchedulingTable(Iterable<IAssignedTask> tasks) { Map<Integer, ITaskConfig> byInstance = Maps .transformValues(Maps.uniqueIndex(tasks, Tasks.ASSIGNED_TO_INSTANCE_ID), Tasks.ASSIGNED_TO_INFO); Map<Integer, SchedulingDetails> detailsByInstance = Maps.transformValues(byInstance, CONFIG_TO_DETAILS); Multimap<SchedulingDetails, Integer> instancesByDetails = Multimaps .invertFrom(Multimaps.forMap(detailsByInstance), HashMultimap.<SchedulingDetails, Integer>create()); Map<SchedulingDetails, String> instanceStringsByDetails = Maps.transformValues(instancesByDetails.asMap(), TransformationUtils.INSTANCES_TOSTRING); return HashBiMap.create(instanceStringsByDetails).inverse(); }