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

The following examples show how to use com.google.common.collect.ImmutableSetMultimap#builder() . 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: ImmutableContextSetImpl.java    From LuckPerms with MIT License 6 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (o == this) return true;
    if (!(o instanceof ContextSet)) return false;
    final ContextSet that = (ContextSet) o;

    // fast(er) path for ImmutableContextSet comparisons
    if (that instanceof ImmutableContextSetImpl) {
        ImmutableContextSetImpl immutableThat = (ImmutableContextSetImpl) that;
        if (this.hashCode != immutableThat.hashCode) return false;
    }

    final Multimap<String, String> thatBacking;
    if (that instanceof AbstractContextSet) {
        thatBacking = ((AbstractContextSet) that).backing();
    } else {
        Map<String, Set<String>> thatMap = that.toMap();
        ImmutableSetMultimap.Builder<String, String> thatBuilder = ImmutableSetMultimap.builder();
        for (Map.Entry<String, Set<String>> e : thatMap.entrySet()) {
            thatBuilder.putAll(e.getKey(), e.getValue());
        }
        thatBacking = thatBuilder.build();
    }

    return backing().equals(thatBacking);
}
 
Example 2
Source File: DocumentFieldDependencyMap.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 6 votes vote down vote up
public Builder add(final DocumentFieldDependencyMap dependencies)
{
	if (dependencies == null || dependencies == EMPTY)
	{
		return this;
	}

	for (final Map.Entry<DependencyType, Multimap<String, String>> l1 : dependencies.type2name2dependencies.entrySet())
	{
		final DependencyType dependencyType = l1.getKey();

		ImmutableSetMultimap.Builder<String, String> name2dependencies = type2name2dependencies.get(dependencyType);
		if (name2dependencies == null)
		{
			name2dependencies = ImmutableSetMultimap.builder();
			type2name2dependencies.put(dependencyType, name2dependencies);
		}

		name2dependencies.putAll(l1.getValue());
	}

	return this;
}
 
Example 3
Source File: ServiceManager.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
ImmutableMultimap<State, Service> servicesByState() {
  ImmutableSetMultimap.Builder<State, Service> builder = ImmutableSetMultimap.builder();
  monitor.enter();
  try {
    for (Entry<State, Service> entry : servicesByState.entries()) {
      if (!(entry.getValue() instanceof NoOpService)) {
        builder.put(entry);
      }
    }
  } finally {
    monitor.leave();
  }
  return builder.build();
}
 
Example 4
Source File: ServiceManager.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
ImmutableMultimap<State, Service> servicesByState() {
  ImmutableSetMultimap.Builder<State, Service> builder = ImmutableSetMultimap.builder();
  monitor.enter();
  try {
    for (Entry<State, Service> entry : servicesByState.entries()) {
      if (!(entry.getValue() instanceof NoOpService)) {
        builder.put(entry);
      }
    }
  } finally {
    monitor.leave();
  }
  return builder.build();
}
 
Example 5
Source File: Feedback.java    From copybara with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a multimap containing enough data to fingerprint the actions for validation
 * purposes.
 */
public ImmutableSetMultimap<String, ImmutableSetMultimap<String, String>>
    getActionsDescription() {
  Builder<String, ImmutableSetMultimap<String, String>> descriptionBuilder =
      ImmutableSetMultimap.builder();
  for (Action action : actions) {
    descriptionBuilder.put(action.getName(), action.describe());
  }
  return descriptionBuilder.build();
}
 
Example 6
Source File: DataBindingV2Context.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Collects all the labels and Java packages of the given rule and every rule that has databinding
 * in the transitive dependencies of the given rule.
 *
 * @return A multimap of Java Package (as a string) to labels which have that Java package.
 */
