Java Code Examples for com.google.common.collect.ImmutableSortedSet#of()

The following examples show how to use com.google.common.collect.ImmutableSortedSet#of() . 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: AndroidLibraryGraphEnhancerTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyResources() {
  BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/com/example:library");
  AndroidLibraryGraphEnhancer graphEnhancer =
      new AndroidLibraryGraphEnhancer(
          buildTarget,
          new FakeProjectFilesystem(),
          ImmutableSortedSet.of(),
          DEFAULT_JAVAC,
          DEFAULT_JAVAC_OPTIONS,
          DependencyMode.FIRST_ORDER,
          /* forceFinalResourceIds */ false,
          /* unionPackage */ Optional.empty(),
          /* rName */ Optional.empty(),
          /* useOldStyleableFormat */ false,
          /* skipNonUnionRDotJava */ false);

  Optional<DummyRDotJava> result =
      graphEnhancer.getBuildableForAndroidResources(
          new TestActionGraphBuilder(), /* createdBuildableIfEmptyDeps */ false);
  assertFalse(result.isPresent());
}
 
Example 2
Source File: PathListing.java    From buck with Apache License 2.0 6 votes vote down vote up
private static ImmutableSortedSet<Path> subSet(
    ImmutableSortedSet<Path> paths, FilterMode filterMode, int limitIndex) {
  // This doesn't copy the contents of the ImmutableSortedSet. We use it
  // as a simple way to get O(1) access to the set's contents, as otherwise
  // we would have to iterate to find the Nth element.
  ImmutableList<Path> pathsList = paths.asList();
  boolean fullSet = limitIndex == paths.size();
  switch (filterMode) {
    case INCLUDE:
      // Make sure we don't call pathsList.get(pathsList.size()).
      if (!fullSet) {
        paths = paths.headSet(pathsList.get(limitIndex));
      }
      break;
    case EXCLUDE:
      if (fullSet) {
        // Make sure we don't call pathsList.get(pathsList.size()).
        paths = ImmutableSortedSet.of();
      } else {
        paths = paths.tailSet(pathsList.get(limitIndex));
      }
      break;
  }
  return paths;
}
 
Example 3
Source File: CxxTestTest.java    From buck with Apache License 2.0 6 votes vote down vote up
public FakeCxxTest() {
  super(
      buildTarget,
      new FakeProjectFilesystem(),
      createBuildParams(),
      new FakeBuildRule("//:target"),
      new CommandTool.Builder().build(),
      ImmutableMap.of(),
      ImmutableList.of(),
      ImmutableSortedSet.of(),
      ImmutableSet.of(),
      unused2 -> ImmutableSortedSet.of(),
      ImmutableSet.of(),
      ImmutableSet.of(),
      /* runTestSeparately */ false,
      TEST_TIMEOUT_MS,
      CxxTestType.GTEST);
}
 
Example 4
Source File: ImmutableConverter.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
@Nonnull
public SortedSet<ImmutableItem> toSortedSet(@Nonnull Comparator<? super ImmutableItem> comparator,
                                            @Nullable final SortedSet<? extends Item> sortedSet) {
    if (sortedSet == null || sortedSet.size() == 0) {
        return ImmutableSortedSet.of();
    }

    @SuppressWarnings("unchecked")
    ImmutableItem[] newItems = (ImmutableItem[])new Object[sortedSet.size()];
    int index = 0;
    for (Item item: sortedSet) {
        newItems[index++] = makeImmutable(item);
    }

    return ArraySortedSet.of(comparator, newItems);
}
 
Example 5
Source File: JavaSourceJarTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void outputNameShouldIndicateThatTheOutputIsASrcJar() {
  ActionGraphBuilder graphBuilder = new TestActionGraphBuilder();
  BuildTarget buildTarget = BuildTargetFactory.newInstance("//example:target");

  JavaSourceJar rule =
      new JavaSourceJar(
          buildTarget,
          new FakeProjectFilesystem(),
          TestBuildRuleParams.create(),
          ImmutableSortedSet.of(),
          Optional.empty());
  graphBuilder.addToIndex(rule);

  SourcePath output = rule.getSourcePathToOutput();

  assertNotNull(output);
  assertThat(
      graphBuilder.getSourcePathResolver().getRelativePath(output).toString(),
      endsWith(JavaPaths.SRC_JAR));
}
 
