public List<KafkaPartitionScanSpec> parseTree() { ImmutableMap.Builder<TopicPartition, KafkaPartitionScanSpec> builder = ImmutableMap.builder(); for(KafkaPartitionScanSpec scanSpec : groupScan.getPartitionScanSpecList()) { builder.put(new TopicPartition(scanSpec.getTopicName(), scanSpec.getPartitionId()), scanSpec); } fullScanSpec = builder.build(); List<KafkaPartitionScanSpec> pushdownSpec = le.accept(this, null); /* Non-existing / invalid partitions may result in empty scan spec. This results in a "ScanBatch" with no reader. DRILL currently requires at least one reader to be present in a scan batch. */ if(pushdownSpec != null && pushdownSpec.isEmpty()) { TopicPartition firstPartition = new TopicPartition(groupScan.getKafkaScanSpec().getTopicName(), 0); KafkaPartitionScanSpec emptySpec = new KafkaPartitionScanSpec(firstPartition.topic(),firstPartition.partition(), fullScanSpec.get(firstPartition).getEndOffset(), fullScanSpec.get(firstPartition).getEndOffset()); pushdownSpec.add(emptySpec); } return pushdownSpec; }
this.cellColumnInRowIndices = cellColumnInRowIndices; ImmutableMap.Builder<R, Map<C, V>> rowBuilder = new ImmutableMap.Builder<R, Map<C, V>>(rows.size()); for (Map.Entry<R, Map<C, V>> row : rows.entrySet()) { rowBuilder.put(row.getKey(), ImmutableMap.copyOf(row.getValue())); this.rowMap = rowBuilder.build(); new ImmutableMap.Builder<C, Map<R, V>>(columns.size()); for (Map.Entry<C, Map<R, V>> col : columns.entrySet()) { columnBuilder.put(col.getKey(), ImmutableMap.copyOf(col.getValue())); this.columnMap = columnBuilder.build();
builder.put(domain, PublicSuffixType.fromCode(c));
new ImmutableMap.Builder<K, ImmutableList<V>>(multimap.asMap().size()); int size = 0; ImmutableList<V> list = ImmutableList.copyOf(entry.getValue()); if (!list.isEmpty()) { builder.put(entry.getKey(), list); size += list.size(); return new ImmutableListMultimap<K, V>(builder.build(), size);
private static <K, V> ImmutableSetMultimap<K, V> copyOf( Multimap<? extends K, ? extends V> multimap, Comparator<? super V> valueComparator) { checkNotNull(multimap); // eager for GWT if (multimap.isEmpty() && valueComparator == null) { return of(); } if (multimap instanceof ImmutableSetMultimap) { @SuppressWarnings("unchecked") // safe since multimap is not writable ImmutableSetMultimap<K, V> kvMultimap = (ImmutableSetMultimap<K, V>) multimap; if (!kvMultimap.isPartialView()) { return kvMultimap; } } ImmutableMap.Builder<K, ImmutableSet<V>> builder = new ImmutableMap.Builder<K, ImmutableSet<V>>(multimap.asMap().size()); int size = 0; for (Entry<? extends K, ? extends Collection<? extends V>> entry : multimap.asMap().entrySet()) { K key = entry.getKey(); Collection<? extends V> values = entry.getValue(); ImmutableSet<V> set = valueSet(valueComparator, values); if (!set.isEmpty()) { builder.put(key, set); size += set.size(); } } return new ImmutableSetMultimap<K, V>(builder.build(), size, valueComparator); }
/** * Creates an {@code ImmutableMap<String, String>} from a {@code Properties} * instance. Properties normally derive from {@code Map<Object, Object>}, but * they typically contain strings, which is awkward. This method lets you get * a plain-old-{@code Map} out of a {@code Properties}. * * @param properties a {@code Properties} object to be converted * @return an immutable map containing all the entries in {@code properties} * @throws ClassCastException if any key in {@code Properties} is not a {@code * String} * @throws NullPointerException if any key or value in {@code Properties} is * null */ @GwtIncompatible // java.util.Properties public static ImmutableMap<String, String> fromProperties(Properties properties) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); builder.put(key, properties.getProperty(key)); } return builder.build(); }
/** * Configures this {@code Builder} to order entries by value according to the specified * comparator. * * <p>The sort order is stable, that is, if two entries have values that compare * as equivalent, the entry that was inserted first will be first in the built map's * iteration order. * * @throws IllegalStateException if this method was already called * @since 19.0 */ @CanIgnoreReturnValue @Beta @Override public Builder<K, V> orderEntriesByValue(Comparator<? super V> valueComparator) { super.orderEntriesByValue(valueComparator); return this; }
private static Map<String, Object> createModel(final boolean authEnabled, final SecurityContext sc, final boolean showControls, final Object pageModel) { final boolean isAdmin = !authEnabled /* when auth is disabled every user is an admin user */ || (showControls && sc.isUserInRole(DrillUserPrincipal.ADMIN_ROLE)); final boolean isUserLoggedIn = AuthDynamicFeature.isUserLoggedIn(sc); final ImmutableMap.Builder<String, Object> mapBuilder = ImmutableMap.<String, Object>builder() .put("showStorage", isAdmin) .put("showOptions", isAdmin) .put("showThreads", isAdmin) .put("showLogs", isAdmin) .put("showLogin", authEnabled && showControls && !isUserLoggedIn) .put("showLogout", authEnabled && showControls && isUserLoggedIn) .put("loggedInUserName", authEnabled && showControls && isUserLoggedIn ? sc.getUserPrincipal().getName() : DrillUserPrincipal.ANONYMOUS_USER).put("showControls", showControls); if (pageModel != null) { mapBuilder.put("model", pageModel); } return mapBuilder.build(); } }
/** * Adds all of the given entries to the built map. Duplicate keys are not * allowed, and will cause {@link #build} to fail. * * @throws NullPointerException if any key, value, or entry is null * @since 19.0 */ @CanIgnoreReturnValue @Beta public Builder<K, V> putAll(Iterable<? extends Entry<? extends K, ? extends V>> entries) { if (entries instanceof Collection) { ensureCapacity(size + ((Collection<?>) entries).size()); } for (Entry<? extends K, ? extends V> entry : entries) { put(entry); } return this; }
/** * Associates all of {@code map's} keys and values in the built map. * Duplicate keys are not allowed, and will cause {@link #build} to fail. * * @throws NullPointerException if any key or value in {@code map} is null * @throws ClassCastException if any value is not an instance of the type * specified by its key */ @CanIgnoreReturnValue public <T extends B> Builder<B> putAll(Map<? extends Class<? extends T>, ? extends T> map) { for (Entry<? extends Class<? extends T>, ? extends T> entry : map.entrySet()) { Class<? extends T> type = entry.getKey(); T value = entry.getValue(); mapBuilder.put(type, cast(type, value)); } return this; }
/** * Returns a new instance of {@link ImmutableMap} with key case-insensitivity. This map is built from the given * map. See {@link ImmutableMap}. * * @param map map to copy from * @param <VALUE> type of values to be stored in the map * @return key case-insensitive immutable map */ public static <VALUE> CaseInsensitiveMap<VALUE> newImmutableMap(final Map<? extends String, ? extends VALUE> map) { final ImmutableMap.Builder<String, VALUE> builder = ImmutableMap.builder(); for (final Entry<? extends String, ? extends VALUE> entry : map.entrySet()) { builder.put(entry.getKey().toLowerCase(), entry.getValue()); } return new CaseInsensitiveMap<>(builder.build()); }
/** * Parses a serialized trie representation of a map of reversed public suffixes into an immutable * map of public suffixes. */ static ImmutableMap<String, PublicSuffixType> parseTrie(CharSequence encoded) { ImmutableMap.Builder<String, PublicSuffixType> builder = ImmutableMap.builder(); int encodedLen = encoded.length(); int idx = 0; while (idx < encodedLen) { idx += doParseTrieToBuilder( Lists.<CharSequence>newLinkedList(), encoded.subSequence(idx, encodedLen), builder); } return builder.build(); }
/** * Returns a new immutable class-to-instance map containing the entries * provided to this builder. * * @throws IllegalArgumentException if duplicate keys were added */ public ImmutableClassToInstanceMap<B> build() { ImmutableMap<Class<? extends B>, B> map = mapBuilder.build(); if (map.isEmpty()) { return of(); } else { return new ImmutableClassToInstanceMap<B>(map); } } }
public LogicalPlan build() { return new LogicalPlan(this.planProperties, this.storageEngines.build(), this.operators.build()); } }
/** * Adds the given {@code entry} to the map, making it immutable if * necessary. Duplicate keys, according to the comparator (which might be * the keys' natural order), are not allowed, and will cause {@link #build} * to fail. * * @since 11.0 */ @CanIgnoreReturnValue @Override public Builder<K, V> put(Entry<? extends K, ? extends V> entry) { super.put(entry); return this; }
/** * Adds the given {@code entry} to the bimap. Duplicate keys or values * are not allowed, and will cause {@link #build} to fail. * * @since 19.0 */ @CanIgnoreReturnValue @Override public Builder<K, V> put(Entry<? extends K, ? extends V> entry) { super.put(entry); return this; }