List of usage examples for com.google.common.collect ImmutableListMultimap builder
public static <K, V> Builder<K, V> builder()
From source file:com.vecna.dbDiff.model.relationalDb.RelationalTable.java
/** * Set the indices.//from w ww. java2 s.co m * @param indices The indices to set * @throws InconsistentSchemaException If adding an index not recognized by the current table */ public void setIndices(List<RelationalIndex> indices) throws InconsistentSchemaException { ImmutableMultimap.Builder<List<String>, RelationalIndex> indexMapBuilder = ImmutableListMultimap.builder(); if (getName() == null) { throw new InconsistentSchemaException("Trying to add indices without setting a table!"); } else { for (RelationalIndex ri : indices) { if (!getCatalogSchema().equals(ri.getCatalogSchema())) { throw new InconsistentSchemaException("Index " + ri.getName() + " and table " + getName() + " belong to different catalogs or schemas."); } indexMapBuilder.put(ri.getColumnNames(), ri); } } m_indicesByColumns = indexMapBuilder.build(); }
From source file:org.tensorics.core.tensor.lang.OngoingOrderedFlattening.java
private ListMultimap<Position, C> intoKeyListMultimap() { ImmutableListMultimap.Builder<Position, C> builder = ImmutableListMultimap.builder(); Tensor<Map<C, S>> maps = TensorInternals.mapOut(tensor).inDirectionOf(dimensionToFlatten); for (Entry<Position, Map<C, S>> entry : entrySetOf(maps)) { Position newPosition = entry.getKey(); Map<C, S> map = entry.getValue(); List<C> keys = new ArrayList<>(map.keySet()); Collections.sort(keys);//from ww w .j av a2s .c om builder.putAll(newPosition, keys); } return builder.build(); }
From source file:ratpack.util.internal.ImmutableDelegatingMultiValueMap.java
@Override public ListMultimap<K, V> asMultimap() { ImmutableListMultimap.Builder<K, V> builder = ImmutableListMultimap.builder(); for (Entry<? extends K, ? extends List<? extends V>> entry : delegate.entrySet()) { builder.putAll(entry.getKey(), entry.getValue()); }/*from w ww .java2s. co m*/ return builder.build(); }
From source file:com.google.devtools.build.lib.skyframe.serialization.MultimapCodec.java
@Override public ImmutableMultimap<K, V> deserialize(DeserializationContext context, CodedInputStream codedIn) throws SerializationException, IOException { ImmutableMultimap.Builder<K, V> result; if (codedIn.readBool()) { result = ImmutableListMultimap.builder(); } else {// w w w . j av a2 s. c o m result = ImmutableSetMultimap.builder(); } int length = codedIn.readInt32(); for (int i = 0; i < length; i++) { K key = context.deserialize(codedIn); Collection<V> values = context.deserialize(codedIn); result.putAll(key, values); } return result.build(); }
From source file:org.jclouds.json.internal.IgnoreNullMultimapTypeAdapterFactory.java
private <K, V> TypeAdapter<Multimap<K, V>> newMapAdapter(final TypeAdapter<K> keyAdapter, final TypeAdapter<V> valueAdapter) { return new TypeAdapter<Multimap<K, V>>() { public void write(JsonWriter out, Multimap<K, V> map) throws IOException { out.beginObject();/* w ww . j av a2 s . c o m*/ for (K key : map.keySet()) { out.name(String.valueOf(key)); out.beginArray(); for (V value : map.get(key)) { valueAdapter.write(out, value); } out.endArray(); } out.endObject(); } public Multimap<K, V> read(JsonReader in) throws IOException { ImmutableMultimap.Builder<K, V> result = ImmutableListMultimap.builder(); in.beginObject(); while (in.hasNext()) { JsonReaderInternalAccess.INSTANCE.promoteNameToValue(in); K name = keyAdapter.read(in); in.beginArray(); while (in.hasNext()) { V value = valueAdapter.read(in); if (value != null) result.put(name, value); } in.endArray(); } in.endObject(); return result.build(); } }.nullSafe(); }
From source file:internal.coprocessor.NonAggregatingRegionObserver.java
/** * Builds the regionIndex by going through all the store files for each region and creating a reader for it that can * later be used to read the bloom filters, on demand. *//*w w w . jav a 2 s. c o m*/ @VisibleForTesting public static NavigableMap<ByteBuffer, ListMultimap<ByteBuffer, BloomFilter>> buildIndex(String tableName, Configuration conf, FileSystem fileSystem, Path tableBasePath) throws IOException { ImmutableSortedMap.Builder<ByteBuffer, ListMultimap<ByteBuffer, BloomFilter>> indexBuilder = ImmutableSortedMap .naturalOrder(); try { HTable table = new HTable(conf, tableName); NavigableMap<HRegionInfo, ServerName> regions = table.getRegionLocations(); Collection<HColumnDescriptor> families = table.getTableDescriptor().getFamilies(); table.close(); LOG.info("Building RegionIndex [Table: " + tableName + " Base Path: " + tableBasePath.toString() + "]"); for (HRegionInfo region : regions.keySet()) { ImmutableListMultimap.Builder<ByteBuffer, BloomFilter> familiesAndStoreFiles = ImmutableListMultimap .builder(); for (HColumnDescriptor family : families) { Path path = new Path(tableBasePath, region.getEncodedName() + Path.SEPARATOR + family.getNameAsString()); FileStatus[] storeFilesStatuses = fileSystem.listStatus(path); for (FileStatus status : storeFilesStatuses) { LOG.info("Processing Store File: " + status.getPath().toString() + " Column Family: " + family.getNameAsString() + " for Region: " + region.getRegionNameAsString()); // maybe increased the cache for this reader since it's be only reading blooms? HFile.Reader reader = HFile.createReader(fileSystem, status.getPath(), new CacheConfig(conf)); familiesAndStoreFiles.put(ByteBuffer.wrap(family.getName()), BloomFilterFactory.createFromMeta(reader.getGeneralBloomFilterMetadata(), reader)); } } indexBuilder.put(ByteBuffer.wrap(region.getStartKey()), familiesAndStoreFiles.build()); } return indexBuilder.build(); } catch (Exception e) { LOG.error("Could not load regionIndex, BloomFilterSemiJoinFilter will not work.", e); } return null; }
From source file:net.minecrell.ice.launch.transformers.AccessTransformer.java
protected AccessTransformer(String file) throws IOException { checkNotNull(file, "file"); ImmutableMultimap.Builder<String, Modifier> builder = ImmutableListMultimap.builder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader( getClass().getClassLoader().getResourceAsStream(file), StandardCharsets.UTF_8))) { String line;/*w ww .j a v a 2 s . c om*/ while ((line = reader.readLine()) != null) { line = substringBefore(line, '#').trim(); if (line.isEmpty()) { continue; } List<String> parts = SEPARATOR.splitToList(line); checkArgument(parts.size() <= 3, "Invalid access transformer config line: " + line); String name = null; String desc = null; boolean isClass = parts.size() == 2; if (!isClass) { name = parts.get(2); int pos = name.indexOf('('); if (pos >= 0) { desc = name.substring(pos); name = name.substring(0, pos); } } String s = parts.get(0); int access = 0; if (s.startsWith("public")) { access = ACC_PUBLIC; } else if (s.startsWith("protected")) { access = ACC_PROTECTED; } else if (s.startsWith("private")) { access = ACC_PRIVATE; } Boolean markFinal = null; if (s.endsWith("+f")) { markFinal = true; } else if (s.endsWith("-f")) { markFinal = false; } String className = parts.get(1).replace('/', '.'); builder.put(className, new Modifier(name, desc, isClass, access, markFinal)); } } this.modifiers = builder.build(); }
From source file:org.elasticsoftware.elasticactors.cluster.LocalActorRefGroup.java
@Override public ActorRefGroup withMembersAdded(ActorRef... membersToAdd) throws IllegalArgumentException { for (ActorRef member : membersToAdd) { if (!(member instanceof ActorShardRef)) { throw new IllegalArgumentException( "Only Persistent Actors (annotated with @Actor) of the same ElasticActors cluster are allowed to form a group"); }/*from w w w . ja v a 2 s . co m*/ } ImmutableListMultimap.Builder<ActorShardRef, ActorRef> newMemberMap = ImmutableListMultimap.builder(); newMemberMap.putAll(this.members); for (ActorRef member : membersToAdd) { newMemberMap.put((ActorShardRef) ((ActorShardRef) member).getActorContainer().getActorRef(), member); } return new LocalActorRefGroup(newMemberMap.build()); }
From source file:com.google.errorprone.bugpatterns.time.TemporalAccessorGetChronoField.java
private static ImmutableListMultimap<Class<?>, ChronoField> buildUnsupported() { ImmutableListMultimap.Builder<Class<?>, ChronoField> builder = ImmutableListMultimap.builder(); for (TemporalAccessor temporalAccessor : TEMPORAL_ACCESSOR_INSTANCES) { for (ChronoField chronoField : ChronoField.values()) { if (!temporalAccessor.isSupported(chronoField)) { builder.put(temporalAccessor.getClass(), chronoField); }/* w ww . j av a 2s .co m*/ } } return builder.build(); }
From source file:io.prestosql.sql.planner.iterative.rule.PushTableWriteThroughUnion.java
@Override public Result apply(TableWriterNode writerNode, Captures captures, Context context) { UnionNode unionNode = captures.get(CHILD); ImmutableList.Builder<PlanNode> rewrittenSources = ImmutableList.builder(); List<Map<Symbol, Symbol>> sourceMappings = new ArrayList<>(); for (int source = 0; source < unionNode.getSources().size(); source++) { rewrittenSources.add(rewriteSource(writerNode, unionNode, source, sourceMappings, context)); }/*from ww w . ja v a 2 s . c om*/ ImmutableListMultimap.Builder<Symbol, Symbol> unionMappings = ImmutableListMultimap.builder(); sourceMappings.forEach(mappings -> mappings.forEach(unionMappings::put)); return Result.ofPlanNode(new UnionNode(context.getIdAllocator().getNextId(), rewrittenSources.build(), unionMappings.build(), ImmutableList.copyOf(unionMappings.build().keySet()))); }