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

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

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

Option.getOrElse介绍

[英]Get the contained value in case of being "some" or return parameter none otherwise.
[中]如果是“some”,则获取包含的值,否则返回参数none

代码示例

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

@Override public A apply(Option<A> as) {
  return as.getOrElse(none);
 }
};

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

@Override
 public A apply(Option<A> ao) {
  return ao.getOrElse(a);
 }
};

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

public StandAloneTrustedHttpClientImpl(String user, String pass, Option<Integer> nonceTimeoutRetries,
                    Option<Integer> retryBaseDelay, Option<Integer> retryMaximumVariableTime) {
 this.user = user;
 this.pass = pass;
 this.nonceTimeoutRetries = nonceTimeoutRetries.getOrElse(DEFAULT_NONCE_TIMEOUT_RETRIES);
 this.retryBaseDelay = retryBaseDelay.getOrElse(DEFAULT_RETRY_BASE_DELAY);
 this.retryMaximumVariableTime = retryMaximumVariableTime.getOrElse(DEFAULT_RETRY_MAXIMUM_VARIABLE_TIME);
}

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

@Override
public T marshal(Option<T> option) throws Exception {
 return option.getOrElse((T) null);
}

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

Transactional currentTx() {
 return emStore.get().getOrElse(startTx);
}

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

/** Create a property. Passing none is like setting {@link #ZERO_VAL} which erases the property. */
public static Prop p(String key, Option<Val> val) {
 return new Prop(key, val.getOrElse(ZERO_VAL));
}

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

/**
 * Returns an expression to search for any date that lies in between <code>startDate</code> and <code>endDate</code>.
 *
 * @param startDate
 *          the start date or none for an infinite left endpoint, "*" in solr query syntax
 * @param endDate
 *          the end date or none for an infinite right endpoint, "*" in solr query syntax
 * @return the serialized search expression
 */
public static String serializeDateRange(Option<Date> startDate, Option<Date> endDate) {
 final Function<Date, String> f = format(newSolrDateFormat());
 return new StringBuilder("[")
     .append(startDate.map(f).getOrElse("*"))
     .append(" TO ")
     .append(endDate.map(f).getOrElse("*"))
     .append("]")
     .toString();
}

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

@Override public String getPrefix(final String uri) {
 return option(b.getPrefix(uri)).getOrElse(new Function0<String>() {
  @Override public String apply() {
   return a.getPrefix(uri);
  }
 });
}

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

/** Evaluate the xpath expression against the contained document. The expression must return a list of strings (text). */
 // todo replace return type with Valid once it is implemented
 public List<String> strings(String expr) {
  final List<String> list = new ArrayList<String>();
  return nodeSet(expr).map(new Function<NodeList, List<String>>() {
   @Override
   public List<String> apply(NodeList nodes) {
    for (int i = 0; i < nodes.getLength(); i++) {
     list.add(nodes.item(i).getNodeValue());
    }
    return list;
   }
  }).getOrElse(list);
 }
}

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

/**
 * OSGI activate method.
 *
 * @param cc
 *          OSGI component context
 **/
public void activate(ComponentContext cc) {
 acceptJobLoadsExeedingMaxLoad = getOptContextProperty(cc, ACCEPT_JOB_LOADS_EXCEEDING_PROPERTY).map(Strings.toBool)
     .getOrElse(DEFAULT_ACCEPT_JOB_LOADS_EXCEEDING);
}

代码示例来源: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

/**
 * Return the endpoint's server URL and the service path by extracting the relevant parameters from the
 * ComponentContext.
 *
 * @param cc
 *          ComponentContext to get configuration from
 * @param serverUrlKey
 *          Configuration key for the server URL
 * @param servicePathKey
 *          Configuration key for the service path
 * @return (serverUrl, servicePath)
 * @throws Error
 *           if the service path is not configured for this component
 */
public static Tuple<String, String> getEndpointUrl(ComponentContext cc, String serverUrlKey, String servicePathKey) {
 final String serverUrl = option(cc.getBundleContext().getProperty(serverUrlKey)).getOrElse(
     UrlSupport.DEFAULT_BASE_URL);
 final String servicePath = option((String) cc.getProperties().get(servicePathKey)).getOrElse(
     Option.<String> error(RestConstants.SERVICE_PATH_PROPERTY + " property not configured"));
 return tuple(serverUrl, servicePath);
}

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

