List of usage examples for com.google.common.collect ImmutableMultimap builder
public static <K, V> Builder<K, V> builder()
From source file:com.outerspacecat.icalendar.Component.java
/** * Returns the properties of this component excluding those whose name is * specified in {@code names}./*from ww w . jav a 2 s .c o m*/ * * @param names the names of the properties to exclude. Must be non * {@code null}. * @return the properties of this component excluding those whose name is * specified in {@code names}. Never {@code null}, contains zero or * more entries. */ public ImmutableMultimap<String, Property> getPropertiesExcept(final Set<String> names) { Preconditions.checkNotNull(names, "names required"); ImmutableMultimap.Builder<String, Property> ret = ImmutableMultimap.builder(); for (Property prop : getProperties().values()) { if (!names.contains(prop.getName().getName())) ret.put(prop.getName().getName(), prop); } return ret.build(); }
From source file:com.google.template.soy.sharedpasses.FindIjParamsVisitor.java
/** * Computes injected params info for a template. * * <p> Note: This method is not thread-safe. If you need to get injected params info in a * thread-safe manner, then please use {@link #execOnAllTemplates}() in a thread-safe manner. *//*from w ww . j a v a 2s . c om*/ public IjParamsInfo exec(TemplateNode rootTemplate) { TransitiveDepTemplatesInfo depsInfo = findTransitiveDepTemplatesVisitor.exec(rootTemplate); if (!depsInfoToIjParamsInfoMap.containsKey(depsInfo)) { ImmutableMultimap.Builder<String, TemplateNode> ijParamToCalleesMultimapBuilder = ImmutableMultimap .builder(); for (TemplateNode template : depsInfo.depTemplateSet) { if (!templateToLocalIjParamsMap.containsKey(template)) { FindIjParamsInExprHelperVisitor helperVisitor = new FindIjParamsInExprHelperVisitor( errorReporter); SoytreeUtils.execOnAllV2Exprs(template, helperVisitor, errorReporter); Set<String> localIjParams = helperVisitor.getResult(); templateToLocalIjParamsMap.put(template, localIjParams); } for (String localIjParam : templateToLocalIjParamsMap.get(template)) { ijParamToCalleesMultimapBuilder.put(localIjParam, template); } for (TemplateParam injectedParam : template.getInjectedParams()) { ijParamToCalleesMultimapBuilder.put(injectedParam.name(), template); } } IjParamsInfo ijParamsInfo = new IjParamsInfo(ijParamToCalleesMultimapBuilder.build()); depsInfoToIjParamsInfoMap.put(depsInfo, ijParamsInfo); } return depsInfoToIjParamsInfoMap.get(depsInfo); }
From source file:com.facebook.buck.android.exopackage.NativeExoHelper.java
@VisibleForTesting public static ImmutableMultimap<String, Path> filterLibrariesForAbi(Path nativeLibsDir, ImmutableMultimap<String, Path> allLibraries, String abi, ImmutableSet<String> ignoreLibraries) { ImmutableMultimap.Builder<String, Path> filteredLibraries = ImmutableMultimap.builder(); for (Map.Entry<String, Path> entry : allLibraries.entries()) { Path relativePath = nativeLibsDir.relativize(entry.getValue()); // relativePath is of the form libs/x86/foo.so, or assetLibs/x86/foo.so etc. Preconditions.checkState(relativePath.getNameCount() == 3); Preconditions.checkState(relativePath.getName(0).toString().equals("libs") || relativePath.getName(0).toString().equals("assetLibs")); String libAbi = relativePath.getParent().getFileName().toString(); String libName = relativePath.getFileName().toString(); if (libAbi.equals(abi) && !ignoreLibraries.contains(libName)) { filteredLibraries.put(entry); }/*from w w w . ja v a2s . c o m*/ } return filteredLibraries.build(); }
From source file:net.minecrell.quartz.launch.mappings.Mappings.java
protected Mappings(List<ClassNode> mappingClasses) { requireNonNull(mappingClasses, "mappingClasses"); if (mappingClasses.isEmpty()) { this.classes = ImmutableBiMap.of(); this.methods = ImmutableTable.of(); this.fields = ImmutableTable.of(); this.constructors = ImmutableMultimap.of(); this.accessMappings = ImmutableTable.of(); return;//from www. j a v a 2 s.co m } ImmutableBiMap.Builder<String, String> classes = ImmutableBiMap.builder(); for (ClassNode classNode : mappingClasses) { ParsedAnnotation annotation = MappingsParser.getAnnotation(classNode, MAPPING); checkState(annotation != null, "Class %s is missing the @Mapping annotation", classNode.name); String mapping = annotation.getString("value", ""); if (!mapping.isEmpty()) { classes.put(mapping, classNode.name); } } this.classes = classes.build(); // We need to remap the descriptors of the fields and methods, use ASM for convenience Remapper remapper = new Remapper() { @Override public String map(String className) { return unmap(className); } }; // Load field, method and access mappings ImmutableTable.Builder<String, String, String> methods = ImmutableTable.builder(); ImmutableTable.Builder<String, String, String> fields = ImmutableTable.builder(); ImmutableMultimap.Builder<String, MethodNode> constructors = ImmutableMultimap.builder(); ImmutableTable.Builder<String, String, AccessMapping> accessMappings = ImmutableTable.builder(); for (ClassNode classNode : mappingClasses) { String className = classNode.name.replace('/', '.'); String internalName = unmap(classNode.name); ParsedAnnotation annotation = MappingsParser.getAnnotation(classNode, ACCESSIBLE); if (annotation != null) { accessMappings.put(className, "", AccessMapping.of(classNode)); } for (MethodNode methodNode : classNode.methods) { Map<String, ParsedAnnotation> annotations = MappingsParser.getAnnotations(methodNode); annotation = annotations.get(CONSTRUCTOR); if (annotation != null) { // Generate constructor call code Methods.visitConstructor(methodNode, classNode.name); constructors.put(className, methodNode); continue; } // TODO: Validation annotation = annotations.get(MAPPING); if (annotation != null) { String mapping = annotation.getString("value", ""); if (!mapping.isEmpty()) { methods.put(internalName, mapping + remapper.mapMethodDesc(methodNode.desc), methodNode.name); } } annotation = annotations.get(ACCESSIBLE); if (annotation != null) { accessMappings.put(className, methodNode.name + methodNode.desc, AccessMapping.of(methodNode)); } } for (FieldNode fieldNode : classNode.fields) { Map<String, ParsedAnnotation> annotations = MappingsParser.getAnnotations(fieldNode); // TODO: Validation annotation = annotations.get(MAPPING); if (annotation != null) { String mapping = annotation.getString("value", ""); if (!mapping.isEmpty()) { fields.put(internalName, mapping + ':' + remapper.mapDesc(fieldNode.desc), fieldNode.name); } } annotation = annotations.get(ACCESSIBLE); if (annotation != null) { accessMappings.put(className, fieldNode.name, AccessMapping.of(fieldNode)); } } } this.methods = methods.build(); this.fields = fields.build(); this.constructors = constructors.build(); this.accessMappings = accessMappings.build(); }
From source file:org.lanternpowered.server.asset.FileAssetRepository.java
@Override public Multimap<String, Asset> getAssetsMap(String path, boolean checkChildDirectories) { final ImmutableMultimap.Builder<String, Asset> builder = ImmutableMultimap.builder(); final Enumeration<? extends ZipEntry> enumeration = getZipFile().entries(); final Pattern pattern = Pattern.compile(generateRegex(path)); while (enumeration.hasMoreElements()) { final ZipEntry zipEntry = enumeration.nextElement(); final String name = zipEntry.getName().replace('\\', '/'); final Matcher matcher = pattern.matcher(name); if (matcher.matches()) { final String id = matcher.group(2).toLowerCase(Locale.ENGLISH); final int index = id.indexOf('/'); if (index == -1 || (checkChildDirectories && index != id.lastIndexOf('/'))) { continue; }//from w w w .j a v a 2s . c o m final String plugin = matcher.group(1).toLowerCase(Locale.ENGLISH); builder.put(id.substring(0, index), registerAsset(plugin, plugin + ':' + id, generateAssetURL(name), Paths.get(name))); } } return builder.build(); }
From source file:ca.cutterslade.match.scheduler.MatchMaker.java
MatchMaker(Configuration configuration, ImmutableSet<Slot> slots, ImmutableSet<Team> teams, int teamSize) { if (null == configuration) throw new IllegalArgumentException("configuration may not be null"); if (null == slots) throw new IllegalArgumentException("slots may not be null"); if (null == teams) throw new IllegalArgumentException("teams may not be null"); if (2 > teamSize) throw new IllegalArgumentException("size must be two or greater"); this.configuration = configuration; this.teams = teams; ImmutableMultimap.Builder<Tier, Team> tiers = ImmutableMultimap.builder(); for (Team t : teams) tiers.put(t.getTier(), t);/*from w w w. j av a 2 s . c o m*/ this.tiers = tiers.build(); ImmutableMultimap.Builder<Day, Slot> days = ImmutableMultimap.builder(); for (Slot s : slots) days.put(s.getDay(), s); this.days = days.build(); this.teamSize = teamSize; }
From source file:org.apache.james.mailbox.store.search.SimpleMessageSearchIndex.java
private Multimap<MailboxId, Long> searchMultimap(MailboxSession session, Iterable<Mailbox> mailboxes, SearchQuery query) throws MailboxException { Builder<MailboxId, Long> multimap = ImmutableMultimap.builder(); for (Mailbox mailbox : mailboxes) { multimap.putAll(searchMultimap(session, mailbox, query)); }//from www . j a v a2 s . c o m return multimap.build(); }
From source file:com.facebook.buck.android.SmartDexingStep.java
/** * @param primaryOutputPath Path for the primary dex artifact. * @param primaryInputsToDex Set of paths to include as inputs for the primary dex artifact. * @param secondaryOutputDir Directory path for the secondary dex artifacts, if there are any. * Note that this directory will be pruned such that only those secondary outputs generated * by this command will remain in the directory! * @param secondaryInputsToDex List of paths to input jar files, to use as dx input, keyed by the * corresponding output dex file./*from w ww.j a v a 2 s. c o m*/ * Note that for each output file (key), a separate dx invocation will be started with the * corresponding jar files (value) as the input. * @param successDir Directory where success artifacts are written. * @param numThreads Number of threads to use when invoking dx commands. If absent, a * reasonable default will be selected based on the number of available processors. */ public SmartDexingStep(final Path primaryOutputPath, final Supplier<Set<Path>> primaryInputsToDex, Optional<Path> secondaryOutputDir, final Optional<Supplier<Multimap<Path, Path>>> secondaryInputsToDex, DexInputHashesProvider dexInputHashesProvider, Path successDir, Optional<Integer> numThreads, EnumSet<Option> dxOptions) { this.outputToInputsSupplier = Suppliers.memoize(new Supplier<Multimap<Path, Path>>() { @Override public Multimap<Path, Path> get() { final ImmutableMultimap.Builder<Path, Path> map = ImmutableMultimap.builder(); map.putAll(primaryOutputPath, primaryInputsToDex.get()); if (secondaryInputsToDex.isPresent()) { map.putAll(secondaryInputsToDex.get().get()); } return map.build(); } }); this.secondaryOutputDir = Preconditions.checkNotNull(secondaryOutputDir); this.dexInputHashesProvider = Preconditions.checkNotNull(dexInputHashesProvider); this.successDir = Preconditions.checkNotNull(successDir); this.numThreads = Preconditions.checkNotNull(numThreads); this.dxOptions = Preconditions.checkNotNull(dxOptions); }
From source file:edu.udo.scaffoldhunter.model.dataimport.ImportProcess.java
/** * //from w ww . j a v a 2 s .c o m * @return a multimap which contains for each import job the property * definitions which are already defined by a previous import job. */ public ImmutableMultimap<ImportJob, PropertyDefinition> getMergedPropeties() { ImmutableMultimap.Builder<ImportJob, PropertyDefinition> builder = ImmutableMultimap.builder(); Set<PropertyDefinition> allDefinitions = Sets.newHashSet(); Set<PropertyDefinition> definitionsFromJ = Sets.newHashSet(); for (ImportJob j : importJobs) { definitionsFromJ.clear(); for (SourcePropertyMapping m : j.getPropertyMappings().values()) { PropertyDefinition propDef = m.getPropertyDefiniton(); if (propDef != null) definitionsFromJ.add(m.getPropertyDefiniton()); } builder.putAll(j, Sets.intersection(allDefinitions, definitionsFromJ)); allDefinitions.addAll(definitionsFromJ); } return builder.build(); }
From source file:com.outerspacecat.icalendar.VAlarm.java
/** * Creates a new alarm./* ww w . j a v a 2 s . c o m*/ * * @param action the action of the alarm. Must be non {@code null}. * @param trigger the trigger of the alarm. Must be non {@code null}. */ public VAlarm(final TypedProperty<TextType> action, final Trigger trigger, final TypedProperty<Integer> repeat, final TypedProperty<DurationType> duration, final TypedProperty<TextType> description, final TypedProperty<TextType> summary, final Collection<ContentSource> attachments, final Collection<Attendee> attendees, final Iterable<Property> extraProperties) { Preconditions.checkNotNull(action, "action required"); Preconditions.checkNotNull(trigger, "trigger required"); Preconditions.checkNotNull(attachments, "attachments required"); for (ContentSource attachment : attachments) Preconditions.checkNotNull(attachment, "all attachments must be non null"); Preconditions.checkNotNull(attendees, "attendees required"); for (Attendee attendee : attendees) Preconditions.checkNotNull(attendee, "all attendees must be non null"); Preconditions.checkNotNull(extraProperties, "extraProperties required"); for (Property extraProperty : extraProperties) Preconditions.checkNotNull(extraProperty, "all extra properties must be non null"); if (action.getValue().getValue().equalsIgnoreCase("AUDIO")) { Preconditions.checkArgument(description == null, "description must be null"); Preconditions.checkArgument(summary == null, "summary must be null"); Preconditions.checkArgument(attachments.size() <= 1, "attachments must be empty or contain exactly one element"); Preconditions.checkArgument(attendees.isEmpty(), "attendees must be empty"); } else if (action.getValue().getValue().equalsIgnoreCase("DISPLAY")) { Preconditions.checkNotNull(description, "description required"); Preconditions.checkArgument(attachments.isEmpty(), "attachments must be empty"); } else if (action.getValue().getValue().equalsIgnoreCase("EMAIL")) { Preconditions.checkNotNull(description, "description required"); Preconditions.checkNotNull(summary, "summary required"); Preconditions.checkArgument(!attendees.isEmpty(), "attendees must be non empty"); } Preconditions.checkArgument((repeat == null) == (duration == null), "repeat and duration must be specified together"); this.action = action; this.trigger = trigger; this.repeat = repeat; this.duration = duration; this.description = description; this.summary = summary; this.attachments = ImmutableSet.copyOf(attachments); this.attendees = ImmutableSet.copyOf(attendees); ImmutableMultimap.Builder<String, Property> extraPropertiesBuilder = ImmutableMultimap.builder(); for (Property prop : extraProperties) extraPropertiesBuilder.put(prop.getName().getName(), prop); this.extraProperties = extraPropertiesBuilder.build(); }