List of usage examples for com.google.common.collect ImmutableListMultimap builder
public static <K, V> Builder<K, V> builder()
From source file:com.google.devtools.build.lib.analysis.RuleContext.java
/** * For a given attribute, returns all {@link TransitiveInfoProvider}s provided by targets * of that attribute. Each {@link TransitiveInfoProvider} is keyed by the * {@link BuildConfiguration} under which the provider was created. *//* w ww . j a va2 s . com*/ public <C extends TransitiveInfoProvider> ImmutableListMultimap<BuildConfiguration, C> getPrerequisitesByConfiguration( String attributeName, Mode mode, final Class<C> classType) { AnalysisUtils.checkProvider(classType); List<? extends TransitiveInfoCollection> transitiveInfoCollections = getPrerequisites(attributeName, mode); ImmutableListMultimap.Builder<BuildConfiguration, C> result = ImmutableListMultimap.builder(); for (TransitiveInfoCollection prerequisite : transitiveInfoCollections) { C prerequisiteProvider = prerequisite.getProvider(classType); if (prerequisiteProvider != null) { result.put(prerequisite.getConfiguration(), prerequisiteProvider); } } return result.build(); }
From source file:com.google.devtools.build.lib.analysis.RuleContext.java
/** * For a given attribute, returns all {@link TransitiveInfoCollection}s provided by targets * of that attribute. Each {@link TransitiveInfoCollection} is keyed by the * {@link BuildConfiguration} under which the collection was created. *///from www . ja va 2s . c o m public ImmutableListMultimap<BuildConfiguration, TransitiveInfoCollection> getPrerequisitesByConfiguration( String attributeName, Mode mode) { List<? extends TransitiveInfoCollection> transitiveInfoCollections = getPrerequisites(attributeName, mode); ImmutableListMultimap.Builder<BuildConfiguration, TransitiveInfoCollection> result = ImmutableListMultimap .builder(); for (TransitiveInfoCollection prerequisite : transitiveInfoCollections) { result.put(prerequisite.getConfiguration(), prerequisite); } return result.build(); }
From source file:io.prestosql.sql.planner.RelationPlanner.java
private SetOperationPlan process(SetOperation node) { List<Symbol> outputs = null; ImmutableList.Builder<PlanNode> sources = ImmutableList.builder(); ImmutableListMultimap.Builder<Symbol, Symbol> symbolMapping = ImmutableListMultimap.builder(); List<RelationPlan> subPlans = node.getRelations().stream() .map(relation -> processAndCoerceIfNecessary(relation, null)).collect(toImmutableList()); for (RelationPlan relationPlan : subPlans) { List<Symbol> childOutputSymbols = relationPlan.getFieldMappings(); if (outputs == null) { // Use the first Relation to derive output symbol names RelationType descriptor = relationPlan.getDescriptor(); ImmutableList.Builder<Symbol> outputSymbolBuilder = ImmutableList.builder(); for (Field field : descriptor.getVisibleFields()) { int fieldIndex = descriptor.indexOf(field); Symbol symbol = childOutputSymbols.get(fieldIndex); outputSymbolBuilder.add( symbolAllocator.newSymbol(symbol.getName(), symbolAllocator.getTypes().get(symbol))); }/*ww w .ja va 2s. c om*/ outputs = outputSymbolBuilder.build(); } RelationType descriptor = relationPlan.getDescriptor(); checkArgument(descriptor.getVisibleFieldCount() == outputs.size(), "Expected relation to have %s symbols but has %s symbols", descriptor.getVisibleFieldCount(), outputs.size()); int fieldId = 0; for (Field field : descriptor.getVisibleFields()) { int fieldIndex = descriptor.indexOf(field); symbolMapping.put(outputs.get(fieldId), childOutputSymbols.get(fieldIndex)); fieldId++; } sources.add(relationPlan.getRoot()); } return new SetOperationPlan(sources.build(), symbolMapping.build()); }
From source file:org.lanternpowered.server.world.chunk.LanternChunkManager.java
public void loadTickets() throws IOException { final Multimap<String, LanternLoadingTicket> tickets = LanternLoadingTicketIO.load(this.worldFolder, this, this.chunkLoadService); final Iterator<Entry<String, LanternLoadingTicket>> it = tickets.entries().iterator(); while (it.hasNext()) { final LanternLoadingTicket ticket = it.next().getValue(); if (ticket instanceof LanternEntityLoadingTicket) { final LanternEntityLoadingTicket ticket0 = (LanternEntityLoadingTicket) ticket; final EntityReference ref = ticket0.getEntityReference().orElse(null); if (ref != null) { final LanternChunk chunk = getOrCreateChunk(ref.getChunkCoords(), () -> Cause.source(ticket0).owner(this.world).build(), true, true); final Entity entity = chunk.getEntity(ref.getUniqueId()).orElse(null); if (entity != null) { ticket0.bindToEntity(entity); } else { // The entity is gone? it.remove();/*from ww w. ja v a2 s .c o m*/ } } else { // The entity is gone? it.remove(); } } } for (Entry<String, Collection<LanternLoadingTicket>> entry : tickets.asMap().entrySet()) { final Collection<ChunkTicketManager.Callback> callbacks = this.chunkLoadService.getCallbacks() .get(entry.getKey()); // These maps will be loaded lazily ImmutableListMultimap<UUID, LoadingTicket> playerLoadedTickets = null; ImmutableList<LoadingTicket> nonPlayerLoadedTickets = null; final Set<LoadingTicket> resultPlayerLoadedTickets = entry.getValue().stream() .filter(ticket -> ticket instanceof PlayerLoadingTicket).collect(Collectors.toSet()); final Set<LoadingTicket> resultNonPlayerLoadedTickets = entry.getValue().stream() .filter(ticket -> !(ticket instanceof PlayerLoadingTicket)).collect(Collectors.toSet()); final int maxTickets = this.chunkLoadService.getMaxTicketsById(entry.getKey()); for (ChunkTicketManager.Callback callback : callbacks) { if (callback instanceof ChunkTicketManager.OrderedCallback) { if (nonPlayerLoadedTickets == null) { nonPlayerLoadedTickets = ImmutableList.copyOf(resultNonPlayerLoadedTickets); resultNonPlayerLoadedTickets.clear(); } final List<LoadingTicket> result = ((ChunkTicketManager.OrderedCallback) callback) .onLoaded(nonPlayerLoadedTickets, this.world, maxTickets); checkNotNull(result, "The OrderedCallback#onLoaded method may not return null, " + "error caused by (plugin=%s, clazz=%s)", entry.getKey(), callback.getClass().getName()); resultNonPlayerLoadedTickets.addAll(result); } if (callback instanceof ChunkTicketManager.PlayerOrderedCallback) { if (playerLoadedTickets == null) { final ImmutableListMultimap.Builder<UUID, LoadingTicket> mapBuilder = ImmutableListMultimap .builder(); resultPlayerLoadedTickets.forEach(ticket -> mapBuilder .put(((PlayerLoadingTicket) ticket).getPlayerUniqueId(), ticket)); resultPlayerLoadedTickets.clear(); playerLoadedTickets = mapBuilder.build(); } final ListMultimap<UUID, LoadingTicket> result = ((ChunkTicketManager.PlayerOrderedCallback) callback) .onPlayerLoaded(playerLoadedTickets, this.world); checkNotNull(result, "The PlayerOrderedCallback#onPlayerLoaded method may not return null, " + "error caused by (plugin=%s, clazz=%s)", entry.getKey(), callback.getClass().getName()); resultPlayerLoadedTickets.addAll(result.values()); } } final List<LoadingTicket> resultLoadedTickets = new ArrayList<>(); resultLoadedTickets.addAll(resultPlayerLoadedTickets); resultLoadedTickets.addAll(resultNonPlayerLoadedTickets); // Lets see how many plugins attempted to add loading tickets final int sizeA = resultLoadedTickets.size(); resultLoadedTickets.retainAll(entry.getValue()); final int sizeB = resultLoadedTickets.size(); if (sizeA != sizeB) { Lantern.getLogger().warn( "The plugin {} attempted to add LoadingTicket's that were previously not present.", entry.getKey()); } // Remove all the tickets that are already released resultLoadedTickets.removeIf(ticket -> ((ChunkLoadingTicket) ticket).isReleased()); if (resultLoadedTickets.size() > maxTickets) { Lantern.getLogger().warn( "The plugin {} has too many open chunk loading tickets {}. " + "Excess will be dropped", entry.getKey(), resultLoadedTickets.size()); resultLoadedTickets.subList(maxTickets, resultLoadedTickets.size()).clear(); } // Release all the tickets that were no longer usable final List<LoadingTicket> removedTickets = new ArrayList<>(entry.getValue()); removedTickets.removeAll(resultLoadedTickets); removedTickets.forEach(LoadingTicket::release); final ImmutableList<LoadingTicket> loadedTickets = ImmutableList.copyOf(resultLoadedTickets); for (ChunkTicketManager.Callback callback : callbacks) { callback.onLoaded(loadedTickets, this.world); } } }
From source file:com.google.cloud.dataflow.sdk.options.PipelineOptionsFactory.java
/** * Splits string arguments based upon expected pattern of --argName=value. * * <p>Example GNU style command line arguments: * * <pre>//from w w w .j a v a 2 s . com * --project=MyProject (simple property, will set the "project" property to "MyProject") * --readOnly=true (for boolean properties, will set the "readOnly" property to "true") * --readOnly (shorthand for boolean properties, will set the "readOnly" property to "true") * --x=1 --x=2 --x=3 (list style simple property, will set the "x" property to [1, 2, 3]) * --x=1,2,3 (shorthand list style simple property, will set the "x" property to [1, 2, 3]) * --complexObject='{"key1":"value1",...} (JSON format for all other complex types) * </pre> * * <p>Simple properties are able to bound to {@link String}, {@link Class}, enums and Java * primitives {@code boolean}, {@code byte}, {@code short}, {@code int}, {@code long}, * {@code float}, {@code double} and their primitive wrapper classes. * * <p>Simple list style properties are able to be bound to {@code boolean[]}, {@code char[]}, * {@code short[]}, {@code int[]}, {@code long[]}, {@code float[]}, {@code double[]}, * {@code Class[]}, enum arrays, {@code String[]}, and {@code List<String>}. * * <p>JSON format is required for all other types. * * <p>If strict parsing is enabled, options must start with '--', and not have an empty argument * name or value based upon the positioning of the '='. Empty or null arguments will be ignored * whether or not strict parsing is enabled. */ private static ListMultimap<String, String> parseCommandLine(String[] args, boolean strictParsing) { ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder(); for (String arg : args) { if (Strings.isNullOrEmpty(arg)) { continue; } try { checkArgument(arg.startsWith("--"), "Argument '%s' does not begin with '--'", arg); int index = arg.indexOf("="); // Make sure that '=' isn't the first character after '--' or the last character checkArgument(index != 2, "Argument '%s' starts with '--=', empty argument name not allowed", arg); if (index > 0) { builder.put(arg.substring(2, index), arg.substring(index + 1, arg.length())); } else { builder.put(arg.substring(2), "true"); } } catch (IllegalArgumentException e) { if (strictParsing) { throw e; } else { LOG.warn("Strict parsing is disabled, ignoring option '{}' because {}", arg, e.getMessage()); } } } return builder.build(); }