private static ImmutableMultimap<String, String> getJavaPackagesWithDatabindingToLabelMap(
    RuleContext context) {

  // Since this method iterates over the labels in deps without first constructing a NestedSet,
  // multiple android_library rules could (and almost certainly will) be reached from dependencies
  // at the top-level which would produce false positives, so use a SetMultimap to avoid this.
  ImmutableMultimap.Builder<String, String> javaPackagesToLabel = ImmutableSetMultimap.builder();

  // Add this top-level rule's label and java package, e.g. for when an android_binary with
  // databinding depends on an android_library with databinding in the same java package.
  String label = context.getRule().getLabel().toString();
  String javaPackage = AndroidCommon.getJavaPackage(context);

  javaPackagesToLabel.put(javaPackage, label);

  if (context.attributes().has("deps", BuildType.LABEL_LIST)) {

    Iterable<DataBindingV2Provider> providers =
        context.getPrerequisites("deps", TransitionMode.TARGET, DataBindingV2Provider.PROVIDER);

    for (DataBindingV2Provider provider : providers) {
      for (LabelJavaPackagePair labelJavaPackagePair :
          provider.getTransitiveLabelAndJavaPackages().toList()) {
        javaPackagesToLabel.put(
            labelJavaPackagePair.getJavaPackage(), labelJavaPackagePair.getLabel());
      }
    }
  }

  return javaPackagesToLabel.build();
}
 
Example 7
Source File: APKModuleGraph.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Group the classes in the input jars into a multimap based on the APKModule they belong to
 *
 * @param apkModuleToJarPathMap the mapping of APKModules to the path for the jar files
 * @param translatorFunction function used to translate the class names to obfuscated names
 * @param filesystem filesystem representation for resolving paths
 * @return The mapping of APKModules to the class names they contain
 * @throws IOException
 */
public static ImmutableMultimap<APKModule, String> getAPKModuleToClassesMap(
    ImmutableMultimap<APKModule, Path> apkModuleToJarPathMap,
    Function<String, String> translatorFunction,
    ProjectFilesystem filesystem)
    throws IOException {
  ImmutableMultimap.Builder<APKModule, String> builder = ImmutableSetMultimap.builder();
  if (!apkModuleToJarPathMap.isEmpty()) {
    for (APKModule dexStore : apkModuleToJarPathMap.keySet()) {
      for (Path jarFilePath : apkModuleToJarPathMap.get(dexStore)) {
        ClasspathTraverser classpathTraverser = new DefaultClasspathTraverser();
        classpathTraverser.traverse(
            new ClasspathTraversal(ImmutableSet.of(jarFilePath), filesystem) {
              @Override
              public void visit(FileLike entry) {
                if (!entry.getRelativePath().endsWith(".class")) {
                  // ignore everything but class files in the jar.
                  return;
                }

                String classpath = entry.getRelativePath().replaceAll("\\.class$", "");

                if (translatorFunction.apply(classpath) != null) {
                  builder.put(dexStore, translatorFunction.apply(classpath));
                }
              }
            });
      }
    }
  }
  return builder.build();
}
 
Example 8
Source File: ServiceManager.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
ImmutableMultimap<State, Service> servicesByState() {
  ImmutableSetMultimap.Builder<State, Service> builder = ImmutableSetMultimap.builder();
  monitor.enter();
  try {
    for (Entry<State, Service> entry : servicesByState.entries()) {
      if (!(entry.getValue() instanceof NoOpService)) {
        builder.put(entry);
      }
    }
  } finally {
    monitor.leave();
  }
  return builder.build();
}
 
Example 9
Source File: BindingGraph.java    From dagger2-sample with Apache License 2.0 5 votes vote down vote up
private <B extends ContributionBinding> ImmutableSetMultimap<Key, B> explicitBindingsByKey(
    Iterable<? extends B> bindings) {
  // Multimaps.index() doesn't do ImmutableSetMultimaps.
  ImmutableSetMultimap.Builder<Key, B> builder = ImmutableSetMultimap.builder();
  for (B binding : bindings) {
    builder.put(binding.key(), binding);
  }
  return builder.build();
}
 
Example 10
Source File: ImmutableSetMultimapJsonDeserializer.java    From gwt-jackson with Apache License 2.0 5 votes vote down vote up
@Override
protected ImmutableSetMultimap<K, V> doDeserialize( JsonReader reader, JsonDeserializationContext ctx,
                                                    JsonDeserializerParameters params ) {
    ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder();
    buildMultimap( reader, ctx, params, builder );
    return builder.build();
}
 
Example 11
Source File: ElementCostOfDataStructures.java    From memory-measurer with Apache License 2.0 5 votes vote down vote up
public ImmutableSetMultimap construct(int entries) {
  ImmutableSetMultimap.Builder builder = ImmutableSetMultimap.builder();
  Object key = newEntry();
  for (int i = 0; i < entries; i++) {
    builder.put(key, newEntry());
  }
  return builder.build();
}
 
