public static ResourceHints fromOptions(PipelineOptions options) {
    ResourceHintsOptions resourceHintsOptions = options.as(ResourceHintsOptions.class);
    ResourceHints result = create();
    List<String> hints = resourceHintsOptions.getResourceHints();
    Splitter splitter = Splitter.on('=').limit(2);
    for (String hint : hints) {
      List<String> parts = splitter.splitToList(hint);
      if (parts.size() != 2) {
        throw new IllegalArgumentException("Unparsable resource hint: " + hint);
      }
      String nameOrUrn = parts.get(0);
      String stringValue = parts.get(1);
      String urn;
      if (hintNameToUrn.containsKey(nameOrUrn)) {
        urn = hintNameToUrn.get(nameOrUrn);
      } else if (!nameOrUrn.startsWith("beam:resources:")) {
        // Allow unknown hints to be passed, but validate a little bit to prevent typos.
        throw new IllegalArgumentException("Unknown resource hint: " + hint);
      } else {
        urn = nameOrUrn;
      }
      ResourceHint value =
          Preconditions.checkNotNull(parsers.getOrDefault(urn, StringHint::new)).apply(stringValue);
      result = result.withHint(urn, value);
    }
    return result;
  }
@Test
  public void testFromOptions() {
    ResourceHintsOptions options =
        PipelineOptionsFactory.fromArgs(
                "--resourceHints=minRam=1KB", "--resourceHints=beam:resources:bar=foo")
            .as(ResourceHintsOptions.class);
    assertEquals(
        ResourceHints.fromOptions(options),
        ResourceHints.create()
            .withMinRam(1000)
            .withHint("beam:resources:bar", new ResourceHints.StringHint("foo")));
    options =
        PipelineOptionsFactory.fromArgs(
                "--resourceHints=min_ram=1KB",
                "--resourceHints=accelerator=foo",
                "--resourceHints=cpu_count=4")
            .as(ResourceHintsOptions.class);
    ResourceHints fromOptions = ResourceHints.fromOptions(options);
    ResourceHints expect =
        ResourceHints.create().withMinRam(1000).withAccelerator("foo").withCPUCount(4);
    assertEquals(fromOptions, expect);
  }