com.google.common.collect.ListMultimap Java Examples

The following examples show how to use com.google.common.collect.ListMultimap. 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: TaskDetailPrinter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private ListMultimap<Class, Task> groupTasksByType(List<Task> tasks) {
    final Set<Class> taskTypes = new TreeSet<Class>(new Comparator<Class>() {
        public int compare(Class o1, Class o2) {
            return o1.getSimpleName().compareTo(o2.getSimpleName());
        }
    });
    taskTypes.addAll(collect(tasks, new Transformer<Class, Task>() {
        public Class transform(Task original) {
            return getDeclaredTaskType(original);
        }
    }));

    ListMultimap<Class, Task> tasksGroupedByType = ArrayListMultimap.create();
    for (final Class taskType : taskTypes) {
        tasksGroupedByType.putAll(taskType, filter(tasks, new Spec<Task>() {
            public boolean isSatisfiedBy(Task element) {
                return getDeclaredTaskType(element).equals(taskType);
            }
        }));
    }
    return tasksGroupedByType;
}
 
Example #2
Source File: SwapTradeCsvPlugin.java    From Strata with Apache License 2.0 6 votes vote down vote up
private static SwapTrade parseVariableNotional(SwapTrade trade, List<CsvRow> variableRows) {
  ImmutableList<SwapLeg> legs = trade.getProduct().getLegs();
  ListMultimap<Integer, ValueStep> steps =
      extractSteps(variableRows, legs, NOTIONAL_FIELD, str -> LoaderUtils.parseDouble(str));
  if (steps.isEmpty()) {
    return trade;
  }
  // adjust the trade, inserting the variable element
  ImmutableList.Builder<SwapLeg> legBuilder = ImmutableList.builder();
  for (int i = 0; i < legs.size(); i++) {
    SwapLeg swapLeg = legs.get(i);
    List<ValueStep> legSteps = steps.get(i);
    if (!legSteps.isEmpty() && swapLeg instanceof RateCalculationSwapLeg) {
      RateCalculationSwapLeg leg = (RateCalculationSwapLeg) swapLeg;
      NotionalSchedule notionalSchedule = leg.getNotionalSchedule().toBuilder()
          .amount(ValueSchedule.of(leg.getNotionalSchedule().getAmount().getInitialValue(), legSteps))
          .build();
      swapLeg = leg.toBuilder().notionalSchedule(notionalSchedule).build();
    }
    legBuilder.add(swapLeg);
  }
  return replaceLegs(trade, legBuilder.build());
}
 
Example #3
Source File: NewQueriesTest.java    From trainbenchmark with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void routeReachabilityTest() throws Exception {
	// Arrange
	final String workload = "NewQueriesTest";
	final String modelFilename = "railway-repair-" + largeSize;
	final List<RailwayOperation> operations = ImmutableList.of(//
		RailwayOperation.ROUTEREACHABILITY //
	);
	final BenchmarkConfigBase bcb = bcbbTransformation.setModelFilename(modelFilename).setOperations(operations)
		.setWorkload(workload).createConfigBase();

	// Act
	final BenchmarkResult result = runTest(bcb);

	// Assert
	final ListMultimap<RailwayQuery, Integer> allMatches = result.getLastRunResult().getMatches();
	collector.checkThat(allMatches.get(RailwayQuery.ROUTEREACHABILITY).get(0), Matchers.equalTo(26));
}
 
Example #4
Source File: NettyServerStreamTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void writeHeadersShouldSendHeaders() throws Exception {
  Metadata headers = new Metadata();
  ListMultimap<CharSequence, CharSequence> expectedHeaders =
      ImmutableListMultimap.copyOf(Utils.convertServerHeaders(headers));

  stream().writeHeaders(headers);

  ArgumentCaptor<SendResponseHeadersCommand> sendHeadersCap =
      ArgumentCaptor.forClass(SendResponseHeadersCommand.class);
  verify(writeQueue).enqueue(sendHeadersCap.capture(), eq(true));
  SendResponseHeadersCommand sendHeaders = sendHeadersCap.getValue();
  assertThat(sendHeaders.stream()).isSameAs(stream.transportState());
  assertThat(ImmutableListMultimap.copyOf(sendHeaders.headers()))
      .containsExactlyEntriesIn(expectedHeaders);
  assertThat(sendHeaders.endOfStream()).isFalse();
}
 