Example 12
Source File: _CorpusQueryAssessments.java    From tac-kbp-eal with MIT License 5 votes vote down vote up
@MoveToBUECommon
private static <K1, K2, V> ImmutableSetMultimap<K2, V> copyWithTransformedKeys(
    final Multimap<K1,V> setMultimap,
    final Function<? super K1, ? extends K2> injection) {
  final ImmutableSetMultimap.Builder<K2,V> ret = ImmutableSetMultimap.builder();
  for (final Map.Entry<K1, V> entry : setMultimap.entries()) {
    ret.put(checkNotNull(injection.apply(entry.getKey())), entry.getValue());
  }
  return ret.build();
}
 
Example 13
Source File: ElementCostOfDataStructures.java    From memory-measurer with Apache License 2.0 5 votes vote down vote up
public ImmutableSetMultimap construct(int entries) {
  ImmutableSetMultimap.Builder builder = ImmutableSetMultimap.builder();
  for (int i = 0; i < entries; i++) {
    builder.put(newEntry(), newEntry());
  }
  return builder.build();
}
 
Example 14
Source File: ServiceManager.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
ImmutableMultimap<State, Service> servicesByState() {
  ImmutableSetMultimap.Builder<State, Service> builder = ImmutableSetMultimap.builder();
  monitor.enter();
  try {
    for (Entry<State, Service> entry : servicesByState.entries()) {
      if (!(entry.getValue() instanceof NoOpService)) {
        builder.put(entry);
      }
    }
  } finally {
    monitor.leave();
  }
  return builder.build();
}
 
Example 15
Source File: ClusterStateImplTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private void assertVictims(IAssignedTask... tasks) {
  ImmutableMultimap.Builder<String, PreemptionVictim> victims = ImmutableSetMultimap.builder();
  for (IAssignedTask task : tasks) {
    victims.put(task.getSlaveId(), PreemptionVictim.fromTask(task));
  }
  assertEquals(victims.build(), state.getSlavesToActiveTasks());
}
 
Example 16
Source File: DefaultTopology.java    From onos with Apache License 2.0 5 votes vote down vote up
private ImmutableSetMultimap<ClusterId, ConnectPoint> buildBroadcastSets() {
    Builder<ClusterId, ConnectPoint> builder = ImmutableSetMultimap.builder();
    for (TopologyCluster cluster : clusters.get().values()) {
        addClusterBroadcastSet(cluster, builder);
    }
    return builder.build();
}
 
Example 17
Source File: BasicAnnotationProcessor.java    From auto with Apache License 2.0 5 votes vote down vote up
private static ImmutableSetMultimap<String, Element> toClassNameKeyedMultimap(
    SetMultimap<TypeElement, Element> elements) {
  ImmutableSetMultimap.Builder<String, Element> builder = ImmutableSetMultimap.builder();
  elements
      .asMap()
      .forEach(
          (annotation, element) ->
              builder.putAll(annotation.getQualifiedName().toString(), element));
  return builder.build();
}
 
