com.google.common.collect.SortedSetMultimap#get ( )源码实例Demo

下面列出了com.google.common.collect.SortedSetMultimap#get ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hmftools   文件: HmfGenePanelSupplierTest.java
@Test
public void allRegionsAreSortedCorrectly() {
    final SortedSetMultimap<String, HmfTranscriptRegion> geneRegions = HmfGenePanelSupplier.allGenesPerChromosomeMap37();
    for (final String chromosome : geneRegions.keySet()) {
        long start = 0;
        for (final HmfTranscriptRegion hmfTranscriptRegion : geneRegions.get(chromosome)) {
            assertTrue(hmfTranscriptRegion.start() >= start);
            start = hmfTranscriptRegion.start();
        }
    }
}
 
/**
 * Checks whether any tables have had partitioning turned off or not, and updates the partition map appropriately
 *
 * @param reconstructedPartitions the reconstructed partitions (may be modified)
 */
private void handlePartitioningTurnedOffOrOn(
    SortedSetMultimap<TableContext, TableRuntimeContext> reconstructedPartitions
) {

  for (TableContext tableContext : reconstructedPartitions.keySet()) {
    final SortedSet<TableRuntimeContext> partitions = reconstructedPartitions.get(tableContext);
    final TableRuntimeContext lastPartition = partitions.last();
    final TableContext sourceTableContext = lastPartition.getSourceTableContext();
    Utils.checkState(
        sourceTableContext.equals(tableContext),
        String.format(
            "Source table context for %s should match TableContext map key of %s",
            lastPartition.getDescription(),
            tableContext.getQualifiedName()
        )
    );

    final boolean partitioningTurnedOff = lastPartition.isPartitioned()
        && sourceTableContext.getPartitioningMode() == PartitioningMode.DISABLED;
    final boolean partitioningTurnedOn = !lastPartition.isPartitioned()
        && sourceTableContext.isPartitionable()
        && sourceTableContext.getPartitioningMode() != PartitioningMode.DISABLED;

    if (!partitioningTurnedOff && !partitioningTurnedOn) {
      continue;
    }

    final Map<String, String> nextStartingOffsets = new HashMap<>();
    final Map<String, String> nextMaxOffsets = new HashMap<>();

    final int newPartitionSequence = lastPartition.getPartitionSequence() > 0 ? lastPartition.getPartitionSequence() + 1 : 1;
    if (partitioningTurnedOff) {
      LOG.info(
          "Table {} has switched from partitioned to non-partitioned; partition sequence {} will be the last (with" +
              " no max offsets)",
          sourceTableContext.getQualifiedName(),
          newPartitionSequence
      );

      lastPartition.getPartitionOffsetStart().forEach(
          (col, off) -> {
            String basedOnStartOffset = lastPartition.generateNextPartitionOffset(col, off);
            nextStartingOffsets.put(col, basedOnStartOffset);
          }
      );

    } else if (partitioningTurnedOn) {

      lastPartition.getPartitionOffsetStart().forEach(
          (col, off) -> {
            String basedOnStoredOffset = lastPartition.getInitialStoredOffsets().get(col);
            nextStartingOffsets.put(col, basedOnStoredOffset);
          }
      );

      nextStartingOffsets.forEach(
          (col, off) -> nextMaxOffsets.put(col, lastPartition.generateNextPartitionOffset(col, off))
      );

      if (!reconstructedPartitions.remove(sourceTableContext, lastPartition)) {
        throw new IllegalStateException(String.format(
            "Failed to remove partition %s for table %s in switching partitioning from off to on",
            lastPartition.getDescription(),
            sourceTableContext.getQualifiedName()
        ));
      }

      LOG.info(
          "Table {} has switched from non-partitioned to partitioned; using last stored offsets as the starting" +
              " offsets for the new partition {}",
          sourceTableContext.getQualifiedName(),
          newPartitionSequence
      );
    }

    final TableRuntimeContext nextPartition = new TableRuntimeContext(
        sourceTableContext,
        lastPartition.isUsingNonIncrementalLoad(),
        (lastPartition.isPartitioned() && !partitioningTurnedOff) || partitioningTurnedOn,
        newPartitionSequence,
        nextStartingOffsets,
        nextMaxOffsets
    );

    reconstructedPartitions.put(sourceTableContext, nextPartition);
  }
}
 
