org.opencastproject.util.data.Option.bind()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(3.6k)|赞(0)|评价(0)|浏览(77)

本文整理了Java中org.opencastproject.util.data.Option.bind()方法的一些代码示例,展示了Option.bind()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.bind()方法的具体详情如下:
包路径:org.opencastproject.util.data.Option
类名称:Option
方法名:bind

Option.bind介绍

[英]Monadic bind operation m a -> (a -> m b) -> m b.
[中]一元绑定操作m a -> (a -> m b) -> m b

代码示例

代码示例来源:origin: opencast/opencast

@Override
 public Option<B> apply(Option<A> a) {
  return a.bind(f);
 }
};

代码示例来源:origin: opencast/opencast

/** @see org.opencastproject.util.data.functions.Functions#bind(Function) */
public <B> Option<B> flatMap(Function<A, Option<B>> f) {
 return bind(f);
}

代码示例来源:origin: opencast/opencast

/**
 * Get an optional, non-blank value from the <em>bundle</em> context.
 *
 * @throws RuntimeException
 *           key does not exist or its value is blank
 */
public static Option<String> getOptContextProperty(ComponentContext cc, String key) {
 return option(cc.getBundleContext().getProperty(key)).bind(Strings.trimToNone);
}

代码示例来源:origin: opencast/opencast

/** m (m a) -&gt; m a */
public static <A> Option<A> join(Option<Option<A>> a) {
 return a.bind(Functions.<Option<A>> identity());
}

代码示例来源:origin: opencast/opencast

/** Get a value from a dictionary. Return none if the key does either not exist or the value is blank. */
public static Option<Integer> getOptCfgAsInt(Dictionary d, String key) {
 return option(d.get(key)).bind(Strings.asString()).bind(Strings.toInt);
}

代码示例来源:origin: opencast/opencast

/** Get a value from a dictionary. Return none if the key does either not exist or the value is blank. */
public static Option<String> getOptCfg(Dictionary d, String key) {
 return option(d.get(key)).bind(Strings.asString()).bind(Strings.trimToNone);
}

代码示例来源:origin: opencast/opencast

/** OSGi callback */
public void activate(ComponentContext cc) {
 host = option(getContextProperty(cc, OpencastConstants.SERVER_URL_PROPERTY)).bind(Strings.trimToNone).getOrElse(
     UrlSupport.DEFAULT_BASE_URL);
 for (BundleInfoDb a : db)
  a.clear(host);
 cc.getBundleContext().addBundleListener(this);
 for (Bundle b : cc.getBundleContext().getBundles()) {
  logBundle(b);
 }
}

代码示例来源:origin: opencast/opencast

/**
 * Get an optional boolean from a dictionary.
 */
public static Option<Boolean> getOptCfgAsBoolean(Dictionary d, String key) {
 return option(d.get(key)).bind(Strings.asString()).map(Strings.toBool);
}

代码示例来源:origin: opencast/opencast

@Override
public WorkflowOperationResult start(WorkflowInstance wi, JobContext ctx) throws WorkflowOperationException {
 final WorkflowOperationInstance woi = wi.getCurrentOperation();
 final int code = option(woi.getConfiguration(OPT_CODE)).bind(Strings.toInt).getOrElse(1);
 final Severity severity = option(woi.getConfiguration(OPT_SEVERITY)).bind(parseEnum(Severity.FAILURE)).getOrElse(Severity.INFO);
 final List<Tuple<String, String>> details = Arrays.stream(ArrayUtils.nullToEmpty(
     StringUtils.split(woi.getConfiguration(OPT_DETAILS), ";")))
     .map((opt) -> opt.split("="))
     .filter((t) -> t.length == 2)
     .map((x) -> Tuple.tuple(x[0], x[1]))
     .collect(Collectors.toList());
 final Map<String, String> params = Arrays.stream(ArrayUtils.nullToEmpty(
     StringUtils.split(woi.getConfiguration(OPT_PARAMS), ";")))
     .map((opt) -> opt.split("="))
     .filter((t) -> t.length == 2)
     .collect(Collectors.toMap(x -> x[0], x -> x[1]));
 log.info("Create nop job");
 final Job job = nopService.nop();
 log.info("Log a dummy incident with code %d", code);
 serviceRegistry.incident().record(job, severity, code, params, details);
 if (!waitForStatus(job).isSuccess()) {
  throw new WorkflowOperationException("Job did not complete successfully");
 } else {
  return createResult(WorkflowOperationResult.Action.CONTINUE);
 }
}

相关文章