List of usage examples for com.google.common.collect ImmutableListMultimap copyOf
@Beta public static <K, V> ImmutableListMultimap<K, V> copyOf( Iterable<? extends Entry<? extends K, ? extends V>> entries)
From source file:com.google.gerrit.server.notedb.DraftCommentNotes.java
@Override protected void onLoad(LoadHandle handle) throws IOException, ConfigInvalidException { ObjectId rev = handle.id();/* w w w . ja v a 2 s .c om*/ if (rev == null) { loadDefaults(); return; } RevCommit tipCommit = handle.walk().parseCommit(rev); ObjectReader reader = handle.walk().getObjectReader(); revisionNoteMap = RevisionNoteMap.parse(args.noteUtil, getChangeId(), reader, NoteMap.read(reader, tipCommit), PatchLineComment.Status.DRAFT); ListMultimap<RevId, Comment> cs = MultimapBuilder.hashKeys().arrayListValues().build(); for (ChangeRevisionNote rn : revisionNoteMap.revisionNotes.values()) { for (Comment c : rn.getComments()) { cs.put(new RevId(c.revId), c); } } comments = ImmutableListMultimap.copyOf(cs); }
From source file:com.opengamma.collect.io.PropertySet.java
/** * Combines this property set with another. * <p>//from ww w .java 2 s .c o m * The specified property set takes precedence. * * @param other the other property set * @return the combined property set */ public PropertySet combinedWith(PropertySet other) { ArgChecker.notNull(other, "other"); if (other.isEmpty()) { return this; } if (isEmpty()) { return other; } ListMultimap<String, String> map = ArrayListMultimap.create(keyValueMap); for (String key : other.asMap().keySet()) { map.removeAll(key); map.putAll(key, other.getValueList(key)); } return new PropertySet(ImmutableListMultimap.copyOf(map)); }
From source file:com.facebook.buck.features.lua.CxxLuaExtensionDescription.java
private ImmutableList<Arg> getExtensionArgs(BuildTarget buildTarget, ProjectFilesystem projectFilesystem, ActionGraphBuilder graphBuilder, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, CellPathResolver cellRoots, LuaPlatform luaPlatform, CxxLuaExtensionDescriptionArg args) { CxxPlatform cxxPlatform = luaPlatform.getCxxPlatform(); // Extract all C/C++ sources from the constructor arg. ImmutableMap<String, CxxSource> srcs = CxxDescriptionEnhancer.parseCxxSources(buildTarget, graphBuilder, ruleFinder, pathResolver, cxxPlatform, args); ImmutableMap<Path, SourcePath> headers = CxxDescriptionEnhancer.parseHeaders(buildTarget, graphBuilder, ruleFinder, pathResolver, Optional.of(cxxPlatform), args); // Setup the header symlink tree and combine all the preprocessor input from this rule // and all dependencies. HeaderSymlinkTree headerSymlinkTree = CxxDescriptionEnhancer.requireHeaderSymlinkTree(buildTarget, projectFilesystem, ruleFinder, graphBuilder, cxxPlatform, headers, HeaderVisibility.PRIVATE, true); ImmutableSet<BuildRule> deps = args.getCxxDeps().get(graphBuilder, cxxPlatform); ImmutableList<CxxPreprocessorInput> cxxPreprocessorInput = ImmutableList.<CxxPreprocessorInput>builder() .add(luaPlatform.getLuaCxxLibrary(graphBuilder).getCxxPreprocessorInput(cxxPlatform, graphBuilder)) .addAll(CxxDescriptionEnhancer.collectCxxPreprocessorInput(buildTarget, cxxPlatform, graphBuilder, deps,//from ww w. j ava2s .c om ImmutableListMultimap.copyOf(Multimaps.transformValues( CxxFlags.getLanguageFlagsWithMacros(args.getPreprocessorFlags(), args.getPlatformPreprocessorFlags(), args.getLangPreprocessorFlags(), args.getLangPlatformPreprocessorFlags(), cxxPlatform), f -> CxxDescriptionEnhancer.toStringWithMacrosArgs(buildTarget, cellRoots, graphBuilder, cxxPlatform, f))), ImmutableList.of(headerSymlinkTree), ImmutableSet.of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput(cxxPlatform, graphBuilder, deps), args.getRawHeaders())) .build(); // Generate rule to build the object files. ImmutableMultimap<CxxSource.Type, Arg> compilerFlags = ImmutableListMultimap .copyOf(Multimaps.transformValues( CxxFlags.getLanguageFlagsWithMacros(args.getCompilerFlags(), args.getPlatformCompilerFlags(), args.getLangCompilerFlags(), args.getLangPlatformCompilerFlags(), cxxPlatform), f -> CxxDescriptionEnhancer.toStringWithMacrosArgs(buildTarget, cellRoots, graphBuilder, cxxPlatform, f))); ImmutableMap<CxxPreprocessAndCompile, SourcePath> picObjects = CxxSourceRuleFactory .of(projectFilesystem, buildTarget, graphBuilder, pathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, cxxPreprocessorInput, compilerFlags, args.getPrefixHeader(), args.getPrecompiledHeader(), PicType.PIC) .requirePreprocessAndCompileRules(srcs); ImmutableList.Builder<Arg> argsBuilder = ImmutableList.builder(); CxxFlags.getFlagsWithMacrosWithPlatformMacroExpansion(args.getLinkerFlags(), args.getPlatformLinkerFlags(), cxxPlatform).stream() .map(f -> CxxDescriptionEnhancer.toStringWithMacrosArgs(buildTarget, cellRoots, graphBuilder, cxxPlatform, f)) .forEach(argsBuilder::add); // Add object files into the args. argsBuilder.addAll(SourcePathArg.from(picObjects.values())); return argsBuilder.build(); }
From source file:com.opengamma.strata.collect.io.PropertySet.java
/** * Combines this property set with another. * <p>/*w w w . ja v a 2 s. c o m*/ * The specified property set takes precedence. * * @param other the other property set * @return the combined property set */ public PropertySet combinedWith(PropertySet other) { ArgChecker.notNull(other, "other"); if (other.isEmpty()) { return this; } if (isEmpty()) { return other; } ListMultimap<String, String> map = ArrayListMultimap.create(keyValueMap); for (String key : other.asMultimap().keySet()) { map.removeAll(key); map.putAll(key, other.valueList(key)); } return new PropertySet(ImmutableListMultimap.copyOf(map)); }
From source file:org.ow2.authzforce.core.pdp.impl.CloseableAttributeProvider.java
/** * Instantiates attribute Provider that tries to find attribute values in evaluation context, then, if not there, query the {@code module} providing the requested attribute ID, if any. * * @param attributeFactory//from w w w . j ava 2s. c om * (mandatory) attribute value factory * @param attributeProviderFactories * Attribute Provider factories (Attribute Providers resolve values of attributes absent from the request context). Empty if none. * @return instance of this class * @param strictAttributeIssuerMatch * true iff it is required that AttributeDesignator without Issuer only match request Attributes without Issuer. This mode is not fully compliant with XACML 3.0, 5.29, in the case that * the Issuer is not present; but it performs better and is recommended when all AttributeDesignators have an Issuer (best practice). Set it to false, if you want full compliance with * the XACML 3.0 Attribute Evaluation: "If the Issuer is not present in the AttributeDesignator, then the matching of the attribute to the named attribute SHALL be governed by * AttributeId and DataType attributes alone." * @throws java.lang.IllegalArgumentException * If any Attribute Provider created from {@code attributeProviderFactories} does not provide any attribute. * @throws java.io.IOException * error closing the Attribute Providers created from {@code attributeProviderFactories}, when a {@link IllegalArgumentException} is raised */ public static CloseableAttributeProvider getInstance( final List<CloseableNamedAttributeProvider.DependencyAwareFactory> attributeProviderFactories, final AttributeValueFactoryRegistry attributeFactory, final boolean strictAttributeIssuerMatch) throws IOException { if (attributeProviderFactories == null || attributeProviderFactories.isEmpty()) { return EVALUATION_CONTEXT_ONLY_SCOPED_CLOSEABLE_ATTRIBUTE_PROVIDER; } final ListMultimap<AttributeFqn, NamedAttributeProvider> modulesByAttributeId = ArrayListMultimap.create(); final int moduleCount = attributeProviderFactories.size(); final Set<ModuleAdapter> mutableModuleCloserSet = HashCollections.newUpdatableSet(moduleCount); for (final CloseableNamedAttributeProvider.DependencyAwareFactory attProviderFactory : attributeProviderFactories) { try { final Set<AttributeDesignatorType> requiredAttrs = attProviderFactory.getDependencies(); /* * Each AttributeProviderModule is given a read-only AttributeProvider - aka "dependency attribute Provider" - to find any attribute they require (dependency), based on the attribute * Provider modules that provide these required attributes (set above); read-only so that modules use this attribute Provider only to get required attributes, nothing else. Create this * dependency attribute Provider. */ final AttributeProvider depAttrProvider; if (requiredAttrs == null) { depAttrProvider = ModularAttributeProvider.EVALUATION_CONTEXT_ONLY_SCOPED_ATTRIBUTE_PROVIDER; } else { final ImmutableListMultimap<AttributeFqn, NamedAttributeProvider> immutableCopyOfAttrProviderModsByAttrId = ImmutableListMultimap .copyOf(modulesByAttributeId); depAttrProvider = new ModularAttributeProvider(immutableCopyOfAttrProviderModsByAttrId, requiredAttrs, strictAttributeIssuerMatch); } /* * attrProviderMod closing isn't done in this method but handled in close() method when closing all modules */ final ModuleAdapter moduleAdapter = new ModuleAdapter( attProviderFactory.getInstance(attributeFactory, depAttrProvider)); mutableModuleCloserSet.add(moduleAdapter); for (final AttributeDesignatorType attrDesignator : moduleAdapter.getProvidedAttributes()) { final AttributeFqn attrGUID = AttributeFqns.newInstance(attrDesignator); /* * We allow multiple modules supporting the same attribute designator (as fall-back: if one does not find any value, the next one comes in) */ modulesByAttributeId.put(attrGUID, moduleAdapter.getAdaptedModule()); } } catch (final IllegalArgumentException e) { close(mutableModuleCloserSet); throw e; } } if (modulesByAttributeId.isEmpty()) { return EVALUATION_CONTEXT_ONLY_SCOPED_CLOSEABLE_ATTRIBUTE_PROVIDER; } return new CloseableAttributeProvider(ImmutableListMultimap.copyOf(modulesByAttributeId), HashCollections.newImmutableSet(mutableModuleCloserSet), strictAttributeIssuerMatch); }
From source file:com.tinspx.util.net.Response.java
/** * Creates a new {@code Response}.//from ww w. ja v a 2 s . c om * * @param request the Request that initiated this response * @param uri the URI of this Response * @param queryParams the query parameters of {@code uri} if already * computed; if null, the params will be extracted from uri. * @param code the response code, if available * @param message the response message, if available. null will be * converted to the empty String. * @param redirects the list of redirects that have led up to this Response. * if null, {@link #redirects()} will return an empty List. A defensive copy * of this List is created, so the caller may continue to use and edit this * List after the constructor is called. */ Response(Request request, URI uri, @Nullable ListMultimap<String, String> queryParams, int code, @Nullable String message, @Nullable Iterable<Response> redirects) { this.request = checkNotNull(request); this.uri = checkNotNull(uri); if (queryParams != null) { this.queryParams = ImmutableListMultimap.copyOf(queryParams); } else { this.queryParams = Multimaps.unmodifiableListMultimap(UriUtil.parseQuery(uri)); } this.code = code; this.message = Strings.nullToEmpty(message); this.redirects = redirects != null ? ImmutableList.copyOf(redirects) : ImmutableList.<Response>of(); checkArgument(CollectUtils.allNonNull(this.redirects)); }
From source file:com.facebook.buck.features.python.CxxPythonExtensionDescription.java
private ImmutableMap<CxxPreprocessAndCompile, SourcePath> requireCxxObjects(BuildTarget target, ProjectFilesystem projectFilesystem, ActionGraphBuilder graphBuilder, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, CellPathResolver cellRoots, CxxPlatform cxxPlatform, CxxPythonExtensionDescriptionArg args, ImmutableSet<BuildRule> deps) { // Extract all C/C++ sources from the constructor arg. ImmutableMap<String, CxxSource> srcs = CxxDescriptionEnhancer.parseCxxSources(target, graphBuilder, ruleFinder, pathResolver, cxxPlatform, args); ImmutableMap<Path, SourcePath> headers = CxxDescriptionEnhancer.parseHeaders(target, graphBuilder, ruleFinder, pathResolver, Optional.of(cxxPlatform), args); // Setup the header symlink tree and combine all the preprocessor input from this rule // and all dependencies. HeaderSymlinkTree headerSymlinkTree = CxxDescriptionEnhancer.requireHeaderSymlinkTree(target, projectFilesystem, ruleFinder, graphBuilder, cxxPlatform, headers, HeaderVisibility.PRIVATE, true); ImmutableList<CxxPreprocessorInput> cxxPreprocessorInput = CxxDescriptionEnhancer .collectCxxPreprocessorInput(target, cxxPlatform, graphBuilder, deps, ImmutableListMultimap.copyOf(Multimaps.transformValues( CxxFlags.getLanguageFlagsWithMacros(args.getPreprocessorFlags(), args.getPlatformPreprocessorFlags(), args.getLangPreprocessorFlags(), args.getLangPlatformPreprocessorFlags(), cxxPlatform), f -> CxxDescriptionEnhancer.toStringWithMacrosArgs(target, cellRoots, graphBuilder, cxxPlatform, f))), ImmutableList.of(headerSymlinkTree), ImmutableSet.of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput(cxxPlatform, graphBuilder, deps), args.getRawHeaders()); // Generate rule to build the object files. ImmutableMultimap<CxxSource.Type, Arg> compilerFlags = ImmutableListMultimap .copyOf(Multimaps.transformValues( CxxFlags.getLanguageFlagsWithMacros(args.getCompilerFlags(), args.getPlatformCompilerFlags(), args.getLangCompilerFlags(), args.getLangPlatformCompilerFlags(), cxxPlatform), f -> CxxDescriptionEnhancer.toStringWithMacrosArgs(target, cellRoots, graphBuilder, cxxPlatform, f))); CxxSourceRuleFactory factory = CxxSourceRuleFactory.of(projectFilesystem, target, graphBuilder, pathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, cxxPreprocessorInput, compilerFlags, args.getPrefixHeader(), args.getPrecompiledHeader(), PicType.PIC); return factory.requirePreprocessAndCompileRules(srcs); }
From source file:com.opengamma.strata.loader.fpml.FpmlDocument.java
private static ImmutableListMultimap<String, String> parseParties(XmlElement root) { ListMultimap<String, String> parties = ArrayListMultimap.create(); for (XmlElement child : root.getChildren("party")) { parties.putAll(child.getAttribute(ID), findPartyIds(child)); }//from w w w. jav a 2 s .c o m return ImmutableListMultimap.copyOf(parties); }
From source file:org.immutables.generator.SourceOrdering.java
/** * While we have {@link SourceOrdering}, there's still a problem: We have inheritance hierarchy * and//from www . j av a 2 s . c o m * we want to have all defined or inherited accessors returned as members of target type, like * {@link Elements#getAllMembers(TypeElement)}, but we need to have them properly and stably * sorted. * This implementation doesn't try to correctly resolve order for accessors inherited from * different supertypes(interfaces), just something that stable and reasonable wrt source ordering * without handling complex cases. * @param elements the elements utility * @param types the types utility * @param type the type to traverse * @return provider of all accessors in source order and mapping */ public static AccessorProvider getAllAccessorsProvider(final Elements elements, final Types types, final TypeElement type) { class CollectedOrdering extends Ordering<Element> { class Intratype { Ordering<String> ordering; int rank; } final Map<String, Intratype> accessorOrderings = Maps.newLinkedHashMap(); final List<TypeElement> linearizedTypes = Lists.newArrayList(); final Predicate<String> accessorNotYetInOrderings = Predicates .not(Predicates.in(accessorOrderings.keySet())); final ArrayListMultimap<String, TypeElement> accessorMapping = ArrayListMultimap.create(); CollectedOrdering() { traverse(type); traverseObjectForInterface(); } private void traverseObjectForInterface() { if (type.getKind() == ElementKind.INTERFACE) { traverse(elements.getTypeElement(Object.class.getName())); } } void traverse(@Nullable TypeElement element) { if (element == null) { return; } collectEnclosing(element); traverse(asTypeElement(element.getSuperclass())); for (TypeMirror implementedInterface : element.getInterfaces()) { traverse(asTypeElement(implementedInterface)); } } @Nullable TypeElement asTypeElement(TypeMirror type) { if (type.getKind() == TypeKind.DECLARED) { return (TypeElement) ((DeclaredType) type).asElement(); } return null; } void collectEnclosing(TypeElement type) { FluentIterable<String> accessorsInType = FluentIterable .from(SourceOrdering.getEnclosedElements(type)).filter(IsParameterlessNonstatic.PREDICATE) .transform(ToSimpleName.FUNCTION); for (String accessor : accessorsInType) { accessorMapping.put(accessor, type); } List<String> accessors = accessorsInType.filter(accessorNotYetInOrderings).toList(); Intratype intratype = new Intratype(); intratype.rank = linearizedTypes.size(); intratype.ordering = Ordering.explicit(accessors); for (String name : accessors) { accessorOrderings.put(name, intratype); } linearizedTypes.add(type); } @Override public int compare(Element left, Element right) { String leftKey = ToSimpleName.FUNCTION.apply(left); String rightKey = ToSimpleName.FUNCTION.apply(right); Intratype leftIntratype = accessorOrderings.get(leftKey); Intratype rightIntratype = accessorOrderings.get(rightKey); if (leftIntratype == null || rightIntratype == null) { // FIXME figure out why it happens (null) return Boolean.compare(leftIntratype == null, rightIntratype == null); } return leftIntratype == rightIntratype ? leftIntratype.ordering.compare(leftKey, rightKey) : Integer.compare(leftIntratype.rank, rightIntratype.rank); } } final CollectedOrdering ordering = new CollectedOrdering(); return new AccessorProvider() { ImmutableListMultimap<String, TypeElement> accessorMapping = ImmutableListMultimap .copyOf(ordering.accessorMapping); ImmutableList<ExecutableElement> sortedList = FluentIterable .from(ElementFilter.methodsIn(elements.getAllMembers(type))) .filter(IsParameterlessNonstatic.PREDICATE).toSortedList(ordering); @Override public ImmutableListMultimap<String, TypeElement> accessorMapping() { return accessorMapping; } @Override public ImmutableList<ExecutableElement> get() { return sortedList; } }; }
From source file:com.google.gerrit.pgm.RebuildNoteDb.java
private ImmutableListMultimap<Project.NameKey, Change.Id> getChangesByProject() throws OrmException { // Memorize all changes so we can close the db connection and allow // rebuilder threads to use the full connection pool. ListMultimap<Project.NameKey, Change.Id> changesByProject = MultimapBuilder.hashKeys().arrayListValues() .build();/*from w w w .j a v a2 s . co m*/ try (ReviewDb db = schemaFactory.open()) { if (projects.isEmpty() && !changes.isEmpty()) { Iterable<Change> todo = unwrapDb(db).changes().get(Iterables.transform(changes, Change.Id::new)); for (Change c : todo) { changesByProject.put(c.getProject(), c.getId()); } } else { for (Change c : unwrapDb(db).changes().all()) { boolean include = false; if (projects.isEmpty() && changes.isEmpty()) { include = true; } else if (!projects.isEmpty() && projects.contains(c.getProject().get())) { include = true; } else if (!changes.isEmpty() && changes.contains(c.getId().get())) { include = true; } if (include) { changesByProject.put(c.getProject(), c.getId()); } } } return ImmutableListMultimap.copyOf(changesByProject); } }