Example 6
Source File: TestCommandTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testLabelConjunctionsWithInclude() throws CmdLineException {
  TestCommand command = getCommand("--include", "windows+linux");

  TestRule rule1 =
      new FakeTestRule(
          ImmutableSet.of("windows", "linux"),
          BuildTargetFactory.newInstance("//:for"),
          ImmutableSortedSet.of());

  TestRule rule2 =
      new FakeTestRule(
          ImmutableSet.of("windows"),
          BuildTargetFactory.newInstance("//:lulz"),
          ImmutableSortedSet.of());

  List<TestRule> testRules = ImmutableList.of(rule1, rule2);

  Iterable<TestRule> result =
      command.filterTestRules(FakeBuckConfig.builder().build(), ImmutableSet.of(), testRules);
  assertEquals(ImmutableSet.of(rule1), result);
}
 
Example 7
Source File: CachingBuildEngineInitializableFromDiskTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Before
public void setUpChild() throws Exception {
  depfileInput = FakeSourcePath.of(filesystem, "path/in/depfile");
  nonDepfileInput = FakeSourcePath.of(filesystem, "path/not/in/depfile");
  RulePipelineStateFactory<SimplePipelineState> pipelineStateFactory =
      (context, filesystem, firstTarget) -> new SimplePipelineState();
  rootRule = new SimpleNoopRule(BUILD_TARGET.withFlavors(InternalFlavor.of("root")), filesystem);
  dependency =
      new InitializableFromDiskRule(
          BUILD_TARGET.withFlavors(InternalFlavor.of("child")),
          filesystem,
          rootRule,
          ImmutableSortedSet.of(depfileInput, nonDepfileInput),
          ImmutableSortedSet.of(depfileInput),
          pipelineStateFactory,
          PipelineType.MIDDLE);
  buildRule =
      new InitializableFromDiskRule(
          BUILD_TARGET,
          filesystem,
          dependency,
          ImmutableSortedSet.of(depfileInput, nonDepfileInput),
          ImmutableSortedSet.of(depfileInput),
          pipelineStateFactory,
          pipelineType);
  dependent =
      new InitializableFromDiskRule(
          BUILD_TARGET.withFlavors(InternalFlavor.of("parent")),
          filesystem,
          buildRule,
          ImmutableSortedSet.of(depfileInput, nonDepfileInput),
          ImmutableSortedSet.of(depfileInput),
          pipelineStateFactory,
          PipelineType.MIDDLE);
  graphBuilder.addToIndex(dependency);
  graphBuilder.addToIndex(buildRule);
  graphBuilder.addToIndex(dependent);
  reset();
}
 
Example 8
Source File: Configs.java    From buck with Apache License 2.0 5 votes vote down vote up
private static ImmutableSortedSet<Path> listFiles(Path root) throws IOException {
  if (!Files.isDirectory(root)) {
    return ImmutableSortedSet.of();
  }
  try (DirectoryStream<Path> directory = Files.newDirectoryStream(root)) {
    return ImmutableSortedSet.<Path>naturalOrder().addAll(directory.iterator()).build();
  }
}
 
Example 9
Source File: IjProjectSourcePathResolver.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Resolve the default output path for the given targetSourcePath, returning a sourcepath pointing
 * to the output.
 */
@Override
protected ImmutableSortedSet<SourcePath> resolveDefaultBuildTargetSourcePath(
    DefaultBuildTargetSourcePath targetSourcePath) {
  BuildTarget target = targetSourcePath.getTarget();
  TargetNode<?> targetNode = targetGraph.get(target);
  Optional<Path> outputPath =
      getOutputPathForTargetNode(targetNode, targetSourcePath.getTargetWithOutputs());
  return ImmutableSortedSet.of(
      PathSourcePath.of(
          targetNode.getFilesystem(),
          outputPath.orElseThrow(
              () -> new HumanReadableException("No known output for: %s", target))));
}
 
Example 10
Source File: Interface.java    From batfish with Apache License 2.0 5 votes vote down vote up
public Interface(String name, CiscoConfiguration c) {
  _active = true;
  _autoState = true;
  _declaredNames = ImmutableSortedSet.of();
  _dhcpRelayAddresses = new TreeSet<>();
  _hsrpGroups = new TreeMap<>();
  _isisInterfaceMode = IsisInterfaceMode.UNSET;
  _memberInterfaces = new HashSet<>();
  _name = name;
  _secondaryAddresses = new LinkedHashSet<>();
  ConfigurationFormat vendor = c.getVendor();

  // Proxy-ARP defaults
  switch (vendor) {
    case CISCO_ASA:
    case CISCO_IOS:
      setProxyArp(true);
      break;

      // $CASES-OMITTED$
    default:
      break;
  }

  // Switchport defaults
  _switchportMode = SwitchportMode.NONE;
  _switchport = false;
  _spanningTreePortfast = c.getSpanningTreePortfastDefault();
}
 
