Java Code Examples for com.google.common.collect.ImmutableSetMultimap#copyOf()

The following examples show how to use com.google.common.collect.ImmutableSetMultimap#copyOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorkspaceAndProjectGenerator.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Transform a map from scheme name to `TargetNode` to scheme name to the associated `PBXProject`.
 *
 * @param schemeToTargetNodes Map to transform.
 * @return Map of scheme name to associated `PXBProject`s.
 */
private static ImmutableSetMultimap<String, PBXTarget> mapFromSchemeToPBXProject(
    ImmutableSetMultimap<String, ? extends TargetNode<?>> schemeToTargetNodes,
    ImmutableMap<BuildTarget, PBXTarget> buildTargetToPBXTarget) {
  ImmutableSetMultimap<String, PBXTarget> schemeToPBXProject =
      ImmutableSetMultimap.copyOf(
          schemeToTargetNodes.entries().stream()
              .map(
                  stringTargetNodeEntry ->
                      Maps.immutableEntry(
                          stringTargetNodeEntry.getKey(),
                          buildTargetToPBXTarget.get(
                              stringTargetNodeEntry.getValue().getBuildTarget())))
              .filter(
                  stringPBXTargetEntry -> {
                    return stringPBXTargetEntry.getValue() != null;
                  })
              .collect(Collectors.toList()));
  return schemeToPBXProject;
}
 
Example 2
Source File: EventArgScoringAlignment.java    From tac-kbp-eal with MIT License 6 votes vote down vote up
private EventArgScoringAlignment(final Symbol docID,
    final ArgumentOutput argumentOutput,
    final AnswerKey answerKey,
    final Iterable<EquivClassType> truePositiveECs,
    final Iterable<EquivClassType> falsePositiveECs,
    final Iterable<EquivClassType> falseNegativeECs,
    final Iterable<EquivClassType> unassessed,
    final Multimap<EquivClassType, AssessedResponse> ecsToAnswerKey,
    final Multimap<EquivClassType, Response> ecsToSystem) {
  this.docID = checkNotNull(docID);
  this.argumentOutput = checkNotNull(argumentOutput);
  this.answerKey = checkNotNull(answerKey);
  this.truePositiveECs = ImmutableSet.copyOf(truePositiveECs);
  this.falsePositiveECs = ImmutableSet.copyOf(falsePositiveECs);
  this.falseNegativeECs = ImmutableSet.copyOf(falseNegativeECs);
  this.unassessed = ImmutableSet.copyOf(unassessed);
  this.ecsToAnswerKey = ImmutableSetMultimap.copyOf(ecsToAnswerKey);
  this.ecsToSystem = ImmutableSetMultimap.copyOf(ecsToSystem);
}
 
Example 3
Source File: OwnersReport.java    From buck with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
OwnersReport updatedWith(OwnersReport other) {
  // If either this or other are empty, the intersection below for missing files will get
  // screwed up. This mostly is just so that when we do a fold elsewhere in the class against
  // a default empty object, we don't obliterate inputsWithNoOwners
  if (this.isEmpty()) {
    return other;
  } else if (other.isEmpty()) {
    return this;
  }

  SetMultimap<TargetNode<?>, Path> updatedOwners = TreeMultimap.create(owners);
  updatedOwners.putAll(other.owners);

  return new OwnersReport(
      ImmutableSetMultimap.copyOf(updatedOwners),
      Sets.intersection(inputsWithNoOwners, other.inputsWithNoOwners).immutableCopy(),
      Sets.union(nonExistentInputs, other.nonExistentInputs).immutableCopy(),
      Sets.union(nonFileInputs, other.nonFileInputs).immutableCopy());
}
 