private void logBundle(final Bundle bundle) {
  final BundleInfo info = bundleInfo(host, bundle.getSymbolicName(), bundle.getBundleId(), bundle.getVersion()
      .toString(), getBuildNumber(bundle));
  final String log = String.format("Bundle %s, id %d, version %s, build number %s", info.getBundleSymbolicName(),
      info.getBundleId(), info.getBundleVersion(), info.getBuildNumber().getOrElse("n/a"));
  logger.info(log);
  for (BundleInfoDb a : db)
   a.store(info);
 }
}

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

/**
 * OSGI callback for activating this component
 *
 * @param cc
 *          the osgi component context
 */
public void activate(ComponentContext cc) throws ConfigurationException {
 logger.info("Static File REST Service started.");
 serverUrl = OsgiUtil.getContextProperty(cc, OpencastConstants.SERVER_URL_PROPERTY);
 useWebserver = BooleanUtils.toBoolean(OsgiUtil.getOptCfg(cc.getProperties(), STATICFILES_WEBSERVER_ENABLED_KEY)
     .getOrElse("false"));
 webserverURL = OsgiUtil.getOptCfg(cc.getProperties(), STATICFILES_WEBSERVER_URL_KEY);
 Option<String> cfgMaxUploadSize = OsgiUtil.getOptContextProperty(cc, STATICFILES_UPLOAD_MAX_SIZE_KEY);
 if (cfgMaxUploadSize.isSome())
  maxUploadSize = Long.parseLong(cfgMaxUploadSize.get());
}

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

.getOrElse(DEFAULT_ACCEPT_JOB_LOADS_EXCEEDING);

代码示例来源: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);
 }
}

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

/**
 * Basic sanity checking for media packages.
 *
 * <pre>
 * // media package is ok
 * sanityCheck(mp).isNone()
 * </pre>
 *
 * @return none if the media package is a healthy condition, some([error_msgs]) otherwise
 */
public static Option<List<String>> sanityCheck(MediaPackage mp) {
 final Option<List<String>> errors = sequenceOpt(list(toOption(mp.getIdentifier() != null, "no ID"),
     toOption(mp.getIdentifier() != null && isNotBlank(mp.getIdentifier().toString()), "blank ID")));
 return errors.getOrElse(NIL).size() == 0 ? Option.<List<String>> none() : errors;
}

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

@Override
public IncidentL10n getLocalization(long id, Locale locale) throws IncidentServiceException, NotFoundException {
 final Incident incident = getIncident(id);
 final List<String> loc = localeToList(locale);
 // check if cache map is empty
 // fill cache from
 final String title = findText(loc, incident.getCode(), FIELD_TITLE).getOrElse(NO_TITLE);
 final String description = findText(loc, incident.getCode(), FIELD_DESCRIPTION).map(
     replaceVarsF(incident.getDescriptionParameters())).getOrElse(NO_DESCRIPTION);
 return new IncidentL10n() {
  @Override
  public String getTitle() {
   return title;
  }
  @Override
  public String getDescription() {
   return description;
  }
 };
}

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

case Analyze:
 audioTrack = (TrackImpl) MediaPackageElementParser.getFromXml(arguments.get(0));
 serialized = analyze(job, audioTrack).map(MediaPackageElementParser.<Track> getAsXml()).getOrElse("");
 break;
case Normalize:
 Float targetRmsLevDb = new Float(arguments.get(1));
 serialized = normalize(job, audioTrack, targetRmsLevDb).map(MediaPackageElementParser.<Track> getAsXml())
     .getOrElse("");
 break;
default:

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

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.metadata.api.MetadataService#getMetadata(org.opencastproject.mediapackage.MediaPackage)
 */
@Override
public StaticMetadata getMetadata(final MediaPackage mp) {
 return mlist(list(mp.getCatalogs(DublinCoreCatalog.ANY_DUBLINCORE)))
     .find(flavorPredicate(MediaPackageElements.EPISODE))
     .flatMap(loader)
     .map(new Function<DublinCoreCatalog, StaticMetadata>() {
      @Override
      public StaticMetadata apply(DublinCoreCatalog episode) {
       return newStaticMetadataFromEpisode(episode);
      }
     })
     .getOrElse((StaticMetadata) null);
}

相关文章