Example 11
Source File: AndroidLibraryGraphEnhancerTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testDummyRDotJavaRuleInheritsJavacOptionsDepsAndNoOthers() {
  ActionGraphBuilder graphBuilder = new TestActionGraphBuilder();
  FakeBuildRule javacDep = new FakeJavaLibrary(BuildTargetFactory.newInstance("//:javac_dep"));
  graphBuilder.addToIndex(javacDep);
  FakeBuildRule dep = new FakeJavaLibrary(BuildTargetFactory.newInstance("//:dep"));
  graphBuilder.addToIndex(dep);
  JavaBuckConfig javaConfig =
      FakeBuckConfig.builder()
          .setSections(ImmutableMap.of("tools", ImmutableMap.of("javac_jar", "//:javac_dep")))
          .build()
          .getView(JavaBuckConfig.class);
  BuildTarget target = BuildTargetFactory.newInstance("//:rule");
  JavacOptions options =
      JavacOptions.builder()
          .setLanguageLevelOptions(
              JavacLanguageLevelOptions.builder().setSourceLevel("5").setTargetLevel("5").build())
          .build();
  AndroidLibraryGraphEnhancer graphEnhancer =
      new AndroidLibraryGraphEnhancer(
          target,
          new FakeProjectFilesystem(),
          ImmutableSortedSet.of(dep),
          JavacFactoryHelper.createJavacFactory(javaConfig)
              .create(graphBuilder, null, UnconfiguredTargetConfiguration.INSTANCE),
          options,
          DependencyMode.FIRST_ORDER,
          /* forceFinalResourceIds */ false,
          /* unionPackage */ Optional.empty(),
          /* rName */ Optional.empty(),
          /* useOldStyleableFormat */ false,
          /* skipNonUnionRDotJava */ false);
  Optional<DummyRDotJava> result =
      graphEnhancer.getBuildableForAndroidResources(
          graphBuilder, /* createdBuildableIfEmptyDeps */ true);
  assertTrue(result.isPresent());
  assertThat(result.get().getBuildDeps(), Matchers.contains(javacDep));
}
 
Example 12
Source File: Layer3EdgeTest.java    From batfish with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonSerialization() {
  Layer3Edge layer3Edge =
      new Layer3Edge(
          NodeInterfacePair.of("node1", "interface1"),
          NodeInterfacePair.of("node2", "interface2"),
          ImmutableSortedSet.of(ConcreteInterfaceAddress.create(Ip.parse("1.1.1.1"), 32)),
          ImmutableSortedSet.of(ConcreteInterfaceAddress.create(Ip.parse("2.2.2.2"), 32)));

  assertThat(BatfishObjectMapper.clone(layer3Edge, Layer3Edge.class), equalTo(layer3Edge));
}
 
Example 13
Source File: EmptyCommunitySetExpr.java    From batfish with Apache License 2.0 4 votes vote down vote up
/**
 * When treated as a literal set of communities, {@link EmptyCommunitySetExpr} represents the
 * empty-set.
 */
@Nonnull
@Override
public SortedSet<Community> asLiteralCommunities(@Nonnull Environment environment) {
  return ImmutableSortedSet.of();
}
 
Example 14
Source File: ImmutableUtils.java    From AppTroy with Apache License 2.0 4 votes vote down vote up
@Nonnull public static <T> ImmutableSortedSet<T> nullToEmptySortedSet(@Nullable ImmutableSortedSet<T> set) {
    if (set == null) {
        return ImmutableSortedSet.of();
    }
    return set;
}
 
