Java 类com.google.common.collect.ImmutableMultimap.Builder 实例源码

项目:guava-mock    文件:ImmutableMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableMultimap.Builder<String, Integer> builder =
      new Builder<String, Integer>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry = new AbstractMapEntry<String, Integer>() {
    @Override public String getKey() {
      return holder.string;
    }
    @Override public Integer getValue() {
      return 1;
    }
  };

  builder.put(entry);
  holder.string = "two";
  assertEquals(Arrays.asList(1), builder.build().get("one"));
}
项目:googles-monorepo-demo    文件:ImmutableMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableMultimap.Builder<String, Integer> builder =
      new Builder<String, Integer>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry = new AbstractMapEntry<String, Integer>() {
    @Override public String getKey() {
      return holder.string;
    }
    @Override public Integer getValue() {
      return 1;
    }
  };

  builder.put(entry);
  holder.string = "two";
  assertEquals(Arrays.asList(1), builder.build().get("one"));
}
项目:de.flapdoodle.solid    文件:Blobs.java   
public static ImmutableMultimap<String, Object> pathPropertiesOfAsMultimap(Blob blob, Function<String, Collection<String>> pathPropertyMapping, Path path, PropertyCollectionResolver propertyResolver) {
    ImmutableList<String> pathProperties = path.propertyNamesWithoutPage();

    ImmutableMap<String, ImmutableSet<?>> blopPathPropertyMap = pathProperties.stream()
        .map(p -> Pair.<String, ImmutableSet<?>>of(p, propertyOf(blob, pathPropertyMapping, propertyResolver, p)))
        .filter(pair -> !pair.b().isEmpty())
        .collect(ImmutableMap.toImmutableMap(Pair::a, Pair::b));

    if (blopPathPropertyMap.keySet().size()<pathProperties.size()) {
        return ImmutableMultimap.of();
    }

    Builder<String, Object> multiMapBuilder = ImmutableMultimap.builder();

    blopPathPropertyMap.forEach((key, values) -> {
        multiMapBuilder.putAll(key, values);
    });

    return multiMapBuilder.build();
}
项目:hashsdn-controller    文件:DOMNotificationRouter.java   
@Override
public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener, final Collection<SchemaPath> types) {
    final ListenerRegistration<T> reg = new AbstractListenerRegistration<T>(listener) {
        @Override
        protected void removeRegistration() {
            final ListenerRegistration<T> me = this;

            synchronized (DOMNotificationRouter.this) {
                replaceListeners(ImmutableMultimap.copyOf(Multimaps.filterValues(listeners, input -> input != me)));
            }
        }
    };

    if (!types.isEmpty()) {
        final Builder<SchemaPath, ListenerRegistration<? extends DOMNotificationListener>> b = ImmutableMultimap.builder();
        b.putAll(listeners);

        for (final SchemaPath t : types) {
            b.put(t, reg);
        }

        replaceListeners(b.build());
    }

    return reg;
}
项目:guava-libraries    文件:ImmutableMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableMultimap.Builder<String, Integer> builder =
      new Builder<String, Integer>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry = new AbstractMapEntry<String, Integer>() {
    @Override public String getKey() {
      return holder.string;
    }
    @Override public Integer getValue() {
      return 1;
    }
  };

  builder.put(entry);
  holder.string = "two";
  assertEquals(Arrays.asList(1), builder.build().get("one"));
}
项目:guava-libraries    文件:ImmutableMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableMultimap.Builder<String, Integer> builder =
      new Builder<String, Integer>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry = new AbstractMapEntry<String, Integer>() {
    @Override public String getKey() {
      return holder.string;
    }
    @Override public Integer getValue() {
      return 1;
    }
  };

  builder.put(entry);
  holder.string = "two";
  assertEquals(Arrays.asList(1), builder.build().get("one"));
}
项目:error-prone    文件:WakelockReleasedDangerously.java   
/**
 * Finds all method invocations on the given symbol, and constructs a map of the called method's
 * name, to the {@link MethodInvocationTree} in which it was called.
 */