Example 18
Source File: Checkpoints.java    From presto with Apache License 2.0 4 votes vote down vote up
public static Map<StreamId, StreamCheckpoint> getStreamCheckpoints(
        Set<OrcColumnId> columns,
        ColumnMetadata<OrcType> columnTypes,
        boolean compressed,
        int rowGroupId,
        ColumnMetadata<ColumnEncoding> columnEncodings,
        Map<StreamId, Stream> streams,
        Map<StreamId, List<RowGroupIndex>> columnIndexes)
        throws InvalidCheckpointException
{
    ImmutableSetMultimap.Builder<OrcColumnId, StreamKind> streamKindsBuilder = ImmutableSetMultimap.builder();
    for (Stream stream : streams.values()) {
        streamKindsBuilder.put(stream.getColumnId(), stream.getStreamKind());
    }
    SetMultimap<OrcColumnId, StreamKind> streamKinds = streamKindsBuilder.build();

    ImmutableMap.Builder<StreamId, StreamCheckpoint> checkpoints = ImmutableMap.builder();
    for (Map.Entry<StreamId, List<RowGroupIndex>> entry : columnIndexes.entrySet()) {
        OrcColumnId columnId = entry.getKey().getColumnId();

        if (!columns.contains(columnId)) {
            continue;
        }

        List<Integer> positionsList = entry.getValue().get(rowGroupId).getPositions();

        ColumnEncodingKind columnEncoding = columnEncodings.get(columnId).getColumnEncodingKind();
        OrcTypeKind columnType = columnTypes.get(columnId).getOrcTypeKind();
        Set<StreamKind> availableStreams = streamKinds.get(columnId);

        ColumnPositionsList columnPositionsList = new ColumnPositionsList(columnId, columnType, positionsList);
        switch (columnType) {
            case BOOLEAN:
                checkpoints.putAll(getBooleanColumnCheckpoints(columnId, compressed, availableStreams, columnPositionsList));
                break;
            case BYTE:
                checkpoints.putAll(getByteColumnCheckpoints(columnId, compressed, availableStreams, columnPositionsList));
                break;
            case SHORT:
            case INT:
            case LONG:
            case DATE:
                checkpoints.putAll(getLongColumnCheckpoints(columnId, columnEncoding, compressed, availableStreams, columnPositionsList));
                break;
            case FLOAT:
                checkpoints.putAll(getFloatColumnCheckpoints(columnId, compressed, availableStreams, columnPositionsList));
                break;
            case DOUBLE:
                checkpoints.putAll(getDoubleColumnCheckpoints(columnId, compressed, availableStreams, columnPositionsList));
                break;
            case TIMESTAMP:
                checkpoints.putAll(getTimestampColumnCheckpoints(columnId, columnEncoding, compressed, availableStreams, columnPositionsList));
                break;
            case BINARY:
            case STRING:
            case VARCHAR:
            case CHAR:
                checkpoints.putAll(getSliceColumnCheckpoints(columnId, columnEncoding, compressed, availableStreams, columnPositionsList));
                break;
            case LIST:
            case MAP:
                checkpoints.putAll(getListOrMapColumnCheckpoints(columnId, columnEncoding, compressed, availableStreams, columnPositionsList));
                break;
            case STRUCT:
                checkpoints.putAll(getStructColumnCheckpoints(columnId, compressed, availableStreams, columnPositionsList));
                break;
            case DECIMAL:
                checkpoints.putAll(getDecimalColumnCheckpoints(columnId, columnEncoding, compressed, availableStreams, columnPositionsList));
                break;
            default:
                throw new IllegalArgumentException("Unsupported column type " + columnType);
        }
    }
    return checkpoints.build();
}
 
Example 19
Source File: WorkspaceAndProjectGenerator.java    From buck with Apache License 2.0 4 votes vote down vote up
private void buildWorkspaceSchemes(
    TargetGraph projectGraph,
    boolean includeProjectTests,
    boolean includeDependenciesTests,
    String workspaceName,
    XcodeWorkspaceConfigDescriptionArg workspaceArguments,
    ImmutableMap.Builder<String, XcodeWorkspaceConfigDescriptionArg> schemeConfigsBuilder,
    ImmutableSetMultimap.Builder<String, Optional<TargetNode<?>>>
        schemeNameToSrcTargetNodeBuilder,
    ImmutableSetMultimap.Builder<String, TargetNode<?>> buildForTestNodesBuilder,
    ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescriptionArg>> testsBuilder) {
  ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescriptionArg>>
      extraTestNodesBuilder = ImmutableSetMultimap.builder();
  addWorkspaceScheme(
      xcodeDescriptions,
      projectGraph,
      dependenciesCache,
      workspaceName,
      workspaceArguments,
      schemeConfigsBuilder,
      schemeNameToSrcTargetNodeBuilder,
      extraTestNodesBuilder);
  addWorkspaceExtensionSchemes(
      projectGraph,
      workspaceName,
      workspaceArguments,
      schemeConfigsBuilder,
      schemeNameToSrcTargetNodeBuilder);
  addExtraWorkspaceSchemes(
      xcodeDescriptions,
      projectGraph,
      dependenciesCache,
      workspaceArguments.getExtraSchemes(),
      schemeConfigsBuilder,
      schemeNameToSrcTargetNodeBuilder,
      extraTestNodesBuilder);
  ImmutableSetMultimap<String, Optional<TargetNode<?>>> schemeNameToSrcTargetNode =
      schemeNameToSrcTargetNodeBuilder.build();
  ImmutableSetMultimap<String, TargetNode<AppleTestDescriptionArg>> extraTestNodes =
      extraTestNodesBuilder.build();

  buildWorkspaceSchemeTests(
      workspaceArguments.getSrcTarget(),
      projectGraph,
      includeProjectTests,
      includeDependenciesTests,
      schemeNameToSrcTargetNode,
      extraTestNodes,
      testsBuilder,
      buildForTestNodesBuilder);
}
 