源代码3 项目: buck   文件: MergeAndroidResourcesStep.java
@VisibleForTesting
void writePerPackageRDotJava(
    SortedSetMultimap<String, RDotTxtEntry> packageToResources, ProjectFilesystem filesystem)
    throws IOException {
  for (String rDotJavaPackage : packageToResources.keySet()) {
    Path outputFile = getPathToRDotJava(rDotJavaPackage);
    filesystem.mkdirs(outputFile.getParent());
    try (ThrowingPrintWriter writer =
        new ThrowingPrintWriter(filesystem.newFileOutputStream(outputFile))) {
      writer.format("package %s;\n\n", rDotJavaPackage);
      writer.format("public class %s {\n", rName);

      ImmutableList.Builder<String> customDrawablesBuilder = ImmutableList.builder();
      ImmutableList.Builder<String> grayscaleImagesBuilder = ImmutableList.builder();
      RType lastType = null;

      for (RDotTxtEntry res : packageToResources.get(rDotJavaPackage)) {
        RType type = res.type;
        if (!type.equals(lastType)) {
          // If the previous type needs to be closed, close it.
          if (lastType != null) {
            writer.println("  }\n");
          }

          // Now start the block for the new type.
          writer.format("  public static class %s {\n", type);
          lastType = type;
        }

        // Write out the resource.
        // Write as an int.
        writer.format(
            "    public static%s%s %s=%s;\n",
            forceFinalResourceIds ? " final " : " ", res.idType, res.name, res.idValue);

        if (type == RType.DRAWABLE && res.customType == RDotTxtEntry.CustomDrawableType.CUSTOM) {
          customDrawablesBuilder.add(res.idValue);
        } else if (type == RType.DRAWABLE
            && res.customType == RDotTxtEntry.CustomDrawableType.GRAYSCALE_IMAGE) {
          grayscaleImagesBuilder.add(res.idValue);
        }
      }

      // If some type was written (e.g., the for loop was entered), then the last type needs to be
      // closed.
      if (lastType != null) {
        writer.println("  }\n");
      }

      ImmutableList<String> customDrawables = customDrawablesBuilder.build();
      if (customDrawables.size() > 0) {
        // Add a new field for the custom drawables.
        writer.format("  public static final int[] custom_drawables = ");
        writer.format("{ %s };\n", Joiner.on(",").join(customDrawables));
        writer.format("\n");
      }

      ImmutableList<String> grayscaleImages = grayscaleImagesBuilder.build();
      if (grayscaleImages.size() > 0) {
        // Add a new field for the custom drawables.
        writer.format("  public static final int[] grayscale_images = ");
        writer.format("{ %s };\n", Joiner.on(",").join(grayscaleImages));
        writer.format("\n");
      }

      // Close the class definition.
      writer.println("}");
    }
  }
}
 
源代码4 项目: buck   文件: MergeAndroidResourcesStepTest.java
@Test
public void testGenerateRDotJavaForMultipleSymbolsFiles() throws DuplicateResourceException {
  RDotTxtEntryBuilder entriesBuilder = new RDotTxtEntryBuilder();

  // Merge everything into the same package space.
  String sharedPackageName = "com.facebook.abc";
  entriesBuilder.add(
      new RDotTxtFile(
          sharedPackageName,
          "a-R.txt",
          ImmutableList.of(
              "int id a1 0x7f010001", "int id a2 0x7f010002", "int string a1 0x7f020001")));

  entriesBuilder.add(
      new RDotTxtFile(
          sharedPackageName,
          "b-R.txt",
          ImmutableList.of(
              "int id b1 0x7f010001", "int id b2 0x7f010002", "int string a1 0x7f020001")));

  entriesBuilder.add(
      new RDotTxtFile(
          sharedPackageName,
          "c-R.txt",
          ImmutableList.of("int attr c1 0x7f010001", "int[] styleable c1 { 0x7f010001 }")));

  SortedSetMultimap<String, RDotTxtEntry> packageNameToResources =
      MergeAndroidResourcesStep.sortSymbols(
          entriesBuilder.buildFilePathToPackageNameSet(),
          Optional.empty(),
          ImmutableMap.of(),
          Optional.empty(),
          /* bannedDuplicateResourceTypes */ EnumSet.noneOf(RType.class),
          ImmutableSet.of(),
          entriesBuilder.getProjectFilesystem(),
          false);

  assertEquals(1, packageNameToResources.keySet().size());
  SortedSet<RDotTxtEntry> resources = packageNameToResources.get(sharedPackageName);
  assertEquals(7, resources.size());

  Set<String> uniqueEntries = new HashSet<>();
  for (RDotTxtEntry resource : resources) {
    if (!resource.type.equals(STYLEABLE)) {
      assertFalse(
          "Duplicate ids should be fixed by renumerate=true; duplicate was: " + resource.idValue,
          uniqueEntries.contains(resource.idValue));
      uniqueEntries.add(resource.idValue);
    }
  }

  assertEquals(6, uniqueEntries.size());

  // All good, no need to further test whether we can write the Java file correctly...
}
 
