Java 类com.google.common.collect.SortedSetMultimap 实例源码

项目:sstable-adaptor    文件:ColumnFilter.java   
public ColumnFilter build()
{
    boolean isFetchAll = metadata != null;

    PartitionColumns queried = queriedBuilder == null ? null : queriedBuilder.build();
    // It's only ok to have queried == null in ColumnFilter if isFetchAll. So deal with the case of a selectionBuilder
    // with nothing selected (we can at least happen on some backward compatible queries - CASSANDRA-10471).
    if (!isFetchAll && queried == null)
        queried = PartitionColumns.NONE;

    SortedSetMultimap<ColumnIdentifier, ColumnSubselection> s = null;
    if (subSelections != null)
    {
        s = TreeMultimap.create(Comparator.<ColumnIdentifier>naturalOrder(), Comparator.<ColumnSubselection>naturalOrder());
        for (ColumnSubselection subSelection : subSelections)
            s.put(subSelection.column().name, subSelection);
    }

    return new ColumnFilter(isFetchAll, metadata, queried, s);
}
项目:matchmaker    文件:MultiMatcherMatchFunctions.java   
private static <R> Stream<Matcher<R>> potentialMatchersInOrder(
        List<Matcher<R>> cases,
        SortedSetMultimap<Class<?>, Indexed<Matcher<R>>> matchersByScopeType,
        Object object
) {
    if (object == null) {
        return cases.stream();
    } else {
        Stream<Class<?>> supertypes = Util.supertypes(object.getClass());
        TreeSet<Indexed<Matcher<R>>> indexedMatchersInOrder = supertypes
                .flatMap(type -> matchersByScopeType.get(type).stream())
                .collect(toCollection(TreeSet::new));
        return indexedMatchersInOrder.stream()
                .map(Indexed::value);
    }
}
项目:beam    文件:PipelineOptionsFactory.java   
/**
 * Output the requirement groups that the property is a member of, including all properties that
 * satisfy the group requirement, breaking up long lines on white space characters and attempting
 * to honor a line limit of {@code TERMINAL_WIDTH}.
 */
private static void prettyPrintRequiredGroups(PrintStream out, Required annotation,
    SortedSetMultimap<String, String> requiredGroupNameToProperties) {
  if (annotation == null || annotation.groups() == null) {
    return;
  }
  for (String group : annotation.groups()) {
    SortedSet<String> groupMembers = requiredGroupNameToProperties.get(group);
    String requirement;
    if (groupMembers.size() == 1) {
      requirement = Iterables.getOnlyElement(groupMembers) + " is required.";
    } else {
      requirement = "At least one of " + groupMembers + " is required";
    }
    terminalPrettyPrint(out, requirement.split("\\s+"));
  }
}
项目:beam    文件:PipelineOptionsFactory.java   
/**
 * Validates that a given class conforms to the following properties:
 * <ul>
 *   <li>Only getters may be annotated with {@link JsonIgnore @JsonIgnore}.
 *   <li>If any getter is annotated with {@link JsonIgnore @JsonIgnore}, then all getters for
 *       this property must be annotated with {@link JsonIgnore @JsonIgnore}.
 * </ul>
 *
 * @param allInterfaceMethods All interface methods that derive from {@link PipelineOptions}.
 * @param descriptors The list of {@link PropertyDescriptor}s representing all valid bean
 * properties of {@code iface}.
 */