Example #5
Source File: DiploidRatioSupplier.java    From hmftools with GNU General Public License v3.0 6 votes vote down vote up
DiploidRatioSupplier(@NotNull final ListMultimap<Chromosome, ReadRatio> normalRatios) {
    final ReferenceRatioStatistics stats = ReferenceRatioStatisticsFactory.fromReferenceRatio(normalRatios);

    for (Chromosome chromosome : normalRatios.keySet()) {
        final List<ReadRatio> ratios = normalRatios.get(chromosome);
        final List<ReadRatio> adjustedRatios;
        if (chromosome.equals(HumanChromosome._Y)) {
            adjustedRatios = ratios;
        } else {
            double expectedRatio = chromosome.equals(HumanChromosome._X) && !stats.containsTwoXChromosomes() ? 0.5 : 1;
            adjustedRatios = new DiploidRatioNormalization(expectedRatio,
                    ROLLING_MEDIAN_MAX_DISTANCE,
                    ROLLING_MEDIAN_MIN_COVERAGE,
                    ratios).get();
        }
        result.replaceValues(chromosome, adjustedRatios);
    }
}
 
Example #6
Source File: FpmlDocument.java    From Strata with Apache License 2.0 6 votes vote down vote up
private ListMultimap<String, StandardId> parseAllTradeIds(XmlElement tradeHeaderEl) {
  // look through each partyTradeIdentifier
  ListMultimap<String, StandardId> allIds = ArrayListMultimap.create();
  List<XmlElement> partyTradeIdentifierEls = tradeHeaderEl.getChildren("partyTradeIdentifier");
  for (XmlElement partyTradeIdentifierEl : partyTradeIdentifierEls) {
    Optional<XmlElement> partyRefOptEl = partyTradeIdentifierEl.findChild("partyReference");
    if (partyRefOptEl.isPresent() && partyRefOptEl.get().findAttribute(HREF).isPresent()) {
      String partyHref = partyRefOptEl.get().findAttribute(HREF).get();
      // try to find a tradeId, either in versionedTradeId or as a direct child
      Optional<XmlElement> vtradeIdOptEl = partyTradeIdentifierEl.findChild("versionedTradeId");
      Optional<XmlElement> tradeIdOptEl = vtradeIdOptEl
          .map(vt -> Optional.of(vt.getChild("tradeId")))
          .orElse(partyTradeIdentifierEl.findChild("tradeId"));
      if (tradeIdOptEl.isPresent() && tradeIdOptEl.get().findAttribute("tradeIdScheme").isPresent()) {
        XmlElement tradeIdEl = tradeIdOptEl.get();
        String scheme = tradeIdEl.getAttribute("tradeIdScheme");
        // ignore if there is an empty scheme or value
        if (!scheme.isEmpty() && !tradeIdEl.getContent().isEmpty()) {
          allIds.put(partyHref, StandardId.of(StandardId.encodeScheme(scheme), tradeIdEl.getContent()));
        }
      }
    }
  }
  return allIds;
}
 
Example #7
Source File: AssignmentCreator.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Does the work of creating the mappings for this AssignmentCreator
 * @return the minor fragment id to work units mapping
 */