Example 15
Source File: ActionExecutionStepTest.java    From buck with Apache License 2.0 4 votes vote down vote up
@Test
public void deletesExistingOutputsOnDiskBeforeExecuting() throws IOException {
  ProjectFilesystem projectFilesystem =
      TestProjectFilesystems.createProjectFilesystem(tmp.getRoot());

  Path baseCell = Paths.get("cell");
  Path output = Paths.get("somepath");
  BuckEventBus testEventBus = BuckEventBusForTests.newInstance();
  BuildTarget buildTarget = BuildTargetFactory.newInstance("//my:foo");

  ActionExecutionResult.ActionExecutionFailure result =
      ActionExecutionResult.failure(
          Optional.empty(), Optional.of("my std err"), ImmutableList.of(), Optional.empty());

  ActionRegistryForTests actionFactoryForTests = new ActionRegistryForTests(buildTarget);
  Artifact declaredArtifact = actionFactoryForTests.declareArtifact(output);
  FakeAction action =
      new FakeAction(
          actionFactoryForTests,
          ImmutableSortedSet.of(),
          ImmutableSortedSet.of(),
          ImmutableSortedSet.of(declaredArtifact),
          (srcs, inputs, outputs, ctx) -> result);

  ActionExecutionStep step =
      new ActionExecutionStep(action, new ArtifactFilesystem(projectFilesystem));

  Path expectedPath = BuildPaths.getGenDir(projectFilesystem, buildTarget).resolve(output);

  projectFilesystem.mkdirs(expectedPath.getParent());
  projectFilesystem.writeContentsToPath("contents", expectedPath);

  assertTrue(projectFilesystem.exists(expectedPath));
  assertEquals(
      StepExecutionResult.builder().setExitCode(-1).setStderr(Optional.of("my std err")).build(),
      step.execute(
          ExecutionContext.builder()
              .setConsole(Console.createNullConsole())
              .setBuckEventBus(testEventBus)
              .setPlatform(Platform.UNKNOWN)
              .setEnvironment(ImmutableMap.of())
              .setJavaPackageFinder(new FakeJavaPackageFinder())
              .setExecutors(ImmutableMap.of())
              .setCellPathResolver(TestCellPathResolver.get(projectFilesystem))
              .setCells(new TestCellBuilder().setFilesystem(projectFilesystem).build())
              .setBuildCellRootPath(baseCell)
              .setProcessExecutor(new FakeProcessExecutor())
              .setProjectFilesystemFactory(new FakeProjectFilesystemFactory())
              .build()));
  assertFalse("file must exist: " + expectedPath, projectFilesystem.exists(expectedPath));
}
 
Example 16
Source File: CompilerParameters.java    From buck with Apache License 2.0 4 votes vote down vote up
@Value.Default
public ImmutableSortedSet<Path> getSourceFilePaths() {
  return ImmutableSortedSet.of();
}
 
Example 17
Source File: RuleWithSupplementaryOutput.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public SortedSet<BuildRule> getBuildDeps() {
  return ImmutableSortedSet.of();
}
 
Example 18
Source File: RegionTest.java    From batfish with Apache License 2.0 4 votes vote down vote up
@Test
public void testAddPrefixListAddressBook() {
  PrefixList plist1 =
      new PrefixList("plist1", ImmutableList.of(Prefix.parse("1.1.1.0/24")), "plist1Name");
  PrefixList plist2 =
      new PrefixList("plist2", ImmutableList.of(Prefix.parse("2.2.2.2/32")), "plist2Name");
  Region region =
      Region.builder("r")
          .setPrefixLists(ImmutableMap.of(plist1.getId(), plist1, plist2.getId(), plist2))
          .build();

  String bookName =
      GeneratedRefBookUtils.getName(AWS_SERVICES_GATEWAY_NODE_NAME, BookType.AwsSeviceIps);

  AddressGroup currentAddressGroup =
      new AddressGroup(ImmutableSortedSet.of("3.3.3.3"), "current");

  ConvertedConfiguration viConfigs = new ConvertedConfiguration();
  Configuration awsServicesNode = newAwsConfiguration(AWS_SERVICES_GATEWAY_NODE_NAME, "aws");
  awsServicesNode
      .getGeneratedReferenceBooks()
      .put(
          bookName,
          ReferenceBook.builder(bookName)
              .setAddressGroups(ImmutableList.of(currentAddressGroup))
              .build());
  viConfigs.addNode(awsServicesNode);

  region.addPrefixListReferenceBook(viConfigs, new Warnings());

  assertThat(
      awsServicesNode.getGeneratedReferenceBooks().get(bookName),
      equalTo(
          ReferenceBook.builder(bookName)
              .setAddressGroups(
                  ImmutableList.of(
                      new AddressGroup(
                          // .1 address is picked for 1.1.1.0/24
                          ImmutableSortedSet.of("1.1.1.1"), plist1.getPrefixListName()),
                      new AddressGroup(
                          // the first and only address is picked for 2.2.2.2
                          ImmutableSortedSet.of("2.2.2.2"), plist2.getPrefixListName()),
                      // the original address group is still present
                      currentAddressGroup))
              .build()));
}
 
Example 19
Source File: BuildCommandErrorsIntegrationTest.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public SortedSet<BuildRule> getBuildDeps() {
  return ImmutableSortedSet.of();
}
 
Example 20
Source File: MultiCurrencyAmount.java    From Strata with Apache License 2.0 2 votes vote down vote up
/**
 * Obtains an instance from a currency and amount.
 * 
 * @param currency  the currency
 * @param amount  the amount
 * @return the amount
 */
public static MultiCurrencyAmount of(Currency currency, double amount) {
  ArgChecker.notNull(currency, "currency");
  return new MultiCurrencyAmount(ImmutableSortedSet.of(CurrencyAmount.of(currency, amount)));
}