List of usage examples for com.google.common.collect ImmutableMultimap builder
public static <K, V> Builder<K, V> builder()
From source file:org.jclouds.http.okhttp.OkHttpCommandExecutorService.java
@Override protected HttpResponse invoke(Request nativeRequest) throws IOException, InterruptedException { OkHttpClient requestScopedClient = globalClient.clone(); requestScopedClient.setProxy(proxyForURI.apply(nativeRequest.uri())); Response response = requestScopedClient.newCall(nativeRequest).execute(); HttpResponse.Builder<?> builder = HttpResponse.builder(); builder.statusCode(response.code()); builder.message(response.message()); Builder<String, String> headerBuilder = ImmutableMultimap.builder(); Headers responseHeaders = response.headers(); for (String header : responseHeaders.names()) { headerBuilder.putAll(header, responseHeaders.values(header)); }//from w w w . j a v a 2 s . co m ImmutableMultimap<String, String> headers = headerBuilder.build(); if (response.code() == 204 && response.body() != null) { response.body().close(); } else { Payload payload = newInputStreamPayload(response.body().byteStream()); contentMetadataCodec.fromHeaders(payload.getContentMetadata(), headers); builder.payload(payload); } builder.headers(filterOutContentHeaders(headers)); return builder.build(); }
From source file:org.graylog2.search.SearchQueryParser.java
public SearchQuery parse(String queryString) { if (Strings.isNullOrEmpty(queryString) || "*".equals(queryString)) { return new SearchQuery(queryString); }//from ww w.j av a 2s . c o m final Matcher matcher = querySplitterMatcher(requireNonNull(queryString).trim()); final ImmutableMultimap.Builder<String, FieldValue> builder = ImmutableMultimap.builder(); final ImmutableSet.Builder<String> disallowedKeys = ImmutableSet.builder(); while (matcher.find()) { final String entry = matcher.group(); if (!entry.contains(":")) { builder.put(defaultField, createFieldValue(defaultFieldKey, entry, false)); continue; } final Iterator<String> entryFields = FIELD_VALUE_SPLITTER.splitToList(entry).iterator(); checkArgument(entryFields.hasNext(), INVALID_ENTRY_MESSAGE, entry); final String key = entryFields.next(); // Skip if there are no valid k/v pairs. (i.e. "action:") if (!entryFields.hasNext()) { continue; } final boolean negate = key.startsWith("-"); final String cleanKey = key.replaceFirst("^-", ""); final String value = entryFields.next(); VALUE_SPLITTER.splitToList(value).forEach(v -> { if (!dbFieldMapping.containsKey(cleanKey)) { disallowedKeys.add(cleanKey); } final SearchQueryField translatedKey = dbFieldMapping.get(cleanKey); if (translatedKey != null) { builder.put(translatedKey.getDbField(), createFieldValue(translatedKey, v, negate)); } else { builder.put(defaultField, createFieldValue(defaultFieldKey, v, negate)); } }); checkArgument(!entryFields.hasNext(), INVALID_ENTRY_MESSAGE, entry); } return new SearchQuery(queryString, builder.build(), disallowedKeys.build()); }
From source file:com.isotrol.impe3.nr.api.Node.java
public Multimap<String, String> getHighlight() { if (highlight == null) { if (highlightMap != null) { ImmutableMultimap.Builder<String, String> b = ImmutableMultimap.builder(); for (Entry<String, Collection<String>> entry : highlightMap.entrySet()) { final Collection<String> values = entry.getValue(); if (values != null) { b.putAll(entry.getKey(), values); }/*from ww w. ja v a 2s . c o m*/ } highlight = b.build(); } else { highlight = ImmutableMultimap.of(); } } return highlight; }
From source file:org.basepom.mojo.duplicatefinder.artifact.ArtifactFileResolver.java
public ImmutableMultimap<File, Artifact> resolveArtifactsForScopes(final Set<String> scopes) throws InvalidVersionSpecificationException, DependencyResolutionRequiredException { checkNotNull(scopes, "scopes is null"); final ImmutableMultimap.Builder<File, Artifact> inScopeBuilder = ImmutableMultimap.builder(); for (final Artifact artifact : listArtifacts()) { if (artifact.getArtifactHandler().isAddedToClasspath()) { if (scopes.isEmpty() || scopes.contains(artifact.getScope())) { final File file = resolveFileForArtifact(artifact); checkState(file != null, "No file for artifact '%s' found!", artifact); inScopeBuilder.put(file, artifact); }/* ww w .j a v a 2 s.co m*/ } } return inScopeBuilder.build(); }
From source file:org.apache.beam.runners.flink.translation.functions.FlinkBatchSideInputHandlerFactory.java
private <K, V, W extends BoundedWindow> SideInputHandler<V, W> forMultimapSideInput( List<WindowedValue<KV<K, V>>> broadcastVariable, Coder<K> keyCoder, Coder<V> valueCoder, Coder<W> windowCoder) {//from w w w. ja v a 2 s. com ImmutableMultimap.Builder<SideInputKey, V> multimap = ImmutableMultimap.builder(); for (WindowedValue<KV<K, V>> windowedValue : broadcastVariable) { K key = windowedValue.getValue().getKey(); V value = windowedValue.getValue().getValue(); for (BoundedWindow boundedWindow : windowedValue.getWindows()) { @SuppressWarnings("unchecked") W window = (W) boundedWindow; multimap.put(SideInputKey.of(keyCoder.structuralValue(key), windowCoder.structuralValue(window)), value); } } return new MultimapSideInputHandler<>(multimap.build(), keyCoder, valueCoder, windowCoder); }
From source file:com.cdancy.artifactory.rest.config.ArtifactoryOkHttpCommandExecutorService.java
@Override protected HttpResponse invoke(Request nativeRequest) throws IOException, InterruptedException { OkHttpClient requestScopedClient = clientSupplier.get(); requestScopedClient.setProxy(proxyForURI.apply(nativeRequest.uri())); Response response = requestScopedClient.newCall(nativeRequest).execute(); HttpResponse.Builder<?> builder = HttpResponse.builder(); builder.statusCode(response.code()); builder.message(response.message()); Builder<String, String> headerBuilder = ImmutableMultimap.builder(); Headers responseHeaders = response.headers(); // Check for Artifactory header and init potential file for downstream use File destinationFile = null;//from w w w . j a va 2 s. co m String artFileName = responseHeaders.get("X-Artifactory-Filename"); if (artFileName != null) { GAVCoordinates gavCoordinates = ArtifactoryUtils.gavFromURL(nativeRequest.url(), endpoint.get().toURL()); destinationFile = ArtifactoryUtils.getGradleFile(gavCoordinates, artFileName, responseHeaders.get("ETag")); headerBuilder.put(ArtifactoryUtils.LOCATION_HEADER, destinationFile.getAbsolutePath()); } for (String header : responseHeaders.names()) { headerBuilder.putAll(header, responseHeaders.values(header)); } ImmutableMultimap<String, String> headers = headerBuilder.build(); if (response.code() == 204 && response.body() != null) { response.body().close(); } else { if (destinationFile != null) { if (!destinationFile.exists() || (destinationFile.length() != response.body().contentLength())) { InputStream inputStream = null; try { inputStream = response.body().byteStream(); ArtifactoryUtils.resolveInputStream(inputStream, destinationFile); } catch (Exception e) { Throwables.propagate(e); } finally { if (inputStream != null) { inputStream.close(); } } } IOUtils.closeQuietly(response.body().byteStream()); } else { Payload payload = newInputStreamPayload(response.body().byteStream()); contentMetadataCodec.fromHeaders(payload.getContentMetadata(), headers); builder.payload(payload); } } builder.headers(filterOutContentHeaders(headers)); return builder.build(); }
From source file:org.opendaylight.mdsal.dom.broker.DOMNotificationRouter.java
@Override public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener( final T listener, final Collection<SchemaPath> types) { final ListenerRegistration<T> reg = new AbstractListenerRegistration<T>(listener) { @Override//from ww w . j a v a2 s.c o m protected void removeRegistration() { final ListenerRegistration<T> me = this; synchronized (DOMNotificationRouter.this) { replaceListeners(ImmutableMultimap.copyOf(Multimaps.filterValues(listeners, new Predicate<ListenerRegistration<? extends DOMNotificationListener>>() { @Override public boolean apply( final ListenerRegistration<? extends DOMNotificationListener> input) { return input != me; } }))); } } }; if (!types.isEmpty()) { final Builder<SchemaPath, ListenerRegistration<? extends DOMNotificationListener>> b = ImmutableMultimap .builder(); b.putAll(listeners); for (final SchemaPath t : types) { b.put(t, reg); } replaceListeners(b.build()); } return reg; }
From source file:com.outerspacecat.icalendar.VEvent.java
/** * Creates a new VEVENT./*from www. j a v a2 s . c o m*/ * * @param uid the uid. Must be non {@code null}. * @param sequence the sequence number. May be {@code null}. * @param dtStamp the DTSTAMP instant. Must be non {@code null}. * @param created the created instant. May be {@code null}. * @param created the last modified instant. May be {@code null}. * @param schedule the schedule. Must be non {@code null}. * @param recurrenceData the recurrence data. Must be non {@code null}. */ public VEvent(final TypedProperty<TextType> uid, final TypedProperty<Integer> sequence, final TypedProperty<Instant> dtStamp, final TypedProperty<Instant> created, final TypedProperty<Instant> lastModified, final Schedule schedule, final RecurrenceData recurrenceData, final TypedProperty<UriType> organizer, final TypedProperty<TextType> status, final TypedProperty<TextType> summary, final TypedProperty<TextType> description, final TypedProperty<TextType> location, final TypedProperty<TextType> classification, final TypedProperty<Boolean> transparent, final TypedProperty<Integer> priority, final TypedProperty<UriType> url, final TypedProperty<GeoType> geo, final Iterable<Attendee> attendees, final Iterable<TypedProperty<ImmutableSet<TextType>>> categories, final Iterable<TypedProperty<TextType>> comments, final Iterable<TypedProperty<ImmutableSet<TextType>>> resources, final Iterable<TypedProperty<TextType>> contacts, final Iterable<Property> extraProperties, final Iterable<Component> extraComponents) { Preconditions.checkNotNull(uid, "uid required"); Preconditions.checkNotNull(dtStamp, "dtStamp required"); Preconditions.checkNotNull(schedule, "schedule required"); Preconditions.checkNotNull(recurrenceData, "recurrenceData required"); Preconditions.checkNotNull(attendees, "attendees required"); Preconditions.checkNotNull(categories, "categories required"); Preconditions.checkNotNull(comments, "comments required"); Preconditions.checkNotNull(resources, "resources required"); Preconditions.checkNotNull(contacts, "contacts required"); Preconditions.checkNotNull(extraProperties, "extraProperties required"); Preconditions.checkNotNull(extraComponents, "extraComponents required"); this.uid = uid; this.sequence = sequence; this.dtStamp = dtStamp; this.created = created; this.lastModified = lastModified; this.schedule = schedule; this.recurrenceId = null; this.recurrenceData = recurrenceData; this.organizer = organizer; this.status = status; this.summary = summary; this.description = description; this.location = location; this.classification = classification; this.transparent = transparent; this.priority = priority; this.url = url; this.geo = geo; this.attendees = ImmutableSet.copyOf(attendees); this.categories = ImmutableSet.copyOf(categories); this.comments = ImmutableSet.copyOf(comments); this.resources = ImmutableSet.copyOf(resources); this.contacts = ImmutableSet.copyOf(contacts); ImmutableMultimap.Builder<String, Property> extraPropertiesBuilder = ImmutableMultimap.builder(); for (Property prop : extraProperties) extraPropertiesBuilder.put(prop.getName().getName(), prop); this.extraProperties = extraPropertiesBuilder.build(); ImmutableMultimap.Builder<String, Component> extraComponentsBuilder = ImmutableMultimap.builder(); for (Component comp : extraComponents) extraComponentsBuilder.put(comp.getName(), comp); this.extraComponents = extraComponentsBuilder.build(); }
From source file:org.jclouds.aws.util.AWSUtils.java
public static <R extends HttpRequest> R indexMultimapToFormValuesWithPrefix(R request, String prefix, String keySuffix, String valueSuffix, Object input) { checkArgument(checkNotNull(input, "input") instanceof Multimap<?, ?>, "this binder is only valid for Multimap<?,?>: " + input.getClass()); Multimap<Object, Object> map = (Multimap<Object, Object>) input; Builder<String, String> builder = ImmutableMultimap.builder(); int i = 1;//from ww w . jav a 2 s .c om for (Map.Entry<Object, Collection<Object>> entry : map.asMap().entrySet()) { builder.put(prefix + "." + i + "." + keySuffix, checkNotNull(entry.getKey().toString(), keySuffix.toLowerCase() + "s[" + i + "]")); int j = 1; for (Object v : entry.getValue()) { builder.put(prefix + "." + i + "." + valueSuffix + "." + j, v.toString()); j++; } i++; } ImmutableMultimap<String, String> forms = builder.build(); return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build(); }
From source file:com.facebook.presto.accumulo.index.Indexer.java
public Indexer(Connector connector, Authorizations auths, AccumuloTable table, BatchWriterConfig writerConfig) throws TableNotFoundException { this.connector = requireNonNull(connector, "connector is null"); this.table = requireNonNull(table, "table is null"); this.writerConfig = requireNonNull(writerConfig, "writerConfig is null"); requireNonNull(auths, "auths is null"); this.serializer = table.getSerializerInstance(); // Create our batch writer indexWriter = connector.createBatchWriter(table.getIndexTableName(), writerConfig); ImmutableMultimap.Builder<ByteBuffer, ByteBuffer> indexColumnsBuilder = ImmutableMultimap.builder(); Map<ByteBuffer, Map<ByteBuffer, Type>> indexColumnTypesBuilder = new HashMap<>(); // Initialize metadata table.getColumns().forEach(columnHandle -> { if (columnHandle.isIndexed()) { // Wrap the column family and qualifier for this column and add it to // collection of indexed columns ByteBuffer family = wrap(columnHandle.getFamily().get().getBytes(UTF_8)); ByteBuffer qualifier = wrap(columnHandle.getQualifier().get().getBytes(UTF_8)); indexColumnsBuilder.put(family, qualifier); // Create a mapping for this column's Presto type, again creating a new one for the // family if necessary Map<ByteBuffer, Type> types = indexColumnTypesBuilder.get(family); if (types == null) { types = new HashMap<>(); indexColumnTypesBuilder.put(family, types); }// w w w.j av a2 s .com types.put(qualifier, columnHandle.getType()); } }); indexColumns = indexColumnsBuilder.build(); indexColumnTypes = ImmutableMap.copyOf(indexColumnTypesBuilder); // If there are no indexed columns, throw an exception if (indexColumns.isEmpty()) { throw new PrestoException(NOT_SUPPORTED, "No indexed columns in table metadata. Refusing to index a table with no indexed columns"); } // Initialize metrics map // This metrics map is for column cardinality metrics.put(METRICS_TABLE_ROW_COUNT, new AtomicLong(0)); // Scan the metrics table for existing first row and last row Pair<byte[], byte[]> minmax = getMinMaxRowIds(connector, table, auths); firstRow = minmax.getLeft(); lastRow = minmax.getRight(); }