private static void validateMethodAnnotations(
    SortedSet<Method> allInterfaceMethods,
    List<PropertyDescriptor> descriptors) {
  SortedSetMultimap<Method, Method> methodNameToAllMethodMap =
      TreeMultimap.create(MethodNameComparator.INSTANCE, MethodComparator.INSTANCE);
  for (Method method : allInterfaceMethods) {
    methodNameToAllMethodMap.put(method, method);
  }

  // Verify that there is no getter with a mixed @JsonIgnore annotation.
  validateGettersHaveConsistentAnnotation(
      methodNameToAllMethodMap, descriptors, AnnotationPredicates.JSON_IGNORE);

  // Verify that there is no getter with a mixed @Default annotation.
  validateGettersHaveConsistentAnnotation(
      methodNameToAllMethodMap, descriptors, AnnotationPredicates.DEFAULT_VALUE);

  // Verify that no setter has @JsonIgnore.
  validateSettersDoNotHaveAnnotation(
      methodNameToAllMethodMap, descriptors, AnnotationPredicates.JSON_IGNORE);

  // Verify that no setter has @Default.
  validateSettersDoNotHaveAnnotation(
      methodNameToAllMethodMap, descriptors, AnnotationPredicates.DEFAULT_VALUE);
}
项目:gerrit    文件:GroupCollectorTest.java   
@Test
public void mergeCommitWhereOneParentHasExistingGroup() throws Exception {
  RevCommit branchTip = tr.commit().create();
  RevCommit a = tr.commit().parent(branchTip).create();
  RevCommit b = tr.commit().parent(branchTip).create();
  RevCommit m = tr.commit().parent(a).parent(b).create();

  String group = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
  SortedSetMultimap<ObjectId, String> groups =
      collectGroups(
          newWalk(m, branchTip), patchSets().put(b, psId(1, 1)), groups().put(psId(1, 1), group));

  // Merge commit and other parent get the existing group.
  assertThat(groups).containsEntry(a, group);
  assertThat(groups).containsEntry(b, group);
  assertThat(groups).containsEntry(m, group);
}
项目:gerrit    文件:GroupCollectorTest.java   
@Test
public void mergeCommitWhereBothParentsHaveDifferentGroups() throws Exception {
  RevCommit branchTip = tr.commit().create();
  RevCommit a = tr.commit().parent(branchTip).create();
  RevCommit b = tr.commit().parent(branchTip).create();
  RevCommit m = tr.commit().parent(a).parent(b).create();

  String group1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
  String group2 = "1234567812345678123456781234567812345678";
  SortedSetMultimap<ObjectId, String> groups =
      collectGroups(
          newWalk(m, branchTip),
          patchSets().put(a, psId(1, 1)).put(b, psId(2, 1)),
          groups().put(psId(1, 1), group1).put(psId(2, 1), group2));

  assertThat(groups).containsEntry(a, group1);
  assertThat(groups).containsEntry(b, group2);
  // Merge commit gets joined group of parents.
  assertThat(groups.asMap()).containsEntry(m, ImmutableSet.of(group1, group2));
}
项目:gerrit    文件:GroupCollectorTest.java   
@Test
public void mergeCommitMergesGroupsFromParent() throws Exception {
  RevCommit branchTip = tr.commit().create();
  RevCommit a = tr.commit().parent(branchTip).create();
  RevCommit b = tr.commit().parent(branchTip).create();
  RevCommit m = tr.commit().parent(a).parent(b).create();

  String group1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
  String group2a = "1234567812345678123456781234567812345678";
  String group2b = "ef123456ef123456ef123456ef123456ef123456";
  SortedSetMultimap<ObjectId, String> groups =
      collectGroups(
          newWalk(m, branchTip),
          patchSets().put(a, psId(1, 1)).put(b, psId(2, 1)),
          groups().put(psId(1, 1), group1).put(psId(2, 1), group2a).put(psId(2, 1), group2b));

  assertThat(groups).containsEntry(a, group1);
  assertThat(groups.asMap()).containsEntry(b, ImmutableSet.of(group2a, group2b));
  // Joined parent groups are split and resorted.
  assertThat(groups.asMap()).containsEntry(m, ImmutableSet.of(group1, group2a, group2b));
}
项目:gerrit    文件:GroupCollectorTest.java   
@Test
public void multipleMergeCommitsInHistoryAllResolveToSameGroup() throws Exception {
  RevCommit branchTip = tr.commit().create();
  RevCommit a = tr.commit().parent(branchTip).create();
  RevCommit b = tr.commit().parent(branchTip).create();
  RevCommit c = tr.commit().parent(branchTip).create();
  RevCommit m1 = tr.commit().parent(b).parent(c).create();
  RevCommit m2 = tr.commit().parent(a).parent(m1).create();

  SortedSetMultimap<ObjectId, String> groups =
      collectGroups(newWalk(m2, branchTip), patchSets(), groups());

  assertThat(groups).containsEntry(a, a.name());
  assertThat(groups).containsEntry(b, a.name());
  assertThat(groups).containsEntry(c, a.name());
  assertThat(groups).containsEntry(m1, a.name());
  assertThat(groups).containsEntry(m2, a.name());
}
项目:gerrit    文件:GroupCollectorTest.java   
@Test
public void mergeCommitWithOneNewParentAndTwoExistingPatchSets() throws Exception {
  RevCommit branchTip = tr.commit().create();
  RevCommit a = tr.commit().parent(branchTip).create();
  RevCommit b = tr.commit().parent(branchTip).create();
  RevCommit c = tr.commit().parent(b).create();
  RevCommit m = tr.commit().parent(a).parent(c).create();

  String group1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
  String group2 = "1234567812345678123456781234567812345678";
  SortedSetMultimap<ObjectId, String> groups =
      collectGroups(
          newWalk(m, branchTip),
          patchSets().put(a, psId(1, 1)).put(b, psId(2, 1)),
          groups().put(psId(1, 1), group1).put(psId(2, 1), group2));

  assertThat(groups).containsEntry(a, group1);
  assertThat(groups).containsEntry(b, group2);
  assertThat(groups).containsEntry(c, group2);
  assertThat(groups.asMap()).containsEntry(m, ImmutableSet.of(group1, group2));
}
项目:datacollector    文件:MultithreadedTableProvider.java   
public Set<String> initializeFromV1Offsets(Map<String, String> offsets) throws StageException {
  // v1 offsets map qualified table names to offset column positions
  LOG.info("Upgrading offsets from v1 to v2; logging current offsets now");
  offsets.forEach((t, v) -> LOG.info("{} -> {}", t, v));

  final Set<String> offsetKeysToRemove = new HashSet<>();
  SortedSetMultimap<TableContext, TableRuntimeContext> v1Offsets = TableRuntimeContext.initializeAndUpgradeFromV1Offsets(
      tableContextMap,
      offsets,
      offsetKeysToRemove
  );
  generateInitialPartitionsInSharedQueue(true, v1Offsets, null);

  initializeMaxPartitionWithDataPerTable(offsets);
  return offsetKeysToRemove;
}
项目:scylla-tools-java    文件:ColumnFilter.java   
public ColumnFilter build()
{
    boolean isFetchAll = metadata != null;

    PartitionColumns selectedColumns = selection == null ? null : selection.build();
    // It's only ok to have selection == null in ColumnFilter if isFetchAll. So deal with the case of a "selection" builder
    // with nothing selected (we can at least happen on some backward compatible queries - CASSANDRA-10471).
    if (!isFetchAll && selectedColumns == null)
        selectedColumns = PartitionColumns.NONE;

    SortedSetMultimap<ColumnIdentifier, ColumnSubselection> s = null;
    if (subSelections != null)
    {
        s = TreeMultimap.create(Comparator.<ColumnIdentifier>naturalOrder(), Comparator.<ColumnSubselection>naturalOrder());
        for (ColumnSubselection subSelection : subSelections)
            s.put(subSelection.column().name, subSelection);
    }

    return new ColumnFilter(isFetchAll, metadata, selectedColumns, s);
}
项目:anycook-api    文件:DBSearch.java   
public SortedSetMultimap<Integer, String> getRecipesWithoutIngredient(String ingredient) throws SQLException {
    SortedSetMultimap<Integer, String> recipes = TreeMultimap.create(new InvertedComparator<Integer>(),
            new InvertedComparator<String>());
    PreparedStatement pStatement = connection.prepareStatement(
            "SELECT gerichte2.name, COUNT(schmeckt.users_id) AS schmecktcount FROM gerichte AS gerichte2 " +
                    "LEFT JOIN schmeckt ON gerichte2.name = schmeckt.gerichte_name " +
                    "WHERE gerichte2.name NOT IN (" +
                    "SELECT gerichte.name FROM gerichte " +
                    "INNER JOIN versions ON gerichte.name = versions.gerichte_name AND gerichte.active_id = versions.id " +
                    "INNER JOIN versions_has_zutaten ON versions.gerichte_name = versions_gerichte_name AND id = versions_id " +
                    "WHERE zutaten_name = ?) " +
                    "GROUP BY gerichte2.name");
    pStatement.setString(1, ingredient);
    try (ResultSet data = pStatement.executeQuery()) {
        while (data.next())
            recipes.put(data.getInt("schmecktcount"), data.getString("gerichte2.name"));
    }

    return recipes;
}
项目:sstable-adaptor    文件:ColumnFilter.java   
private ColumnFilter(boolean isFetchAll,
                     CFMetaData metadata,
                     PartitionColumns queried,
                     SortedSetMultimap<ColumnIdentifier, ColumnSubselection> subSelections)
{
    assert !isFetchAll || metadata != null;
    assert isFetchAll || queried != null;
    this.isFetchAll = isFetchAll;
    this.metadata = metadata;
    this.queried = queried;
    this.subSelections = subSelections;
}
项目:sstable-adaptor    文件:ColumnFilter.java   
public ColumnFilter deserialize(DataInputPlus in, int version, CFMetaData metadata) throws IOException
{
    int header = in.readUnsignedByte();
    boolean isFetchAll = (header & IS_FETCH_ALL_MASK) != 0;
    boolean hasQueried = (header & HAS_QUERIED_MASK) != 0;
    boolean hasSubSelections = (header & HAS_SUB_SELECTIONS_MASK) != 0;

    PartitionColumns queried = null;
    if (hasQueried)
    {
        Columns statics = Columns.serializer.deserialize(in, metadata);
        Columns regulars = Columns.serializer.deserialize(in, metadata);
        queried = new PartitionColumns(statics, regulars);
    }

    SortedSetMultimap<ColumnIdentifier, ColumnSubselection> subSelections = null;
    if (hasSubSelections)
    {
        subSelections = TreeMultimap.create(Comparator.<ColumnIdentifier>naturalOrder(), Comparator.<ColumnSubselection>naturalOrder());
        int size = (int)in.readUnsignedVInt();
        for (int i = 0; i < size; i++)
        {
            ColumnSubselection subSel = ColumnSubselection.serializer.deserialize(in, version, metadata);
            subSelections.put(subSel.column().name, subSel);
        }
    }

    return new ColumnFilter(isFetchAll, isFetchAll ? metadata : null, queried, subSelections);
}
项目:n4js    文件:ReportUtils.java   
/** Creates a histogram of the given collections */
static public <E extends Comparable<E>, T extends Comparable<T>> Multimap<T, E> getHistogram(Collection<E> elems,
        Function<E, T> pivot) {

    final SortedSetMultimap<T, E> histogram = TreeMultimap.create();
    for (E elem : elems) {
        T t = pivot.apply(elem);
        histogram.put(t, elem);
    }
    return histogram;
}
项目:matchmaker    文件:MultiMatcherMatchFunctions.java   
static <R> BiFunction<Object, Captures, Match<R>> returnFirst(List<Matcher<R>> cases) {
    SortedSetMultimap<Class<?>, Indexed<Matcher<R>>> matchersByScopeType = indexByScopeType(cases);
    return (object, captures) -> {
        Stream<Match<R>> successfulCases = successfulCases(cases, matchersByScopeType, object);
        return successfulCases.findFirst().orElse(Match.empty());
    };
}
项目:matchmaker    文件:MultiMatcherMatchFunctions.java   
static <R> BiFunction<Object, Captures, Match<List<R>>> returnAll(List<Matcher<R>> cases) {
    SortedSetMultimap<Class<?>, Indexed<Matcher<R>>> matchersByScopeType = indexByScopeType(cases);
    return (object, captures) -> {
        Stream<Match<R>> successfulCases = successfulCases(cases, matchersByScopeType, object);
        //TODO we're losing captures here
        List<R> allMatches = successfulCases.map(Match::value).collect(toList());
        return Match.of(allMatches, captures)
                .filter(matches -> !matches.isEmpty())
                .flatMap(value -> createMatch(null, allMatches, captures));
    };
}
项目:matchmaker    文件:MultiMatcherMatchFunctions.java   
private static <R> SortedSetMultimap<Class<?>, Indexed<Matcher<R>>> indexByScopeType(List<Matcher<R>> cases) {
    SortedSetMultimap<Class<?>, Indexed<Matcher<R>>> matchersByScopeType =
            newSortedSetMultimap(new HashMap<>(), TreeSet::new);
    AtomicInteger i = new AtomicInteger();
    Stream<Indexed<Matcher<R>>> indexedMatchers = cases.stream().map(c -> Indexed.at(i.getAndIncrement(), c));
    indexedMatchers.forEach(matcher -> matchersByScopeType.put(matcher.value().getScopeType(), matcher));
    return matchersByScopeType;
}
项目:matchmaker    文件:MultiMatcherMatchFunctions.java   
private static <R> Stream<Match<R>> successfulCases(
        List<Matcher<R>> cases,
        SortedSetMultimap<Class<?>, Indexed<Matcher<R>>> matchersByScopeType,
        Object object
) {
    Stream<Matcher<R>> potentialMatchersInOrder = potentialMatchersInOrder(cases, matchersByScopeType, object);
    Stream<Match<R>> caseResults = potentialMatchersInOrder
            .map(matcher -> matcher.match(object));
    return caseResults.filter(Match::isPresent);
}
项目:IntelliJ-Action-IDs    文件:ProcessActionsXml.java   
public static void main(String[] args) throws IOException {
    if(args.length == 0) {
        System.err.println("Usage: ProcessActionsXml <IntelliJDir1> [<IntelliJDir2] ...");
        return;
    }

    try (final Writer out = new BufferedWriter(new FileWriter("docs/_data/actions.csv"))) {
        try (final CSVPrinter printer = CSVFormat.DEFAULT.withHeader("file", "id", "text", "group", "link").print(out)) {
            for (String dir : args) {
                ActionDirectoryWalker walker = new ActionDirectoryWalker();
                final SortedSetMultimap<String, ActionIDDef> ids = walker.walk(new File(dir));
                for (String file : ids.keySet()) {
                    for (ActionIDDef def : ids.get(file)) {
                        final String fileName = StringUtils.removeStart(StringUtils.removeStart(StringUtils.removeStart(file, dir), "\\"), "/");
                        System.out.println("File: " + fileName + ": had " + def.getId() + "/" + def.getText() + "/" + def.getGroup() + "/" + def.getLink());
                        printer.print(fileName);
                        printer.print(def.getId());
                        printer.print(def.getText());
                        printer.print(def.getGroup());
                        printer.print(def.getLink());
                        printer.println();
                    }
                }

                System.out.println("Found " + ids.size() + " actions in " + ids.keySet().size() + " files");
            }
        }
    }
}
项目:hmftools    文件:SlicerTest.java   
@Before
public void setup() {
    final SortedSetMultimap<String, GenomeRegion> regionMap = TreeMultimap.create();
    regionMap.put("X", GenomeRegionFactory.create("X", 100, 200));
    regionMap.put("X", GenomeRegionFactory.create("X", 300, 400));
    regionMap.put("Y", GenomeRegionFactory.create("Y", 500, 600));

    bidirectionalSlicer = new BidirectionalSlicer(regionMap);
    forwardSlicer = new ForwardSlicer(regionMap);
}
项目:hmftools    文件:BEDFileLoaderTest.java   
@Test
public void testStartIsOneBased() throws IOException, EmptyFileException {
    final String bedFile = BED_FILE_BASE_PATH + File.separator + VALID_BED;
    final SortedSetMultimap<String, GenomeRegion> regions = BEDFileLoader.fromBedFile(bedFile);
    assertEquals(1, regions.get("1").first().start());
    assertEquals(1, regions.get("1").first().end());
}
项目:hmftools    文件:HmfGenePanelSupplierTest.java   
@Test
public void loadedRegionsAreSortedCorrectly() throws IOException, EmptyFileException {
    final SortedSetMultimap<String, HmfGenomeRegion> geneRegions = HmfGenePanelSupplier.allGeneMap();
    for (final String chromosome : geneRegions.keySet()) {
        long start = 0;
        for (final HmfGenomeRegion hmfGenomeRegion : geneRegions.get(chromosome)) {
            assertTrue(hmfGenomeRegion.start() >= start);
            start = hmfGenomeRegion.start();
        }
    }
}
项目:beam    文件:PipelineOptionsFactory.java   
/**
 * Returns a map of required groups of arguments to the properties that satisfy the requirement.
 */
