/** * Get all of the values. If reset is true, we will reset the all AtomicLongs back to 0. * @param reset whether to reset the AtomicLongs to 0. * @return A Map of String -> Long for metrics */ public Map<String, Long> getMetricsMap(boolean reset) { // Create a builder ImmutableMap.Builder<String, Long> builder = ImmutableMap.builder(); for (Map.Entry<String, AtomicLong> e : this.counters.entrySet()) { long value = reset ? e.getValue().getAndSet(0) : e.getValue().get(); builder.put(e.getKey(), value); } // Build the immutable map so that people can't mess around with it. return builder.build(); } }
metaZNodePrefix = conf.get("zookeeper.znode.metaserver", META_ZNODE_PREFIX); String defaultMetaReplicaZNode = ZNodePaths.joinZNode(baseZNode, metaZNodePrefix); builder.put(DEFAULT_REPLICA_ID, defaultMetaReplicaZNode); int numMetaReplicas = conf.getInt(META_REPLICAS_NUM, DEFAULT_META_REPLICA_NUM); IntStream.range(1, numMetaReplicas) .forEachOrdered(i -> builder.put(i, defaultMetaReplicaZNode + "-" + i)); metaReplicaZNodes = builder.build(); rsZNode = joinZNode(baseZNode, conf.get("zookeeper.znode.rs", "rs"));
private static StorageTypeSetter createStorageTypeSetter() throws NoSuchMethodException { Method setStorageTypeMethod = OpWriteBlockProto.Builder.class.getMethod("setStorageType", StorageTypeProto.class); ImmutableMap.Builder<String, StorageTypeProto> builder = ImmutableMap.builder(); for (StorageTypeProto storageTypeProto : StorageTypeProto.values()) { builder.put(storageTypeProto.name(), storageTypeProto); } ImmutableMap<String, StorageTypeProto> name2ProtoEnum = builder.build(); return new StorageTypeSetter() { @Override public OpWriteBlockProto.Builder set(OpWriteBlockProto.Builder builder, Enum<?> storageType) { Object protoEnum = name2ProtoEnum.get(storageType.name()); try { setStorageTypeMethod.invoke(builder, protoEnum); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException(e); } return builder; } }; }
/** * Returns a map from the ith element of list to i. */ static <E> ImmutableMap<E, Integer> indexMap(Collection<E> list) { ImmutableMap.Builder<E, Integer> builder = new ImmutableMap.Builder<E, Integer>(list.size()); int i = 0; for (E e : list) { builder.put(e, i++); } return builder.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; }
/** * Associates {@code key} with {@code value} in the built bimap. Duplicate * keys or values are not allowed, and will cause {@link #build} to fail. */ @CanIgnoreReturnValue @Override public Builder<K, V> put(K key, V value) { super.put(key, value); return this; }
/** * Associates {@code key} with {@code value} in the built map. Duplicate keys are not allowed, * and will cause {@link #build} to fail. */ @CanIgnoreReturnValue public <T extends B> Builder<B> put(TypeToken<T> key, T value) { mapBuilder.put(key.rejectTypeVariables(), value); return this; }
/** * Associates {@code key} with {@code value} in the built map. Duplicate keys are not allowed, * and will cause {@link #build} to fail. */ @CanIgnoreReturnValue public <T extends B> Builder<B> put(Class<T> key, T value) { mapBuilder.put(TypeToken.of(key), value); return this; }
/** * Associates {@code key} with {@code value} in the built map. Duplicate * keys, according to the comparator (which might be the keys' natural * order), are not allowed, and will cause {@link #build} to fail. */ @CanIgnoreReturnValue @Override public Builder<K, V> put(K key, V value) { super.put(key, value); return this; }
private static <N, E> Map<E, N> getEdgeToReferenceNode(Network<N, E> network) { // ImmutableMap.Builder maintains the order of the elements as inserted, so the map will have // whatever ordering the network's edges do, so ImmutableSortedMap is unnecessary even if the // input edges are sorted. ImmutableMap.Builder<E, N> edgeToReferenceNode = ImmutableMap.builder(); for (E edge : network.edges()) { edgeToReferenceNode.put(edge, network.incidentNodes(edge).nodeU()); } return edgeToReferenceNode.build(); }
static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction) { checkNotNull(keyFunction); checkNotNull(valueFunction); return Collector.of( ImmutableMap.Builder<K, V>::new, (builder, input) -> builder.put(keyFunction.apply(input), valueFunction.apply(input)), ImmutableMap.Builder::combine, ImmutableMap.Builder::build); }
Object createMap(Builder<Object, Object> builder) { for (int i = 0; i < keys.length; i++) { builder.put(keys[i], values[i]); } return builder.build(); }
/** * Adds the given {@code entry} to the map, making it immutable if * necessary. Duplicate keys are not allowed, and will cause {@link #build} * to fail. * * @since 11.0 */ @CanIgnoreReturnValue public Builder<K, V> put(Entry<? extends K, ? extends V> entry) { return put(entry.getKey(), entry.getValue()); }
/** * 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; }
/** Returns a new {@code TypeResolver} with {@code variable} mapping to {@code type}. */ final TypeTable where(Map<TypeVariableKey, ? extends Type> mappings) { ImmutableMap.Builder<TypeVariableKey, Type> builder = ImmutableMap.builder(); builder.putAll(map); for (Map.Entry<TypeVariableKey, ? extends Type> mapping : mappings.entrySet()) { TypeVariableKey variable = mapping.getKey(); Type type = mapping.getValue(); checkArgument(!variable.equalsType(type), "Type variable %s bound to itself", variable); builder.put(variable, type); } return new TypeTable(builder.build()); }
private static <N, E> Map<N, NetworkConnections<N, E>> getNodeConnections(Network<N, E> network) { // ImmutableMap.Builder maintains the order of the elements as inserted, so the map will have // whatever ordering the network's nodes do, so ImmutableSortedMap is unnecessary even if the // input nodes are sorted. ImmutableMap.Builder<N, NetworkConnections<N, E>> nodeConnections = ImmutableMap.builder(); for (N node : network.nodes()) { nodeConnections.put(node, connectionsOf(network, node)); } return nodeConnections.build(); }
/** * Associates {@code key} with {@code value} in the built map. Duplicate * keys are not allowed, and will cause {@link #build} to fail. */ @CanIgnoreReturnValue public <T extends B> Builder<B> put(Class<T> key, T value) { mapBuilder.put(key, value); return this; }
metaZNodePrefix = conf.get("zookeeper.znode.metaserver", META_ZNODE_PREFIX); String defaultMetaReplicaZNode = ZNodePaths.joinZNode(baseZNode, metaZNodePrefix); builder.put(DEFAULT_REPLICA_ID, defaultMetaReplicaZNode); int numMetaReplicas = conf.getInt(META_REPLICAS_NUM, DEFAULT_META_REPLICA_NUM); IntStream.range(1, numMetaReplicas) .forEachOrdered(i -> builder.put(i, defaultMetaReplicaZNode + "-" + i)); metaReplicaZNodes = builder.build(); rsZNode = joinZNode(baseZNode, conf.get("zookeeper.znode.rs", "rs"));
/** * Get all of the values. If reset is true, we will reset the all AtomicLongs back to 0. * @param reset whether to reset the AtomicLongs to 0. * @return A Map of String -> Long for metrics */ public Map<String, Long> getMetricsMap(boolean reset) { // Create a builder ImmutableMap.Builder<String, Long> builder = ImmutableMap.builder(); for (Map.Entry<String, AtomicLong> e : this.counters.entrySet()) { long value = reset ? e.getValue().getAndSet(0) : e.getValue().get(); builder.put(e.getKey(), value); } // Build the immutable map so that people can't mess around with it. return builder.build(); } }
.put(-1, new ImmutableBytesWritable(Bytes.fromHex("714cb10a9e3b5569852980edd8c6ca2f"))) .put(5, new ImmutableBytesWritable(Bytes.fromHex("28d961d9252ce8f8d44a07b38d3e1d96"))) .put(10, new ImmutableBytesWritable(Bytes.fromHex("f6bbc4a224d8fd929b783a92599eaffa"))) .put(15, new ImmutableBytesWritable(Bytes.fromHex("522deb5d97f73a414ecc11457be46881"))) .put(20, new ImmutableBytesWritable(Bytes.fromHex("b026f2611aaa46f7110116d807545352"))) .put(25, new ImmutableBytesWritable(Bytes.fromHex("39ffc1a3094aa12a2e90ffd9cef2ce93"))) .put(30, new ImmutableBytesWritable(Bytes.fromHex("f6b4d75727ce9a30ac29e4f08f601666"))) .put(35, new ImmutableBytesWritable(Bytes.fromHex("422e2d2f1eb79a8f02171a705a42c090"))) .put(40, new ImmutableBytesWritable(Bytes.fromHex("559ad61c900fffefea0a15abf8a97bc3"))) .put(45, new ImmutableBytesWritable(Bytes.fromHex("23019084513eca41cee436b2a29611cb"))) .put(50, new ImmutableBytesWritable(Bytes.fromHex("b40467d222ddb4949b142fe145ee9edc"))) .put(55, new ImmutableBytesWritable(Bytes.fromHex("372bf89fcd8ca4b7ab3c1add9d07f7e4"))) .put(60, new ImmutableBytesWritable(Bytes.fromHex("69ae0585e6255de27dce974e332b8f8b"))) .put(65, new ImmutableBytesWritable(Bytes.fromHex("8029610044297aad0abdbecd485d8e59"))) .put(70, new ImmutableBytesWritable(Bytes.fromHex("de5f784f7f78987b6e57ecfd81c8646f"))) .put(75, new ImmutableBytesWritable(Bytes.fromHex("1cd757cc4e1715c8c3b1c24447a1ec56"))) .put(80, new ImmutableBytesWritable(Bytes.fromHex("f9a53aacfeb6142b08066615e7038095"))) .put(85, new ImmutableBytesWritable(Bytes.fromHex("89b872b7e639df32d3276b33928c0c91"))) .put(90, new ImmutableBytesWritable(Bytes.fromHex("45eeac0646d46a474ea0484175faed38"))) .put(95, new ImmutableBytesWritable(Bytes.fromHex("f57c447e32a08f4bf1abb2892839ac56"))) .build();