Example 4
Source File: RdeStagingAction.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private ImmutableSetMultimap<String, PendingDeposit> getStandardPendingDeposits() {
  if (directory.isPresent()) {
    throw new BadRequestException("Directory parameter not allowed in standard operation");
  }
  if (!modeStrings.isEmpty()) {
    throw new BadRequestException("Mode parameter not allowed in standard operation");
  }
  if (!tlds.isEmpty()) {
    throw new BadRequestException("Tld parameter not allowed in standard operation");
  }
  if (!watermarks.isEmpty()) {
    throw new BadRequestException("Watermark parameter not allowed in standard operation");
  }
  if (revision.isPresent()) {
    throw new BadRequestException("Revision parameter not allowed in standard operation");
  }

  return ImmutableSetMultimap.copyOf(
      Multimaps.filterValues(
          pendingDepositChecker.getTldsAndWatermarksPendingDepositForRdeAndBrda(),
          pending -> {
            if (clock.nowUtc().isBefore(pending.watermark().plus(transactionCooldown))) {
              logger.atInfo().log(
                  "Ignoring within %s cooldown: %s", transactionCooldown, pending);
              return false;
            } else {
              return true;
            }
          }));
}
 
Example 5
Source File: AliasConfig.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * In a {@link BuckConfig}, an alias can either refer to a fully-qualified build target, or an
 * alias defined earlier in the {@code alias} section. The mapping produced by this method
 * reflects the result of resolving all aliases as values in the {@code alias} section.
 */
private ImmutableSetMultimap<String, UnconfiguredBuildTarget> createAliasToBuildTargetMap(
    ImmutableMap<String, String> rawAliasMap) {
  // We use a LinkedHashMap rather than an ImmutableMap.Builder because we want both (1) order to
  // be preserved, and (2) the ability to inspect the Map while building it up.
  SetMultimap<String, UnconfiguredBuildTarget> aliasToBuildTarget = LinkedHashMultimap.create();
  for (Map.Entry<String, String> aliasEntry : rawAliasMap.entrySet()) {
    String alias = aliasEntry.getKey();
    validateAliasName(alias);

    // Determine whether the mapping is to a build target or to an alias.
    List<String> values = Splitter.on(' ').splitToList(aliasEntry.getValue());
    for (String value : values) {
      Set<UnconfiguredBuildTarget> buildTargets;
      if (isValidAliasName(value)) {
        buildTargets = aliasToBuildTarget.get(value);
        if (buildTargets.isEmpty()) {
          throw new HumanReadableException("No alias for: %s.", value);
        }
      } else if (value.isEmpty()) {
        continue;
      } else {
        // Here we parse the alias values with a BuildTargetParser to be strict. We could be
        // looser and just grab everything between "//" and ":" and assume it's a valid base path.
        buildTargets =
            ImmutableSet.of(
                getDelegate().getUnconfiguredBuildTargetForFullyQualifiedTarget(value));
      }
      aliasToBuildTarget.putAll(alias, buildTargets);
    }
  }
  return ImmutableSetMultimap.copyOf(aliasToBuildTarget);
}
 
Example 6
Source File: DiscretizationUtil.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
public SetMultimap<Object, Integer> getValueRowsMap(DataType dataType){
	SetMultimap<Object, Integer> result = this.valueRowsMap.get(dataType);

	if(result == null){
		result = ImmutableSetMultimap.copyOf(parseColumnValues(dataType));

		this.valueRowsMap.put(dataType, result);
	}

	return result;
}
 
Example 7
Source File: ModuleAbiSanitizer.java    From bundletool with Apache License 2.0 5 votes vote down vote up
private static ImmutableMultimap<ZipPath, ModuleEntry> discardAbiDirsWithTooFewFiles(
    ImmutableMultimap<ZipPath, ModuleEntry> libFilesByAbiDir) {
  int maxAbiFiles =
      libFilesByAbiDir.asMap().values().stream().mapToInt(Collection::size).max().orElse(0);

  // Create a set-based multimap for fast look-ups.
  return ImmutableSetMultimap.copyOf(
      Multimaps.filterKeys(
          libFilesByAbiDir, abiDir -> libFilesByAbiDir.get(abiDir).size() == maxAbiFiles));
}
 
Example 8
Source File: ImmutableRatesProviderGenerator.java    From Strata with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance.
 * 
 * @param knownProvider  the underlying known provider
 * @param curveDefinitions  the curve definitions
 * @param curveMetadata  the curve metadata
 * @param discountCurveNames  the map of discount curves
 * @param forwardCurveNames  the map of index forward curves
 */