private ImmutableMultimap<String, MethodInvocationTree> methodCallsForSymbol(
    Symbol sym, ClassTree classTree) {
  Builder<String, MethodInvocationTree> methodMap = ImmutableMultimap.builder();
  // Populate map builder with names of method called : the tree in which it is called.
  classTree.accept(
      new TreeScanner<Void, Void>() {
        @Override
        public Void visitMethodInvocation(MethodInvocationTree callTree, Void unused) {
          if (sym.equals(getSymbol(getReceiver(callTree)))) {
            MethodSymbol methodSymbol = getSymbol(callTree);
            if (methodSymbol != null) {
              methodMap.put(methodSymbol.getSimpleName().toString(), callTree);
            }
          }
          return super.visitMethodInvocation(callTree, unused);
        }
      },
      null);
  return methodMap.build();
}
项目:guava    文件:ImmutableMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableMultimap.Builder<String, Integer> builder = new Builder<>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry =
      new AbstractMapEntry<String, Integer>() {
        @Override
        public String getKey() {
          return holder.string;
        }

        @Override
        public Integer getValue() {
          return 1;
        }
      };

  builder.put(entry);
  holder.string = "two";
  assertEquals(Arrays.asList(1), builder.build().get("one"));
}
项目:guava    文件:ImmutableMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableMultimap.Builder<String, Integer> builder = new Builder<>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry =
      new AbstractMapEntry<String, Integer>() {
        @Override
        public String getKey() {
          return holder.string;
        }

        @Override
        public Integer getValue() {
          return 1;
        }
      };

  builder.put(entry);
  holder.string = "two";
  assertEquals(Arrays.asList(1), builder.build().get("one"));
}
项目:buck    文件:SmartDexingStep.java   
private void buildInternal(ImmutableList.Builder<Step> steps) {
  Preconditions.checkState(newInputsHash != null, "Must call checkIsCached first!");

  createDxStepForDxPseudoRule(
      target,
      androidPlatformTarget,
      steps,
      buildContext,
      filesystem,
      srcs,
      outputPath,
      dxOptions,
      xzCompressionLevel,
      dxMaxHeapSize,
      dexTool);
  steps.add(
      new WriteFileStep(filesystem, newInputsHash, outputHashPath, /* executable */ false));
}
项目:de.flapdoodle.solid    文件:Blobs.java   
public static ImmutableMultimap<ImmutableMap<String, Object>, Blob> orderByKey(ImmutableMultimap<ImmutableMap<String, Object>, Blob> src,
        ImmutableList<String> pathOrdering) {
    ImmutableMultimap.Builder<ImmutableMap<String, Object>, Blob> builder=ImmutableMultimap.builder();

    src.asMap().entrySet()
        .stream()
        .sorted(pathOrderingOf(pathOrdering))
        .forEach(e -> {
            builder.putAll(e.getKey(), e.getValue());
        });

    return builder.build();
}
项目:textokit-core    文件:BratRelation.java   
public BratRelation(BratRelationType type, BratEntity arg1, BratEntity arg2) {
    super(type, ImmutableMultimap.<String, BratEntity>of());
    if (!checkArgVal(arg1) || !checkArgVal(arg2)) {
        throw new IllegalArgumentException(String.format(
                "Relation %s arguments: %s, %s", type, arg1, arg2));
    }
    Builder<String, BratEntity> b = ImmutableMultimap.builder();
    b.put(type.getArg1Name(), arg1);
    b.put(type.getArg2Name(), arg2);
    setRoleAnnotations(b.build());
}
项目:metasfresh    文件:MaterialEventHandlerRegistry.java   
public MaterialEventHandlerRegistry(
        @NonNull final Optional<Collection<MaterialEventHandler>> handlers,
        @NonNull final EventLogUserService eventLogUserService)
{
    this.eventLogUserService = eventLogUserService;

    final Builder<Class, MaterialEventHandler> builder = createEventHandlerMapping(handlers);
    eventType2Handler = builder.build();
}
项目:metasfresh    文件:MaterialEventHandlerRegistry.java   
private Builder<Class, MaterialEventHandler> createEventHandlerMapping(
        @NonNull final Optional<Collection<MaterialEventHandler>> handlers)
{
    final Builder<Class, MaterialEventHandler> builder = ImmutableMultimap.builder();
    for (final MaterialEventHandler handler : handlers.orElse(ImmutableList.of()))
    {
        final Collection<Class<? extends MaterialEventHandler>> handeledEventType = //
                handler.getHandeledEventType();

        handeledEventType.forEach(type -> builder.put(type, handler));
    }
    return builder;
}
项目:bazel    文件:WorkerActionContextConsumer.java   
@Override
public Multimap<Class<? extends ActionContext>, String> getActionContexts() {
  Builder<Class<? extends ActionContext>, String> contexts = ImmutableMultimap.builder();
  contexts.put(SpawnActionContext.class, "standalone");
  contexts.put(SpawnActionContext.class, "worker");
  return contexts.build();
}
项目:HiveRunner    文件:TableDataBuilder.java   
private Map<String, String> createPartitionSpec() {
  ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
  for (HCatFieldSchema partitionColumn : partitionColumns) {
    String name = partitionColumn.getName();
    Object value = get(name);
    checkState(value != null, "Value for partition column %s must not be null.", name);
    builder.put(name, value.toString());
  }
  return builder.build();
}
项目:buck    文件: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. 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 executorService The thread pool to execute the dx command on.
 */
