Java Code Examples for com.google.common.base.Optional#transform()

The following examples show how to use com.google.common.base.Optional#transform() . 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: CollaborationHelper.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public Optional<Wiki> getWiki(String entityId) throws NamespaceException {
  NameSpaceContainer container = validateEntity(entityId);

  Optional<CollaborationWiki> wiki = wikiStore.getLatestWikiForEntityId(entityId);

  if (!wiki.isPresent()) {
    // check if container has a description and migrate it.
    String description = getDescription(container);

    if (description != null) {
      setWiki(entityId, new Wiki(description, null));
      wiki = wikiStore.getLatestWikiForEntityId(entityId);
    }
  }

  return wiki.transform(Wiki::fromCollaborationWiki);
}
 
Example 2
Source File: BqOperatorFactory.java    From digdag with Apache License 2.0 5 votes vote down vote up
@Override
protected JobConfiguration jobConfiguration(String projectId)
{
    JobConfigurationQuery cfg = new JobConfigurationQuery()
            .setQuery(query);

    cfg.setUseLegacySql(params.get("use_legacy_sql", boolean.class, false));

    params.getOptional("allow_large_results", boolean.class).transform(cfg::setAllowLargeResults);
    params.getOptional("use_query_cache", Boolean.class).transform(cfg::setUseQueryCache);
    params.getOptional("create_disposition", String.class).transform(cfg::setCreateDisposition);
    params.getOptional("write_disposition", String.class).transform(cfg::setWriteDisposition);
    params.getOptional("flatten_results", Boolean.class).transform(cfg::setFlattenResults);
    params.getOptional("maximum_billing_tier", Integer.class).transform(cfg::setMaximumBillingTier);
    params.getOptional("priority", String.class).transform(cfg::setPriority);

    params.getOptional("table_definitions", new TypeReference<Map<String, ExternalDataConfiguration>>() {})
            .transform(cfg::setTableDefinitions);
    params.getOptional("user_defined_function_resources", new TypeReference<List<UserDefinedFunctionResource>>() {})
            .transform(cfg::setUserDefinedFunctionResources);

    Optional<DatasetReference> defaultDataset = params.getOptional("dataset", String.class)
            .transform(Bq::datasetReference);
    defaultDataset.transform(cfg::setDefaultDataset);

    params.getOptional("destination_table", String.class)
            .transform(s -> cfg.setDestinationTable(tableReference(projectId, defaultDataset, s)));

    return new JobConfiguration()
            .setQuery(cfg);
}
 
Example 3
Source File: Instrumented.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link com.codahale.metrics.Timer.Context} only if {@link org.apache.gobblin.metrics.MetricContext} is defined.
 * @param context an Optional&lt;{@link org.apache.gobblin.metrics.MetricContext}$gt;
 * @param name name of the timer.
 * @return an Optional&lt;{@link com.codahale.metrics.Timer.Context}$gt;
 */
public static Optional<Timer.Context> timerContext(Optional<MetricContext> context, final String name) {
  return context.transform(new Function<MetricContext, Timer.Context>() {
    @Override
    public Timer.Context apply(@Nonnull MetricContext input) {
      return input.timer(name).time();
    }
  });
}
 
Example 4
Source File: Instrumented.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Ends a {@link com.codahale.metrics.Timer.Context} only if it exists.
 * @param timer an Optional&lt;{@link com.codahale.metrics.Timer.Context}$gt;
 */
public static void endTimer(Optional<Timer.Context> timer) {
  timer.transform(new Function<Timer.Context, Timer.Context>() {
    @Override
    public Timer.Context apply(@Nonnull Timer.Context input) {
      input.close();
      return input;
    }
  });
}
 
Example 5
Source File: Instrumented.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Updates a timer only if it is defined.
 * @param timer an Optional&lt;{@link com.codahale.metrics.Timer}&gt;
 * @param duration
 * @param unit
 */
public static void updateTimer(Optional<Timer> timer, final long duration, final TimeUnit unit) {
  timer.transform(new Function<Timer, Timer>() {
    @Override
    public Timer apply(@Nonnull Timer input) {
      input.update(duration, unit);
      return input;
    }
  });
}
 
Example 6
Source File: Instrumented.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Marks a meter only if it is defined.
 * @param meter an Optional&lt;{@link com.codahale.metrics.Meter}&gt;
 * @param value value to mark
 */
public static void markMeter(Optional<Meter> meter, final long value) {
  meter.transform(new Function<Meter, Meter>() {
    @Override
    public Meter apply(@Nonnull Meter input) {
      input.mark(value);
      return input;
    }
  });
}
 
Example 7
Source File: AndroidFeatureFlagSetProvider.java    From bazel with Apache License 2.0 4 votes vote down vote up
AndroidFeatureFlagSetProvider(Optional<? extends Map<Label, String>> flags) {
  super(PROVIDER);
  this.flags = flags.transform(ImmutableMap::copyOf);
}
 
Example 8
Source File: AndroidFeatureFlagSetProvider.java    From bazel with Apache License 2.0 4 votes vote down vote up
public static AndroidFeatureFlagSetProvider create(Optional<? extends Map<Label, String>> flags) {
  return new AndroidFeatureFlagSetProvider(flags.transform(ImmutableMap::copyOf));
}
 
Example 9
Source File: StoredAsJsonBean.java    From Rosetta with Apache License 2.0 4 votes vote down vote up
public void setOptionalTypeInfoField(Optional<? extends StoredAsJsonTypeInfoBean> optionalTypeInfoField) {
  this.optionalTypeInfoField = optionalTypeInfoField.transform(CAST_TO_SUPER);
}
 
Example 10
Source File: StoredAsJsonBean.java    From Rosetta with Apache License 2.0 4 votes vote down vote up
public void setOptionalTypeInfoGetter(Optional<? extends StoredAsJsonTypeInfoBean> optionalTypeInfoGetter) {
  this.optionalTypeInfoGetter = optionalTypeInfoGetter.transform(CAST_TO_SUPER);
}
 
Example 11
Source File: StoredAsJsonBean.java    From Rosetta with Apache License 2.0 4 votes vote down vote up
@StoredAsJson
public void setOptionalTypeInfoSetter(Optional<? extends StoredAsJsonTypeInfoBean> optionalTypeInfoSetter) {
  this.optionalTypeInfoSetter = optionalTypeInfoSetter.transform(CAST_TO_SUPER);
}
 
Example 12
Source File: Routines.java    From immutables with Apache License 2.0 4 votes vote down vote up
public static <T> Optional<List<T>> immutableCopyOf(Optional<? extends List<T>> list) {
  return list.transform(ImmutableList::copyOf);
}
 
Example 13
Source File: CollaborationHelper.java    From dremio-oss with Apache License 2.0 3 votes vote down vote up
public Optional<Tags> getTags(String entityId) throws NamespaceException {
  validateEntityForTag(entityId);

  final Optional<CollaborationTag> tags = tagsStore.getTagsForEntityId(entityId);

  return tags.transform(Tags::fromCollaborationTag);
}