private ImmutableRatesProviderGenerator(
    ImmutableRatesProvider knownProvider,
    List<CurveDefinition> curveDefinitions,
    List<CurveMetadata> curveMetadata,
    SetMultimap<CurveName, Currency> discountCurveNames,
    SetMultimap<CurveName, Index> forwardCurveNames) {

  this.knownProvider = ArgChecker.notNull(knownProvider, "knownProvider");
  this.curveDefinitions = ImmutableList.copyOf(ArgChecker.notNull(curveDefinitions, "curveDefinitions"));
  this.curveMetadata = ImmutableList.copyOf(ArgChecker.notNull(curveMetadata, "curveMetadata"));
  this.discountCurveNames = ImmutableSetMultimap.copyOf(ArgChecker.notNull(discountCurveNames, "discountCurveNames"));
  this.forwardCurveNames = ImmutableSetMultimap.copyOf(ArgChecker.notNull(forwardCurveNames, "forwardCurveNames"));
}
 
Example 9
Source File: MutableContextSetImpl.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public @NonNull ImmutableContextSet immutableCopy() {
    // if the map is empty, don't create a new instance
    if (this.map.isEmpty()) {
        return ImmutableContextSetImpl.EMPTY;
    }
    synchronized (this.map) {
        return new ImmutableContextSetImpl(ImmutableSetMultimap.copyOf(this.map));
    }
}
 
Example 10
Source File: TreeMultimapState.java    From Rails with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ImmutableSetMultimap<K,V> view() {
    return ImmutableSetMultimap.copyOf(map);
}
 
Example 11
Source File: MutableDirectedGraph.java    From buck with Apache License 2.0 4 votes vote down vote up
ImmutableSetMultimap<T, T> createImmutableCopyOfIncomingEdges() {
  return ImmutableSetMultimap.copyOf(incomingEdges);
}
 
Example 12
Source File: FilteringSchemaContextProxy.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Filters SchemaContext for yang modules.
 *
 * @param delegate original SchemaContext
 * @param rootModules modules (yang schemas) to be available and all their dependencies (modules importing
 *                    rootModule and whole chain of their imports)
 * @param additionalModuleIds (additional) modules (yang schemas) to be available and whole chain of their imports
 */
public FilteringSchemaContextProxy(final SchemaContext delegate, final Collection<ModuleId> rootModules,
        final Set<ModuleId> additionalModuleIds) {
    requireNonNull(rootModules, "Base modules cannot be null.");
    requireNonNull(additionalModuleIds, "Additional modules cannot be null.");

    final Builder<Module> filteredModulesBuilder = new Builder<>();

    // preparing map to get all modules with one name but difference in revision
    final TreeMultimap<String, Module> nameToModulesAll = TreeMultimap.create(String::compareTo,
        REVISION_COMPARATOR);

    nameToModulesAll.putAll(getStringModuleMap(delegate));

    // in case there is a particular dependency to view filteredModules/YANG models dependency is checked
    // for module name and imports
    processForRootModules(delegate, rootModules, filteredModulesBuilder);

    // adding additional modules
    processForAdditionalModules(delegate, additionalModuleIds, filteredModulesBuilder);

    filteredModulesBuilder.addAll(getImportedModules(
            Maps.uniqueIndex(delegate.getModules(), ModuleId.MODULE_TO_MODULE_ID::apply),
            filteredModulesBuilder.build(), nameToModulesAll));

    /**
     * Instead of doing this on each invocation of getModules(), pre-compute it once and keep it around.
     */
    final List<Module> sortedModules = new ArrayList<>(filteredModulesBuilder.build());
    sortedModules.sort(NAME_REVISION_COMPARATOR);
    this.filteredModules = ImmutableSet.copyOf(sortedModules);

    final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(new TreeMap<>(),
        AbstractSchemaContext::createModuleSet);
    final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(new TreeMap<>(),
        AbstractSchemaContext::createModuleSet);
    final ImmutableMap.Builder<QNameModule, Module> moduleMapBuilder = ImmutableMap.builder();
    for (final Module module : filteredModules) {
        nameMap.put(module.getName(), module);
        nsMap.put(module.getNamespace(), module);
        moduleMapBuilder.put(module.getQNameModule(), module);
    }

    namespaceToModules = ImmutableSetMultimap.copyOf(nsMap);
    nameToModules = ImmutableSetMultimap.copyOf(nameMap);
    moduleMap = moduleMapBuilder.build();
}
 