源代码5 项目: buck   文件: MergeAndroidResourcesStepTest.java
@Test
public void testGenerateRDotJavaForWithStyleables() throws DuplicateResourceException {
  RDotTxtEntryBuilder entriesBuilder = new RDotTxtEntryBuilder();

  // Merge everything into the same package space.
  String sharedPackageName = "com.facebook.abc";
  entriesBuilder.add(
      new RDotTxtFile(
          sharedPackageName,
          "a-R.txt",
          ImmutableList.of(
              "int attr android_layout 0x010100f2",
              "int attr buttonPanelSideLayout 0x7f01003a",
              "int attr listLayout 0x7f01003b",
              "int[] styleable AlertDialog { 0x7f01003a, 0x7f01003b, 0x010100f2 }",
              "int styleable AlertDialog_android_layout 2",
              "int styleable AlertDialog_buttonPanelSideLayout 0",
              "int styleable AlertDialog_multiChoiceItemLayout 1")));
  entriesBuilder.add(
      new RDotTxtFile(
          sharedPackageName,
          "b-R.txt",
          ImmutableList.of(
              "int id a1 0x7f010001",
              "int id a2 0x7f010002",
              "int attr android_layout_gravity 0x7f078008",
              "int attr background 0x7f078009",
              "int attr backgroundSplit 0x7f078008",
              "int attr backgroundStacked 0x7f078010",
              "int attr layout_heightPercent 0x7f078012",
              "int[] styleable ActionBar {  }",
              "int styleable ActionBar_background 10",
              "int styleable ActionBar_backgroundSplit 12",
              "int styleable ActionBar_backgroundStacked 11",
              "int[] styleable ActionBarLayout { 0x7f060008 }",
              "int styleable ActionBarLayout_android_layout 0",
              "int styleable ActionBarLayout_android_layout_gravity 1",
              "int[] styleable PercentLayout_Layout { }",
              "int styleable PercentLayout_Layout_layout_aspectRatio 9",
              "int styleable PercentLayout_Layout_layout_heightPercent 1")));

  SortedSetMultimap<String, RDotTxtEntry> packageNameToResources =
      MergeAndroidResourcesStep.sortSymbols(
          entriesBuilder.buildFilePathToPackageNameSet(),
          Optional.empty(),
          ImmutableMap.of(),
          Optional.empty(),
          /* bannedDuplicateResourceTypes */ EnumSet.noneOf(RType.class),
          ImmutableSet.of(),
          entriesBuilder.getProjectFilesystem(),
          false);

  assertEquals(23, packageNameToResources.size());

  ArrayList<RDotTxtEntry> resources =
      new ArrayList<>(packageNameToResources.get(sharedPackageName));
  assertEquals(23, resources.size());

  System.out.println(resources);

  ImmutableList<RDotTxtEntry> fakeRDotTxtEntryWithIDS =
      ImmutableList.of(
          FakeEntry.createWithId(INT, ATTR, "android_layout_gravity", "0x07f01005"),
          FakeEntry.createWithId(INT, ATTR, "background", "0x07f01006"),
          FakeEntry.createWithId(INT, ATTR, "backgroundSplit", "0x07f01007"),
          FakeEntry.createWithId(INT, ATTR, "backgroundStacked", "0x07f01008"),
          FakeEntry.createWithId(INT, ATTR, "buttonPanelSideLayout", "0x07f01001"),
          FakeEntry.createWithId(INT, ATTR, "layout_heightPercent", "0x07f01009"),
          FakeEntry.createWithId(INT, ATTR, "listLayout", "0x07f01002"),
          FakeEntry.createWithId(INT, ID, "a1", "0x07f01003"),
          FakeEntry.createWithId(INT, ID, "a2", "0x07f01004"),
          FakeEntry.createWithId(
              INT_ARRAY, STYLEABLE, "ActionBar", "{ 0x07f01006,0x07f01007,0x07f01008 }"),
          FakeEntry.createWithId(INT, STYLEABLE, "ActionBar_background", "0"),
          FakeEntry.createWithId(INT, STYLEABLE, "ActionBar_backgroundSplit", "1"),
          FakeEntry.createWithId(INT, STYLEABLE, "ActionBar_backgroundStacked", "2"),
          FakeEntry.createWithId(
              INT_ARRAY, STYLEABLE, "ActionBarLayout", "{ 0x010100f2,0x07f01005 }"),
          FakeEntry.createWithId(INT, STYLEABLE, "ActionBarLayout_android_layout", "0"),
          FakeEntry.createWithId(INT, STYLEABLE, "ActionBarLayout_android_layout_gravity", "1"),
          FakeEntry.createWithId(
              INT_ARRAY, STYLEABLE, "AlertDialog", "{ 0x010100f2,0x07f01001,0x7f01003b }"),
          FakeEntry.createWithId(INT, STYLEABLE, "AlertDialog_android_layout", "0"),
          FakeEntry.createWithId(INT, STYLEABLE, "AlertDialog_buttonPanelSideLayout", "1"),
          FakeEntry.createWithId(INT, STYLEABLE, "AlertDialog_multiChoiceItemLayout", "2"),
          FakeEntry.createWithId(
              INT_ARRAY, STYLEABLE, "PercentLayout_Layout", "{ 0x00000000,0x07f01009 }"),
          FakeEntry.createWithId(INT, STYLEABLE, "PercentLayout_Layout_layout_aspectRatio", "0"),
          FakeEntry.createWithId(
              INT, STYLEABLE, "PercentLayout_Layout_layout_heightPercent", "1"));

  assertEquals(createTestingFakesWithIds(resources), fakeRDotTxtEntryWithIDS);
}