public SmartDexingStep(
    BuildTarget target,
    AndroidPlatformTarget androidPlatformTarget,
    BuildContext buildContext,
    ProjectFilesystem filesystem,
    final Path primaryOutputPath,
    final Supplier<Set<Path>> primaryInputsToDex,
    Optional<Path> secondaryOutputDir,
    final Optional<Supplier<Multimap<Path, Path>>> secondaryInputsToDex,
    DexInputHashesProvider dexInputHashesProvider,
    Path successDir,
    EnumSet<Option> dxOptions,
    ListeningExecutorService executorService,
    Optional<Integer> xzCompressionLevel,
    Optional<String> dxMaxHeapSize,
    String dexTool) {
  this.target = target;
  this.androidPlatformTarget = androidPlatformTarget;
  this.buildContext = buildContext;
  this.filesystem = filesystem;
  this.outputToInputsSupplier =
      MoreSuppliers.memoize(
          () -> {
            final Builder<Path, Path> map = ImmutableMultimap.builder();
            map.putAll(primaryOutputPath, primaryInputsToDex.get());
            if (secondaryInputsToDex.isPresent()) {
              map.putAll(secondaryInputsToDex.get().get());
            }
            return map.build();
          });
  this.secondaryOutputDir = secondaryOutputDir;
  this.dexInputHashesProvider = dexInputHashesProvider;
  this.successDir = successDir;
  this.dxOptions = dxOptions;
  this.executorService = executorService;
  this.xzCompressionLevel = xzCompressionLevel;
  this.dxMaxHeapSize = dxMaxHeapSize;
  this.dexTool = dexTool;
}
项目:buck    文件:SmartDexingStep.java   
/**
 * Once the {@code .class} files have been split into separate zip files, each must be converted
 * to a {@code .dex} file.
 */