Example 13
Source File: Report.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
public SetMultimap<String, BugDescription> getReproducedBugsMap() {
    return ImmutableSetMultimap.copyOf(reproducedBugs);
}
 
Example 14
Source File: JethroDataSqlDialect.java    From Quicksql with MIT License 4 votes vote down vote up
public JethroInfo(Multimap<String, JethroSupportedFunction> supportedFunctions) {
  this.supportedFunctions = ImmutableSetMultimap.copyOf(supportedFunctions);
}
 
Example 15
Source File: ClusterStateImpl.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
@Override
public Multimap<String, PreemptionVictim> getSlavesToActiveTasks() {
  synchronized (victims) {
    return ImmutableSetMultimap.copyOf(victims);
  }
}
 
Example 16
Source File: HashGenerationOptimizer.java    From presto with Apache License 2.0 4 votes vote down vote up
private HashComputationSet(Multimap<HashComputation, HashComputation> hashes)
{
    requireNonNull(hashes, "hashes is null");
    this.hashes = ImmutableSetMultimap.copyOf(hashes);
}
 
Example 17
Source File: MutableDirectedGraph.java    From buck with Apache License 2.0 4 votes vote down vote up
ImmutableSetMultimap<T, T> createImmutableCopyOfOutgoingEdges() {
  return ImmutableSetMultimap.copyOf(outgoingEdges);
}
 
Example 18
Source File: JethroDataSqlDialect.java    From calcite with Apache License 2.0 4 votes vote down vote up
public JethroInfo(Multimap<String, JethroSupportedFunction> supportedFunctions) {
  this.supportedFunctions = ImmutableSetMultimap.copyOf(supportedFunctions);
}
 
Example 19
Source File: AttachToContentAnchorageOperation.java    From gef with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link AttachToContentAnchorageOperation} to attach the
 * given <i>anchored</i> {@link IContentPart} to the given
 * <i>contentAnchorage</i> under the specified <i>role</i>, so that it will
 * be returned by subsequent calls to
 * {@link IContentPart#getContentAnchoragesUnmodifiable()}.
 *
 * @param anchored
 *            The {@link IContentPart} which is to be attached to the given
 *            <i>contentAnchorage</i>.
 * @param contentAnchorage
 *            The content object to which the given <i>anchored</i> is to be
 *            attached.
 * @param role
 *            The role under which the <i>contentAnchorage</i> is anchored.
 */
public AttachToContentAnchorageOperation(
		IContentPart<? extends Node> anchored, Object contentAnchorage,
		String role) {
	super("Attach To Content Anchorage");
	this.anchored = anchored;
	this.contentAnchorage = contentAnchorage;
	this.initialContentAnchorages = ImmutableSetMultimap
			.copyOf(anchored.getContentAnchoragesUnmodifiable());
	this.role = role;
}
 
Example 20
Source File: SchemaContextFactoryConfiguration.java    From yangtools with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Set YANG modules which can be deviated by specified modules during the parsing process. Map key (QNameModule)
 * denotes a module which can be deviated by the modules in the Map value.
 *
 * @param modulesDeviatedByModules Map of YANG modules (Map key) which can be deviated by specified modules
 *                                 (Map values) in the final SchemaContext. If the map is empty, no deviations
 *                                 encountered will be supported. If the map is null, all deviations will be
 *                                 applied.
 * @return this builder
 */
public @NonNull Builder setModulesDeviatedByModules(
        final @Nullable SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules) {
    this.modulesDeviatedByModules = modulesDeviatedByModules != null
            ? ImmutableSetMultimap.copyOf(modulesDeviatedByModules) : null;
    return this;
}