private static SortedSetMultimap<String, String> getRequiredGroupNamesToProperties(
    Map<String, Method> propertyNamesToGetters) {
  SortedSetMultimap<String, String> result = TreeMultimap.create();
  for (Map.Entry<String, Method> propertyEntry : propertyNamesToGetters.entrySet()) {
    Required requiredAnnotation =
        propertyEntry.getValue().getAnnotation(Validation.Required.class);
    if (requiredAnnotation != null) {
      for (String groupName : requiredAnnotation.groups()) {
        result.put(groupName, propertyEntry.getKey());
      }
    }
  }
  return result;
}
项目:beam    文件:PipelineOptionsFactory.java   
/**
 * Validates that any method with the same name must have the same return type for all derived
 * interfaces of {@link PipelineOptions}.
 *
 * @param iface The interface to validate.
 */
private static void validateReturnType(Class<? extends PipelineOptions> iface) {
  Iterable<Method> interfaceMethods = FluentIterable
      .from(ReflectHelpers.getClosureOfMethodsOnInterface(iface))
      .filter(NOT_SYNTHETIC_PREDICATE)
      .toSortedSet(MethodComparator.INSTANCE);
  SortedSetMultimap<Method, Method> methodNameToMethodMap =
      TreeMultimap.create(MethodNameComparator.INSTANCE, MethodComparator.INSTANCE);
  for (Method method : interfaceMethods) {
    methodNameToMethodMap.put(method, method);
  }
  List<MultipleDefinitions> multipleDefinitions = Lists.newArrayList();
  for (Map.Entry<Method, Collection<Method>> entry
      : methodNameToMethodMap.asMap().entrySet()) {
    Set<Class<?>> returnTypes = FluentIterable.from(entry.getValue())
        .transform(ReturnTypeFetchingFunction.INSTANCE).toSet();
    SortedSet<Method> collidingMethods = FluentIterable.from(entry.getValue())
        .toSortedSet(MethodComparator.INSTANCE);
    if (returnTypes.size() > 1) {
      MultipleDefinitions defs = new MultipleDefinitions();
      defs.method = entry.getKey();
      defs.collidingMethods = collidingMethods;
      multipleDefinitions.add(defs);
    }
  }
  throwForMultipleDefinitions(iface, multipleDefinitions);
}
项目:beam    文件:PipelineOptionsFactory.java   
/**
 * Validates that setters don't have the given annotation.
 */