private ListMultimap<Integer, T> getMappings() {
  Stopwatch watch = Stopwatch.createStarted();
  maxWork = (int) Math.ceil(units.size() / ((float) incomingEndpoints.size()));
  LinkedList<WorkEndpointListPair<T>> workList = getWorkList();
  LinkedList<WorkEndpointListPair<T>> unassignedWorkList;
  Map<NodeEndpoint,FragIteratorWrapper> endpointIterators = getEndpointIterators();

  unassignedWorkList = assign(workList, endpointIterators, true);

  assignLeftovers(unassignedWorkList, endpointIterators, true);
  assignLeftovers(unassignedWorkList, endpointIterators, false);

  if (!unassignedWorkList.isEmpty()) {
    throw new IllegalStateException("There are still unassigned work units");
  }

  logger.debug("Took {} ms to assign {} work units to {} fragments", watch.elapsed(TimeUnit.MILLISECONDS), units.size(), incomingEndpoints.size());
  return mappings;
}
 
Example #8
Source File: PPOrderLinesLoader.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 6 votes vote down vote up
private List<PPOrderLineRow> createRowsForBomLines(
		@NonNull final I_PP_Order ppOrder,
		@NonNull final ListMultimap<Integer, I_PP_Order_Qty> ppOrderQtysByBOMLineId)
{
	final Comparator<PPOrderLineRow> ppOrderBomLineRowSorter = //
			Comparator.<PPOrderLineRow> comparingInt(row -> row.isReceipt() ? 0 : 1) // receipt lines first
					.thenComparing(row -> row.getOrderBOMLineId());  // BOM lines order

	final Function<? super I_PP_Order_BOMLine, ? extends PPOrderLineRow> ppOrderBomLineRowCreator = //
			ppOrderBOMLine -> createRowForBOMLine(
					ppOrderBOMLine,
					isReadOnly(ppOrder),
					ppOrderQtysByBOMLineId.get(ppOrderBOMLine.getPP_Order_BOMLine_ID()));

	final PPOrderId ppOrderId = PPOrderId.ofRepoId(ppOrder.getPP_Order_ID());
	final ImmutableList<PPOrderLineRow> bomLineRows = ppOrderBOMDAO.retrieveOrderBOMLines(ppOrderId, I_PP_Order_BOMLine.class)
			.stream()
			.map(ppOrderBomLineRowCreator)
			.sorted(ppOrderBomLineRowSorter)
			.collect(ImmutableList.toImmutableList());
	return bomLineRows;
}
 
Example #9
Source File: BlazeOptionHandlerTest.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Test
public void testStructureRcOptionsAndConfigs_importedRcs() throws Exception {
  ListMultimap<String, RcChunkOfArgs> structuredRc =
      BlazeOptionHandler.structureRcOptionsAndConfigs(
          eventHandler,
          Arrays.asList("rc1", "rc2"),
          Arrays.asList(
              new ClientOptions.OptionOverride(0, "c0", "a"),
              new ClientOptions.OptionOverride(0, "c0:config", "b"),
              new ClientOptions.OptionOverride(1, "common", "c"),
              new ClientOptions.OptionOverride(1, "c0", "d"),
              new ClientOptions.OptionOverride(1, "c0", "e"),
              new ClientOptions.OptionOverride(1, "c1:other", "f"),
              new ClientOptions.OptionOverride(1, "c1:other", "g"),
              new ClientOptions.OptionOverride(0, "c0", "h")),
          ImmutableSet.of("c0", "c1"));
  assertThat(structuredRc).isEqualTo(structuredArgsFromImportedRcsWithOnlyResidue());
  assertThat(eventHandler.isEmpty()).isTrue();
}
 
