本文整理了Java中org.opencastproject.util.data.Option
类的一些代码示例,展示了Option
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option
类的具体详情如下:
包路径:org.opencastproject.util.data.Option
类名称:Option
[英]The option type encapsulates on optional value. It contains either some value or is empty. Please make sure to NEVER wrap null into a some. Instead use none.
[中]选项类型封装在可选值上。它要么包含某个值,要么为空。请确保不要将空值包装到some中。取而代之的是不使用。
代码示例来源:origin: opencast/opencast
/** Wrap an arbitrary object into an option with <code>null</code> being mapped to none. */
public static <A> Option<A> option(A a) {
if (a != null)
return some(a);
else
return none();
}
代码示例来源:origin: opencast/opencast
@Override
public Option<Date[]> getTemporalPeriod() {
if (temporalOpt.isSome()) {
if (temporalOpt.get() instanceof DCMIPeriod) {
DCMIPeriod p = (DCMIPeriod) temporalOpt.get();
return option(new Date[] { p.getStart(), p.getEnd() });
}
}
return Option.none();
}
代码示例来源: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
@Override
public Option<Long> getTemporalDuration() {
if (temporalOpt.isSome()) {
if (temporalOpt.get() instanceof Long) {
return temporalOpt;
}
}
return Option.none();
}
代码示例来源:origin: opencast/opencast
/** If this is some return <code>some</code>. Like {@link #map(Function)} but ignores the option's content. */
public <B> Option<B> andThenV(B some) {
return isSome() ? some(some) : Option.<B> none();
}
代码示例来源:origin: opencast/opencast
public <B> Option<Tuple<A, B>> and(Option<B> b) {
if (isSome() && b.isSome()) {
return some(tuple(get(), b.get()));
} else {
return none();
}
}
代码示例来源:origin: opencast/opencast
@Override
public Option<A> apply(A a) {
return option(a);
}
};
代码示例来源:origin: opencast/opencast
/** Evaluate the xpath expression against the contained document. The expression must return a nodelist. */
// todo replace return type with Valid once it is implemented
public Option<NodeList> nodeSet(String expr) {
try {
return option(((NodeList) xpath.evaluate(expr, node, XPathConstants.NODESET)));
} catch (XPathExpressionException e) {
return none();
}
}
代码示例来源: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
/** If this is some return <code>some</code>. Like {@link #bind(Function)} but ignores the option's content. */
public <B> Option<B> andThen(Option<B> some) {
return isSome() ? some : Option.<B> none();
}
代码示例来源: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
/**
* 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
@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
/**
* 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
/**
* 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
/**
* {@inheritDoc}
*
* @see org.opencastproject.workingfilerepository.api.WorkingFileRepository#getTotalSpace()
*/
public Option<Long> getTotalSpace() {
File f = new File(rootDirectory);
return Option.some(f.getTotalSpace());
}
代码示例来源:origin: opencast/opencast
@Override
public boolean equals(Object o) {
if (o instanceof Option) {
Option<?> opt = (Option<?>) o;
// since an Option should NEVER contain any null this is safe
return opt.isSome() && a.equals(opt.get());
} else {
return false;
}
}
代码示例来源: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 A apply(Option<A> ao) {
return ao.getOrElse(a);
}
};
代码示例来源:origin: opencast/opencast
@Override
public Option<String> apply(MediaPackageElement mediaPackageElement) {
return option(mediaPackageElement.getReference()).map(getReferenceId);
}
};
内容来源于网络,如有侵权,请联系作者删除!