private static void validateSettersDoNotHaveAnnotation(
    SortedSetMultimap<Method, Method> methodNameToAllMethodMap,
    List<PropertyDescriptor> descriptors,
    AnnotationPredicates annotationPredicates) {
  List<AnnotatedSetter> annotatedSetters = new ArrayList<>();
  for (PropertyDescriptor descriptor : descriptors) {
    if (descriptor.getWriteMethod() == null
        || IGNORED_METHODS.contains(descriptor.getWriteMethod())) {
      continue;
    }
    SortedSet<Method> settersWithTheAnnotation = Sets.filter(
        methodNameToAllMethodMap.get(descriptor.getWriteMethod()),
        annotationPredicates.forMethod);

    Iterable<String> settersWithTheAnnotationClassNames =
        FluentIterable.from(settersWithTheAnnotation)
        .transform(MethodToDeclaringClassFunction.INSTANCE)
        .transform(ReflectHelpers.CLASS_NAME);

    if (!settersWithTheAnnotation.isEmpty()) {
      AnnotatedSetter annotated = new AnnotatedSetter();
      annotated.descriptor = descriptor;
      annotated.settersWithTheAnnotationClassNames = settersWithTheAnnotationClassNames;
      annotatedSetters.add(annotated);
    }
  }
  throwForSettersWithTheAnnotation(annotatedSetters, annotationPredicates.annotationClass);
}
项目:omakase    文件:AWSRequestSignerV4.java   
private static Multimap<String, String> buildCanonicalizedHeadersMap(HttpMessage request) {
    Header[] headers = request.getAllHeaders();
    SortedSetMultimap<String, String> canonicalizedHeaders = TreeMultimap.create();
    for (Header header : headers) {
        if (header.getName() == null) {
            continue;
        }
        String key = header.getName().toLowerCase();
        canonicalizedHeaders.put(key, header.getValue());
    }
    return canonicalizedHeaders;
}
项目:gerrit    文件:GroupCollector.java   
public SortedSetMultimap<ObjectId, String> getGroups() throws OrmException {
  done = true;
  SortedSetMultimap<ObjectId, String> result =
      MultimapBuilder.hashKeys(groups.keySet().size()).treeSetValues().build();
  for (Map.Entry<ObjectId, Collection<String>> e : groups.asMap().entrySet()) {
    ObjectId id = e.getKey();
    result.putAll(id.copy(), resolveGroups(id, e.getValue()));
  }
  return result;
}
项目:gerrit    文件:GroupCollectorTest.java   
@Test
public void commitWhoseParentIsUninterestingGetsNewGroup() throws Exception {
  RevCommit branchTip = tr.commit().create();
  RevCommit a = tr.commit().parent(branchTip).create();

  SortedSetMultimap<ObjectId, String> groups =
      collectGroups(newWalk(a, branchTip), patchSets(), groups());

  assertThat(groups).containsEntry(a, a.name());
}
项目:gerrit    文件:GroupCollectorTest.java   
@Test
public void commitWhoseParentIsNewPatchSetGetsParentsGroup() throws Exception {
  RevCommit branchTip = tr.commit().create();
  RevCommit a = tr.commit().parent(branchTip).create();
  RevCommit b = tr.commit().parent(a).create();

  SortedSetMultimap<ObjectId, String> groups =
      collectGroups(newWalk(b, branchTip), patchSets(), groups());

  assertThat(groups).containsEntry(a, a.name());
  assertThat(groups).containsEntry(b, a.name());
}
项目:gerrit    文件:GroupCollectorTest.java   
@Test
public void commitWhoseParentIsExistingPatchSetGetsParentsGroup() throws Exception {
  RevCommit branchTip = tr.commit().create();
  RevCommit a = tr.commit().parent(branchTip).create();
  RevCommit b = tr.commit().parent(a).create();

  String group = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
  SortedSetMultimap<ObjectId, String> groups =
      collectGroups(
          newWalk(b, branchTip), patchSets().put(a, psId(1, 1)), groups().put(psId(1, 1), group));

  assertThat(groups).containsEntry(a, group);
  assertThat(groups).containsEntry(b, group);
}
项目:gerrit    文件:GroupCollectorTest.java   
@Test
public void commitWhoseParentIsExistingPatchSetWithNoGroup() throws Exception {
  RevCommit branchTip = tr.commit().create();
  RevCommit a = tr.commit().parent(branchTip).create();
  RevCommit b = tr.commit().parent(a).create();

  SortedSetMultimap<ObjectId, String> groups =
      collectGroups(newWalk(b, branchTip), patchSets().put(a, psId(1, 1)), groups());

  assertThat(groups).containsEntry(a, a.name());
  assertThat(groups).containsEntry(b, a.name());
}
项目:gerrit    文件:GroupCollectorTest.java   
@Test
public void mergeCommitAndNewParentsAllGetSameGroup() throws Exception {
  RevCommit branchTip = tr.commit().create();
  RevCommit a = tr.commit().parent(branchTip).create();
  RevCommit b = tr.commit().parent(branchTip).create();
  RevCommit m = tr.commit().parent(a).parent(b).create();

  SortedSetMultimap<ObjectId, String> groups =
      collectGroups(newWalk(m, branchTip), patchSets(), groups());

  assertThat(groups).containsEntry(a, a.name());
  assertThat(groups).containsEntry(b, a.name());
  assertThat(groups).containsEntry(m, a.name());
}
项目:gerrit    文件:GroupCollectorTest.java   
@Test
public void mergeCommitWithOneUninterestingParentAndOtherParentIsExisting() throws Exception {
  RevCommit branchTip = tr.commit().create();
  RevCommit a = tr.commit().parent(branchTip).create();
  RevCommit m = tr.commit().parent(branchTip).parent(a).create();

  String group = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
  SortedSetMultimap<ObjectId, String> groups =
      collectGroups(
          newWalk(m, branchTip), patchSets().put(a, psId(1, 1)), groups().put(psId(1, 1), group));

  assertThat(groups).containsEntry(a, group);
  assertThat(groups).containsEntry(m, group);
}
项目:gerrit    文件:GroupCollectorTest.java   
@Test
public void mergeCommitWithOneUninterestingParentAndOtherParentIsNew() throws Exception {
  RevCommit branchTip = tr.commit().create();
  RevCommit a = tr.commit().parent(branchTip).create();
  RevCommit m = tr.commit().parent(branchTip).parent(a).create();

  SortedSetMultimap<ObjectId, String> groups =
      collectGroups(newWalk(m, branchTip), patchSets(), groups());

  assertThat(groups).containsEntry(a, a.name());
  assertThat(groups).containsEntry(m, a.name());
}
项目:gerrit    文件:GroupCollectorTest.java   
@Test
public void mergeCommitWithDuplicatedParentGetsParentsGroup() throws Exception {
  RevCommit branchTip = tr.commit().create();
  RevCommit a = tr.commit().parent(branchTip).create();
  RevCommit m = tr.commit().parent(a).parent(a).create();
  tr.getRevWalk().parseBody(m);
  assertThat(m.getParentCount()).isEqualTo(2);
  assertThat(m.getParent(0)).isEqualTo(m.getParent(1));

  SortedSetMultimap<ObjectId, String> groups =
      collectGroups(newWalk(m, branchTip), patchSets(), groups());

  assertThat(groups).containsEntry(a, a.name());
  assertThat(groups).containsEntry(m, a.name());
}
项目:gerrit    文件:GroupCollectorTest.java   
@Test
public void collectGroupsForMultipleTipsInParallel() throws Exception {
  RevCommit branchTip = tr.commit().create();
  RevCommit a = tr.commit().parent(branchTip).create();
  RevCommit b = tr.commit().parent(a).create();
  RevCommit c = tr.commit().parent(branchTip).create();
  RevCommit d = tr.commit().parent(c).create();

  RevWalk rw = newWalk(b, branchTip);
  rw.markStart(rw.parseCommit(d));
  // Schema upgrade case: all commits are existing patch sets, but none have
  // groups assigned yet.
  SortedSetMultimap<ObjectId, String> groups =
      collectGroups(
          rw,
          patchSets()
              .put(branchTip, psId(1, 1))
              .put(a, psId(2, 1))
              .put(b, psId(3, 1))
              .put(c, psId(4, 1))
              .put(d, psId(5, 1)),
          groups());

  assertThat(groups).containsEntry(a, a.name());
  assertThat(groups).containsEntry(b, a.name());
  assertThat(groups).containsEntry(c, c.name());
  assertThat(groups).containsEntry(d, c.name());
}
项目:gerrit    文件:GroupCollectorTest.java   
private static SortedSetMultimap<ObjectId, String> collectGroups(
    RevWalk rw,
    ImmutableListMultimap.Builder<ObjectId, PatchSet.Id> patchSetsBySha,
    ImmutableListMultimap.Builder<PatchSet.Id, String> groupLookup)
    throws Exception {
  GroupCollector gc = new GroupCollector(patchSetsBySha.build(), groupLookup.build());
  RevCommit c;
  while ((c = rw.next()) != null) {
    gc.visit(c);
  }
  return gc.getGroups();
}
项目:datacollector    文件:TableRuntimeContext.java   
public static SortedSetMultimap<TableContext, TableRuntimeContext> initializeAndUpgradeFromV1Offsets(
    Map<String, TableContext> tableContextMap,
    Map<String, String> offsets,
    Set<String> offsetKeysToRemove
) throws StageException {
  SortedSetMultimap<TableContext, TableRuntimeContext> returnMap = buildSortedPartitionMap();

  for (Map.Entry<String, TableContext> tableEntry : tableContextMap.entrySet()) {
    final String tableName = tableEntry.getKey();
    final TableContext tableContext = tableEntry.getValue();

    Map<String, String> startingOffsets;
    String offsetValue = null;
    Map<String, String> storedOffsets = null;
    if (offsets.containsKey(tableName)) {
      offsetValue = offsets.remove(tableName);
      storedOffsets = OffsetQueryUtil.validateStoredAndSpecifiedOffset(tableContext, offsetValue);

      offsetKeysToRemove.add(tableName);

      startingOffsets = OffsetQueryUtil.getOffsetsFromSourceKeyRepresentation(offsetValue);
      tableContext.getOffsetColumnToStartOffset().putAll(startingOffsets);
    }

    final TableRuntimeContext partition = createInitialPartition(tableContext, storedOffsets);
    returnMap.put(tableContext, partition);

    if (offsetValue != null) {
      offsets.put(partition.getOffsetKey(), offsetValue);
    }
  }

  return returnMap;
}
项目:datacollector    文件:MultithreadedTableProvider.java   
public void initializeFromV2Offsets(
    Map<String, String> offsets,
    Map<String, String> newCommitOffsets
) throws StageException {
  final Set<TableContext> excludeTables = new HashSet<>();
  SortedSetMultimap<TableContext, TableRuntimeContext> v2Offsets = TableRuntimeContext.buildPartitionsFromStoredV2Offsets(
      tableContextMap,
      offsets,
      excludeTables,
      newCommitOffsets
  );
  handlePartitioningTurnedOffOrOn(v2Offsets);
  generateInitialPartitionsInSharedQueue(true, v2Offsets, excludeTables);
  initializeMaxPartitionWithDataPerTable(newCommitOffsets);
}