Example 20
Source File: TargetsCommand.java    From buck with Apache License 2.0 4 votes vote down vote up
private ExitCode runWithExecutor(CommandRunnerParams params, ListeningExecutorService executor)
    throws IOException, InterruptedException, BuildFileParseException, CycleException,
        VersionException {
  if (isShowOutput) {
    CommandHelper.maybePrintShowOutputWarning(
        params.getBuckConfig().getView(CliConfig.class),
        params.getConsole().getAnsi(),
        params.getBuckEventBus());
  }
  Optional<ImmutableSet<Class<? extends BaseDescription<?>>>> descriptionClasses =
      getDescriptionClassFromParams(params);
  if (!descriptionClasses.isPresent()) {
    return ExitCode.FATAL_GENERIC;
  }

  // shortcut to old plain simple format
  if (!(isShowCellPath
      || isShowOutput
      || isShowOutputs
      || isShowFullOutput
      || isShowRuleKey
      || isShowTargetHash)) {
    printResults(
        params,
        executor,
        getMatchingNodes(
            params, buildTargetGraphAndTargets(params, executor), descriptionClasses));
    return ExitCode.SUCCESS;
  }

  // shortcut to DOT format, it only works along with rule keys and transitive rule keys
  // because we want to construct action graph
  if (shouldUseDotFormat()) {
    printDotFormat(params, executor);
    return ExitCode.SUCCESS;
  }

  ImmutableList<TargetNodeSpec> targetNodeSpecs = getTargetNodeSpecs(params);

  // plain or json output
  TargetGraphCreationResult targetGraphAndBuildTargetsForShowRules =
      buildTargetGraphAndTargetsForShowRules(
          params, targetNodeSpecs, executor, descriptionClasses);
  boolean useVersioning =
      isShowRuleKey || isShowOutput || isShowOutputs || isShowFullOutput
          ? params.getBuckConfig().getView(BuildBuckConfig.class).getBuildVersions()
          : params.getBuckConfig().getView(BuildBuckConfig.class).getTargetsVersions();
  targetGraphAndBuildTargetsForShowRules =
      useVersioning
          ? toVersionedTargetGraph(params, targetGraphAndBuildTargetsForShowRules)
          : targetGraphAndBuildTargetsForShowRules;
  ImmutableSortedMap<BuildTargetWithOutputs, TargetResult> showRulesResult =
      computeShowRules(
          params,
          targetNodeSpecs,
          executor,
          new Pair<>(
              targetGraphAndBuildTargetsForShowRules.getTargetGraph(),
              targetGraphAndBuildTargetsForShowRules
                  .getTargetGraph()
                  .getAll(targetGraphAndBuildTargetsForShowRules.getBuildTargets())));

  if (shouldUseJsonFormat()) {
    ImmutableSetMultimap.Builder<BuildTarget, OutputLabel> builder =
        ImmutableSetMultimap.builder();
    for (BuildTargetWithOutputs buildTargetWithOutputs : showRulesResult.keySet()) {
      builder.put(
          buildTargetWithOutputs.getBuildTarget(), buildTargetWithOutputs.getOutputLabel());
    }
    ImmutableSetMultimap<BuildTarget, OutputLabel> targetToAllLabels = builder.build();
    Iterable<TargetNode<?>> matchingNodes =
        targetGraphAndBuildTargetsForShowRules
            .getTargetGraph()
            .getAll(targetToAllLabels.keySet());
    printJsonForTargets(
        params,
        executor,
        matchingNodes,
        targetToAllLabels,
        showRulesResult,
        outputAttributes.get());
  } else {
    printShowRules(showRulesResult, params);
  }

  return ExitCode.SUCCESS;
}