Example #10
Source File: SensitivityCsvLoaderTest.java    From Strata with Apache License 2.0 6 votes vote down vote up
@Test
public void test_parse_list() {
  CharSource source =
      ResourceLocator.ofClasspath("com/opengamma/strata/loader/csv/sensitivity-list.csv").getCharSource();

  assertThat(LOADER.isKnownFormat(source)).isTrue();
  ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER.parse(ImmutableList.of(source));
  assertThat(test.getFailures().size()).as(test.getFailures().toString()).isEqualTo(0);
  assertThat(test.getValue().size()).isEqualTo(1);
  List<CurveSensitivities> list = test.getValue().get("");
  assertThat(list).hasSize(1);

  CurveSensitivities csens0 = list.get(0);
  assertThat(csens0.getTypedSensitivities()).hasSize(3);
  String tenors = "1D, 1W, 2W, 1M, 3M, 6M, 12M, 2Y, 5Y, 10Y";
  assertSens(csens0, ZERO_RATE_DELTA, "GBP", GBP, tenors, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
  assertSens(csens0, ZERO_RATE_DELTA, "GBP-LIBOR", GBP, tenors, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
  assertSens(csens0, ZERO_RATE_GAMMA, "GBP", GBP, tenors, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1);
  assertSens(csens0, ZERO_RATE_GAMMA, "GBP-LIBOR", GBP, tenors, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1);
  assertSens(csens0, OTHER, "GBP", GBP, tenors, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0);
  assertSens(csens0, OTHER, "GBP-LIBOR", GBP, tenors, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0);

  assertThat(LOADER.parseAndMerge(ImmutableList.of(source)).getValue()).isEqualTo(csens0);
}
 
Example #11
Source File: ModuleValidator.java    From dagger2-sample with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationReport<TypeElement> validate(final TypeElement subject) {
  final ValidationReport.Builder<TypeElement> builder = ValidationReport.Builder.about(subject);

  List<ExecutableElement> moduleMethods = ElementFilter.methodsIn(subject.getEnclosedElements());
  ListMultimap<String, ExecutableElement> allMethodsByName = ArrayListMultimap.create();
  ListMultimap<String, ExecutableElement> bindingMethodsByName = ArrayListMultimap.create();
  for (ExecutableElement moduleMethod : moduleMethods) {
    if (isAnnotationPresent(moduleMethod, methodClass)) {
      bindingMethodsByName.put(moduleMethod.getSimpleName().toString(), moduleMethod);
    }
    allMethodsByName.put(moduleMethod.getSimpleName().toString(), moduleMethod);
  }
    
  validateModuleVisibility(subject, builder);
  validateMethodsWithSameName(builder, bindingMethodsByName);
  validateProvidesOverrides(subject, builder, allMethodsByName, bindingMethodsByName);
  validateModifiers(subject, builder);    
  validateReferencedModules(subject, builder);
  
  // TODO(gak): port the dagger 1 module validation?
  return builder.build();
}
 
Example #12
Source File: ConfigExpander.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * If --enable_platform_specific_config is true and the corresponding config definition exists, we
 * should enable the platform specific config.
 */
private static boolean shouldEnablePlatformSpecificConfig(
    OptionValueDescription enablePlatformSpecificConfigDescription,
    ListMultimap<String, RcChunkOfArgs> commandToRcArgs,
    List<String> commandsToParse) {
  if (enablePlatformSpecificConfigDescription == null
      || !(boolean) enablePlatformSpecificConfigDescription.getValue()) {
    return false;
  }

  for (String commandName : commandsToParse) {
    String defaultConfigDef = commandName + ":" + getPlatformName();
    if (commandToRcArgs.containsKey(defaultConfigDef)) {
      return true;
    }
  }
  return false;
}
 
Example #13
Source File: TrainBenchmarkTest.java    From trainbenchmark with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void posLengthInjectTest() throws Exception {
	// Arrange
	final String modelFilename = "railway-inject-" + largeSize;
	final String workload = "PosLengthInjectTest";
	final List<RailwayOperation> operations = ImmutableList.of(//
			RailwayOperation.POSLENGTH, //
			RailwayOperation.POSLENGTH_INJECT //
	);
	final BenchmarkConfigBase bcb = bcbbTransformation.setModelFilename(modelFilename).setOperations(operations)
			.setWorkload(workload).createConfigBase();

	// Act
	final BenchmarkResult result = runTest(bcb);

	// Assert
	final ListMultimap<RailwayQuery, Integer> allMatches = result.getLastRunResult().getMatches();
	collector.checkThat(allMatches.get(RailwayQuery.POSLENGTH).get(0), Matchers.equalTo(32));
	collector.checkThat(allMatches.get(RailwayQuery.POSLENGTH).get(1), Matchers.equalTo(41));
}
 
Example #14
Source File: PickingHURowsRepository.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 6 votes vote down vote up
public ListMultimap<PickingSlotId, PickedHUEditorRow> //
		retrieveAllPickedHUsIndexedByPickingSlotId(@NonNull final List<I_M_PickingSlot> pickingSlots)
{
	final SetMultimap<PickingSlotId, HuId> //
	huIdsByPickingSlotId = Services.get(IHUPickingSlotDAO.class).retrieveAllHUIdsIndexedByPickingSlotId(pickingSlots);

	final HUEditorViewRepository huEditorRepo = getHUEditorViewRepository();
	huEditorRepo.warmUp(ImmutableSet.copyOf(huIdsByPickingSlotId.values()));

	return huIdsByPickingSlotId
			.entries()
			.stream()
			.map(pickingSlotAndHU -> {
				final PickingSlotId pickingSlotId = pickingSlotAndHU.getKey();
				final HuId huId = pickingSlotAndHU.getValue();

				final HUEditorRow huEditorRow = huEditorRepo.retrieveForHUId(huId);
				final boolean pickingCandidateProcessed = true;
				final PickedHUEditorRow row = new PickedHUEditorRow(huEditorRow, pickingCandidateProcessed);

				return GuavaCollectors.entry(pickingSlotId, row);
			})
			.collect(GuavaCollectors.toImmutableListMultimap());
}
 
Example #15
Source File: DependencyTreeFormatter.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
private static void formatDependencyPathTree(
    StringBuilder stringBuilder,
    ListMultimap<DependencyPath, DependencyPath> tree,
    DependencyPath currentNode,
    int depth) {
  Artifact leaf = currentNode.getLeaf();
  if (leaf != null) {
    // Nodes at top have one or more depth
    stringBuilder.append(Strings.repeat("  ", depth));
    stringBuilder.append(leaf);
    stringBuilder.append("\n");
    depth++;
  }
  for (DependencyPath childPath : tree.get(currentNode)) {
    if (!currentNode.equals(childPath)) { // root node's parent is the root itself
      formatDependencyPathTree(stringBuilder, tree, childPath, depth);
    }
  }
}
 
Example #16
Source File: DataMerger.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the post blob load state to WRITTEN.
 *
 * After a load from the blob file, all items have their state set to nothing.
 * If the load mode is set to incrementalState then we want the items that are in the current
 * merge result to have their state be WRITTEN.
 *
 * This will allow further updates with {@link #mergeData(MergeConsumer, boolean)} to ignore the
 * state at load time and only apply the new changes.
 *
 * @see #loadFromBlob(File, boolean)
 * @see DataItem#isWritten()
 */
private void setPostBlobLoadStateToWritten() {
    ListMultimap<String, I> itemMap = ArrayListMultimap.create();

    // put all the sets into list per keys. The order is important as the lower sets are
    // overridden by the higher sets.
    for (S dataSet : mDataSets) {
        ListMultimap<String, I> map = dataSet.getDataMap();
        for (Map.Entry<String, Collection<I>> entry : map.asMap().entrySet()) {
            itemMap.putAll(entry.getKey(), entry.getValue());
        }
    }

    // the items that represent the current state is the last item in the list for each key.
    for (String key : itemMap.keySet()) {
        List<I> itemList = itemMap.get(key);
        itemList.get(itemList.size() - 1).resetStatusToWritten();
    }
}
 
Example #17
Source File: AbstractResourceRepository.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@Nullable
public ResourceValue getConfiguredValue(
        @NonNull ResourceType type,
        @NonNull String name,
        @NonNull FolderConfiguration referenceConfig) {
    // get the resource item for the given type
    ListMultimap<String, ResourceItem> items = getMap(type, false);
    if (items == null) {
        return null;
    }

    List<ResourceItem> keyItems = items.get(name);
    if (keyItems == null) {
        return null;
    }

    // look for the best match for the given configuration
    // the match has to be of type ResourceFile since that's what the input list contains
    ResourceItem match = (ResourceItem) referenceConfig.findMatchingConfigurable(keyItems);
    return match != null ? match.getResourceValue(mFramework) : null;
}
 
Example #18
Source File: PickingSlotViewRepository.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 5 votes vote down vote up
private PickingSlotRow createPickingSlotRow(
		@NonNull final I_M_PickingSlot pickingSlot,
		@NonNull final ListMultimap<PickingSlotId, PickedHUEditorRow> huEditorRowsByPickingSlotId)
{
	final List<PickingSlotRow> pickedHuRows = retrieveHuRowsToIncludeInPickingSlotRow(pickingSlot, huEditorRowsByPickingSlotId);
	return createPickingSlotRowWithIncludedRows(pickingSlot, pickedHuRows);
}
 
Example #19
Source File: AMLConverter.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public static ListMultimap<AMLBlockType, AMLTestCase> convert(AMLMatrix matrix, AMLSettings settings, IActionManager actionManager, AlertCollector alertCollector) throws AMLException {
    AMLMatrixWrapper wrapper = new AMLMatrixWrapper(matrix);
    AMLConverterVisitor visitor = new AMLConverterVisitor(settings, actionManager, wrapper, alertCollector);

    for(AMLBlock block : matrix.getBlocks()) {
        block.accept(visitor);
    }

    return visitor.getBlocks();
}
 
Example #20
Source File: ExtractJsonPathsBuilder.java    From kite with Apache License 2.0 5 votes vote down vote up
public ExtractJsonPaths(CommandBuilder builder, Config config, Command parent, Command child, MorphlineContext context) {
  super(builder, config, parent, child, context);
  ListMultimap<String, String> stepMultiMap = ArrayListMultimap.create();
  this.flatten = getConfigs().getBoolean(config, "flatten", true);
  Config paths = getConfigs().getConfig(config, "paths");
  for (Map.Entry<String, Object> entry : new Configs().getEntrySet(paths)) {
    String fieldName = entry.getKey();        
    String path = entry.getValue().toString().trim();
    if (path.contains("//")) {
      throw new MorphlineCompilationException("No support for descendant axis available yet", config);
    }
    if (path.startsWith("/")) {
      path = path.substring(1);
    }
    if (path.endsWith("/")) {
      path = path.substring(0, path.length() - 1);
    }
    path = path.trim();
    for (String step : path.split("/")) {
      step = step.trim();
      if (step.length() > ARRAY_TOKEN.length() && step.endsWith(ARRAY_TOKEN)) {
        step = step.substring(0,  step.length() - ARRAY_TOKEN.length());
        stepMultiMap.put(fieldName, normalize(step));
        stepMultiMap.put(fieldName, ARRAY_TOKEN);
      } else {
        stepMultiMap.put(fieldName, normalize(step));
      }
    }
  }
  this.stepMap = stepMultiMap.asMap();
  LOG.debug("stepMap: {}", stepMap);
  validateArguments();
}
 
Example #21
Source File: SingularityDeployStatisticsBuilder.java    From Singularity with Apache License 2.0 5 votes vote down vote up
@Deprecated
public SingularityDeployStatisticsBuilder setInstanceSequentialFailureTimestamps(
  ListMultimap<Integer, Long> instanceSequentialFailureTimestamps
) {
  this.instanceSequentialFailureTimestamps = instanceSequentialFailureTimestamps;
  return this;
}
 
Example #22
Source File: AstyanaxEventWriterDAO.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Override
public void delete(String channel, Collection<EventId> eventIds) {
    checkNotNull(channel, "channel");
    checkNotNull(eventIds, "eventIds");

    ListMultimap<ByteBuffer, Integer> eventsBySlab = ArrayListMultimap.create();
    for (EventId eventId : eventIds) {
        AstyanaxEventId eventIdImpl = (AstyanaxEventId) eventId;
        checkArgument(channel.equals(eventIdImpl.getChannel()));
        eventsBySlab.put(eventIdImpl.getSlabId(), eventIdImpl.getEventIdx());
    }

    // We might be able to use weak consistency since we're allowed to forget deletes and repeat events.  But we'd
    // need to measure it in production to see how frequently weak consistency would cause events to repeat.
    BatchUpdate update = new BatchUpdate(_keyspace, ConsistencyLevel.CL_LOCAL_QUORUM,
            Constants.MUTATION_MAX_ROWS, Constants.MUTATION_MAX_COLUMNS);

    for (Map.Entry<ByteBuffer, Collection<Integer>> entry : eventsBySlab.asMap().entrySet()) {
        ByteBuffer slabId = entry.getKey();
        Collection<Integer> eventIdxs = entry.getValue();

        BatchUpdate.Row<ByteBuffer, Integer> row = update.updateRow(ColumnFamilies.SLAB, slabId);
        for (Integer eventIdx : eventIdxs) {
            row.deleteColumn(eventIdx);
        }
    }

    update.finish();
}
 
Example #23
Source File: TraceAttributeNameDao.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, List<String>> processResultSet(ResultSet resultSet) throws Exception {
    ListMultimap<String, String> multimap = ArrayListMultimap.create();
    while (resultSet.next()) {
        multimap.put(resultSet.getString(1), resultSet.getString(2));
    }
    return Multimaps.asMap(multimap);
}
 
Example #24
Source File: AbstractResourceRepository.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the sorted list of languages used in the resources.
 */
@NonNull
public SortedSet<LocaleQualifier> getLocales() {
    SortedSet<LocaleQualifier> set = new TreeSet<LocaleQualifier>();

    // As an optimization we could just look for values since that's typically where
    // the languages are defined -- not on layouts, menus, etc -- especially if there
    // are no translations for it
    Set<String> qualifiers = Sets.newHashSet();

    synchronized (ITEM_MAP_LOCK) {
        for (ListMultimap<String, ResourceItem> map : getMap().values()) {
            for (ResourceItem item : map.values()) {
                qualifiers.add(item.getQualifiers());
            }
        }
    }

    for (String s : qualifiers) {
        FolderConfiguration configuration = FolderConfiguration.getConfigForQualifierString(s);
        if (configuration != null) {
            LocaleQualifier locale = configuration.getLocaleQualifier();
            if (locale != null) {
                set.add(locale);
            }
        }
    }

    return set;
}
 
Example #25
Source File: RootInputInitializerManager.java    From tez with Apache License 2.0 5 votes vote down vote up
public void handleInitializerEvents(List<TezEvent> events) {
  ListMultimap<InitializerWrapper, TezEvent> eventMap = LinkedListMultimap.create();

  for (TezEvent tezEvent : events) {
    Preconditions.checkState(tezEvent.getEvent() instanceof InputInitializerEvent);
    InputInitializerEvent event = (InputInitializerEvent)tezEvent.getEvent();
    Preconditions.checkState(vertex.getName().equals(event.getTargetVertexName()),
        "Received event for incorrect vertex");
    Objects.requireNonNull(event.getTargetInputName(), "target input name must be set");
    InitializerWrapper initializer = initializerMap.get(event.getTargetInputName());
    Preconditions.checkState(initializer != null,
        "Received event for unknown input : " + event.getTargetInputName());
    eventMap.put(initializer, tezEvent);
  }

  // This is a restriction based on current flow - i.e. events generated only by initialize().
  // TODO Rework the flow as per the first comment on TEZ-1076
  if (isStopped) {
    LOG.warn("InitializerManager already stopped for " + vertex.getLogIdentifier() +
        " Dropping " + events.size() + " events");
  }

  for (Map.Entry<InitializerWrapper, Collection<TezEvent>> entry : eventMap.asMap().entrySet()) {
    InitializerWrapper initializerWrapper = entry.getKey();
    if (initializerWrapper.isComplete()) {
      LOG.warn(entry.getValue().size() +
          " events targeted at vertex " + vertex.getLogIdentifier() +
          ", initializerWrapper for Input: " +
          initializerWrapper.getInput().getName() +
          " will be dropped, since Input has already been initialized.");
    } else {
      initializerWrapper.handleInputInitializerEvents(entry.getValue());
    }

  }
}
 
Example #26
Source File: AmberApplication.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
private ListMultimap<Chromosome, TumorBAF> tumorBAF(@NotNull final SamReaderFactory readerFactory,
        @NotNull final ListMultimap<Chromosome, BaseDepth> normalHetSites) throws ExecutionException, InterruptedException {
    final int partitionSize = Math.max(config.minPartition(), normalHetSites.values().size() / config.threadCount());

    LOGGER.info("Processing {} heterozygous sites in tumor bam {}", normalHetSites.values().size(), config.tumorBamPath());
    final AmberTaskCompletion completion = new AmberTaskCompletion();

    final List<Future<TumorBAFEvidence>> futures = Lists.newArrayList();
    for (final Chromosome chromosome : normalHetSites.keySet()) {
        for (final List<BaseDepth> chromosomeBafPoints : Lists.partition(normalHetSites.get(chromosome), partitionSize)) {
            if (!chromosomeBafPoints.isEmpty()) {
                final String contig = chromosomeBafPoints.get(0).chromosome();
                final TumorBAFEvidence evidence = new TumorBAFEvidence(config.typicalReadDepth(),
                        config.minMappingQuality(),
                        config.minBaseQuality(),
                        contig,
                        config.tumorBamPath(),
                        readerFactory,
                        chromosomeBafPoints);
                futures.add(executorService.submit(completion.task(evidence)));
            }
        }
    }

    final ListMultimap<Chromosome, TumorBAF> result = ArrayListMultimap.create();
    getFuture(futures).forEach(x -> result.putAll(HumanChromosome.fromString(x.contig()), x.evidence()));

    return result;
}
 
Example #27
Source File: ClusterFactory.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
private ListMultimap<Chromosome, Cluster> cluster(@NotNull final Multimap<Chromosome, SVSegment> variantPositions,
        @NotNull final Multimap<Chromosome, PCFPosition> pcfPositions, @NotNull final ListMultimap<Chromosome, CobaltRatio> ratios) {
    ListMultimap<Chromosome, Cluster> clusters = ArrayListMultimap.create();
    for (Chromosome chromosome : pcfPositions.keySet()) {
        final Collection<PCFPosition> chromosomePcfPositions = pcfPositions.get(chromosome);
        final List<CobaltRatio> chromosomeRatios = ratios.containsKey(chromosome) ? ratios.get(chromosome) : Lists.newArrayList();
        final Collection<SVSegment> chromosomeVariants =
                variantPositions.containsKey(chromosome) ? variantPositions.get(chromosome) : Lists.newArrayList();
        clusters.putAll(chromosome, cluster(chromosomeVariants, chromosomePcfPositions, chromosomeRatios));
    }

    return clusters;
}
 
Example #28
Source File: Multimaps.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
public static <T extends GenomePosition> ListMultimap<Chromosome, T> fromPositions(@NotNull final Collection<T> regions) {
    final ListMultimap<Chromosome, T> result = ArrayListMultimap.create();
    for (T region : regions) {
        if (HumanChromosome.contains(region.chromosome())) {
            result.put(HumanChromosome.fromString(region.chromosome()), region);
        }
    }

    return result;
}
 
Example #29
Source File: ForceLookupProcessor.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private static void sendChunkToError(
    String[] ids,
    ListMultimap<String, Record> recordsToRetrieve,
    ToErrorContext context,
    ApiFault e
) {
  for (String id : ids) {
    for (Record record : recordsToRetrieve.get(id)) {
      context.toError(record, e);
    }
  }
}
 
Example #30
Source File: PostContainer.java    From sfs with Apache License 2.0 5 votes vote down vote up
public PostContainer(HttpClient httpClient, String accountName, String containerName, Producer auth, ListMultimap<String, String> headers) {
    this.httpClient = httpClient;
    this.accountName = accountName;
    this.containerName = containerName;
    this.auth = auth;
    this.headers = headers;
}