private ImmutableList<ImmutableList<Step>> generateDxCommands(
    ProjectFilesystem filesystem, Multimap<Path, Path> outputToInputs) {
  ImmutableList.Builder<DxPseudoRule> pseudoRules = ImmutableList.builder();

  ImmutableMap<Path, Sha1HashCode> dexInputHashes = dexInputHashesProvider.getDexInputHashes();

  for (Path outputFile : outputToInputs.keySet()) {
    pseudoRules.add(
        new DxPseudoRule(
            target,
            androidPlatformTarget,
            buildContext,
            filesystem,
            dexInputHashes,
            ImmutableSet.copyOf(outputToInputs.get(outputFile)),
            outputFile,
            successDir.resolve(outputFile.getFileName()),
            dxOptions,
            xzCompressionLevel,
            dxMaxHeapSize,
            dexTool));
  }

  ImmutableList.Builder<ImmutableList<Step>> stepGroups = new ImmutableList.Builder<>();
  for (DxPseudoRule pseudoRule : pseudoRules.build()) {
    if (!pseudoRule.checkIsCached()) {
      ImmutableList.Builder<Step> steps = ImmutableList.builder();
      pseudoRule.buildInternal(steps);
      stepGroups.add(steps.build());
    }
  }

  return stepGroups.build();
}
项目:guava-mock    文件:ImmutableMultimapTest.java   
public void testBuilder_withImmutableEntry() {
  ImmutableMultimap<String, Integer> multimap = new Builder<String, Integer>()
      .put(Maps.immutableEntry("one", 1))
      .build();
  assertEquals(Arrays.asList(1), multimap.get("one"));
}
项目:Equella    文件:InstitutionServiceImpl.java   
private synchronized void setAllInstitutions(Map<Long, InstitutionStatus> map)
{
    allInstitutions = ImmutableMap.copyOf(map);

    Multimap<Long, Institution> newlyAvailable = ArrayListMultimap.create();
    Multimap<Long, Institution> newlyUnavailable = ArrayListMultimap.create(availableInstitutions);
    Builder<Long, Institution> availableBuilder = ImmutableMultimap.builder();
    ImmutableMap.Builder<Long, Long> schemaBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<Long, Institution> instBuilder = ImmutableMap.builder();
    for( Entry<Long, InstitutionStatus> entry : allInstitutions.entrySet() )
    {
        InstitutionStatus instStatus = entry.getValue();
        Institution institution = instStatus.getInstitution();
        Long schemaId = instStatus.getSchemaId();
        if( instStatus.isValid() && institution.isEnabled() )
        {
            availableBuilder.put(schemaId, institution);
            if( !newlyUnavailable.remove(schemaId, institution) )
            {
                newlyAvailable.put(schemaId, institution);
            }
        }
        long uniqueId = institution.getUniqueId();
        schemaBuilder.put(uniqueId, schemaId);
        instBuilder.put(uniqueId, institution);
    }

    availableInstitutions = availableBuilder.build();
    schemaMap = schemaBuilder.build();
    instMap = instBuilder.build();

    if( !newlyAvailable.isEmpty() )
    {
        eventService.publishApplicationEvent(new InstitutionEvent(InstitutionEventType.AVAILABLE, newlyAvailable));
    }

    if( !newlyUnavailable.isEmpty() )
    {
        eventService
                .publishApplicationEvent(new InstitutionEvent(InstitutionEventType.UNAVAILABLE, newlyUnavailable));
    }
}
项目:googles-monorepo-demo    文件:ImmutableMultimapTest.java   
public void testBuilder_withImmutableEntry() {
  ImmutableMultimap<String, Integer> multimap = new Builder<String, Integer>()
      .put(Maps.immutableEntry("one", 1))
      .build();
  assertEquals(Arrays.asList(1), multimap.get("one"));
}
项目:guava-libraries    文件:ImmutableMultimapTest.java   
public void testBuilder_withImmutableEntry() {
  ImmutableMultimap<String, Integer> multimap = new Builder<String, Integer>()
      .put(Maps.immutableEntry("one", 1))
      .build();
  assertEquals(Arrays.asList(1), multimap.get("one"));
}
项目:guava-libraries    文件:ImmutableMultimapTest.java   
public void testBuilder_withImmutableEntry() {
  ImmutableMultimap<String, Integer> multimap = new Builder<String, Integer>()
      .put(Maps.immutableEntry("one", 1))
      .build();
  assertEquals(Arrays.asList(1), multimap.get("one"));
}
项目:ocamljava-maven-plugin    文件:PackageComparator.java   
public PackageComparator(final SortedSetMultimap<String, ModuleDescriptor> resolvedModuleDependencies) {
    this.resolvedModuleDependencies = Preconditions.checkNotNull(resolvedModuleDependencies);

    final Set<Entry<String,ModuleDescriptor>> entries = resolvedModuleDependencies.entries();

    final Builder<String, ModuleDescriptor> builder = ImmutableMultimap.builder();
    for (final Entry<String, ModuleDescriptor> entry : entries) {
        final String javaPackageName = entry.getValue().getJavaPackageName();

        builder.put(javaPackageName, entry.getValue());

    }

    this.modulesByPackageName = builder.build();


}
项目:guava    文件:ImmutableMultimapTest.java   
public void testBuilder_withImmutableEntry() {
  ImmutableMultimap<String, Integer> multimap =
      new Builder<String, Integer>().put(Maps.immutableEntry("one", 1)).build();
  assertEquals(Arrays.asList(1), multimap.get("one"));
}
项目:guava    文件:ImmutableMultimapTest.java   
public void testBuilder_withImmutableEntry() {
  ImmutableMultimap<String, Integer> multimap =
      new Builder<String, Integer>().put(Maps.immutableEntry("one", 1)).build();
  assertEquals(Arrays.asList(1), multimap.get("one"));
}
项目:buck    文件:SmartDexingStep.java   
@Override
public StepExecutionResult execute(ExecutionContext context)
    throws IOException, InterruptedException {
  try {
    Multimap<Path, Path> outputToInputs = outputToInputsSupplier.get();
    runDxCommands(context, outputToInputs);
    if (secondaryOutputDir.isPresent()) {
      removeExtraneousSecondaryArtifacts(
          secondaryOutputDir.get(), outputToInputs.keySet(), filesystem);

      // Concatenate if solid compression is specified.
      // create a mapping of the xzs file target and the dex.jar files that go into it
      ImmutableMultimap.Builder<Path, Path> secondaryDexJarsMultimapBuilder =
          ImmutableMultimap.builder();
      for (Path p : outputToInputs.keySet()) {
        if (DexStore.XZS.matchesPath(p)) {
          String[] matches = p.getFileName().toString().split("-");
          Path output = p.getParent().resolve(matches[0].concat(SECONDARY_SOLID_DEX_EXTENSION));
          secondaryDexJarsMultimapBuilder.put(output, p);
        }
      }
      ImmutableMultimap<Path, Path> secondaryDexJarsMultimap =
          secondaryDexJarsMultimapBuilder.build();
      if (!secondaryDexJarsMultimap.isEmpty()) {
        for (Map.Entry<Path, Collection<Path>> entry :
            secondaryDexJarsMultimap.asMap().entrySet()) {
          Path store = entry.getKey();
          Collection<Path> secondaryDexJars = entry.getValue();
          // Construct the output path for our solid blob and its compressed form.
          Path secondaryBlobOutput = store.getParent().resolve("uncompressed.dex.blob");
          Path secondaryCompressedBlobOutput = store;
          // Concatenate the jars into a blob and compress it.
          StepRunner stepRunner = new DefaultStepRunner();
          Step concatStep =
              new ConcatStep(
                  filesystem, ImmutableList.copyOf(secondaryDexJars), secondaryBlobOutput);
          Step xzStep;

          if (xzCompressionLevel.isPresent()) {
            xzStep =
                new XzStep(
                    filesystem,
                    secondaryBlobOutput,
                    secondaryCompressedBlobOutput,
                    xzCompressionLevel.get().intValue());
          } else {
            xzStep = new XzStep(filesystem, secondaryBlobOutput, secondaryCompressedBlobOutput);
          }
          stepRunner.runStepForBuildTarget(context, concatStep, Optional.empty());
          stepRunner.runStepForBuildTarget(context, xzStep, Optional.empty());
        }
      }
    }
  } catch (StepFailedException e) {
    context.logError(e, "There was an error in smart dexing step.");
    return StepExecutionResults.ERROR;
  }

  return StepExecutionResults.SUCCESS;
}