本文整理汇总了Java中com.google.common.base.Optional.or方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.or方法的具体用法?Java Optional.or怎么用?Java Optional.or使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.base.Optional
的用法示例。
在下文中一共展示了Optional.or方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: KBP2015Scorer
import com.google.common.base.Optional; //导入方法依赖的package包/类
private KBP2015Scorer(final EALScorer2015Style documentScorer,
Map<String, SimpleResultWriter> resultWriters,
Map<String, BootstrappedResultWriterSource> bootstrappedResultWriters,
Optional<Integer> bootstrapSeed, Optional<Integer> bootstrapSamples) {
this.documentScorer = checkNotNull(documentScorer);
this.resultWriters = ImmutableMap.copyOf(resultWriters);
this.bootstrappedResultWriterSources = ImmutableMap.copyOf(bootstrappedResultWriters);
checkArgument(bootstrapSeed.isPresent() == bootstrapSamples.isPresent(),
"Bootstrapping parameters must both be specified if either is present");
this.doBootstrapping = bootstrapSeed.isPresent();
this.bootstrapSeed = bootstrapSeed.or(-1);
this.numBootstrapSamples = bootstrapSamples.or(0);
if (bootstrapSamples.isPresent()) {
checkArgument(bootstrapSamples.get() > 0, "Num bootstrap samples must be positive");
}
}
示例2: resolveToERE
import com.google.common.base.Optional; //导入方法依赖的package包/类
private DocLevelEventArg resolveToERE(final EREDocument doc, final EREAligner ereAligner,
final Response response) {
numResponses.add(errKey(response));
final Symbol realis = Symbol.from(response.realis().name());
final Optional<ScoringCorefID> alignedCorefIDOpt = ereAligner.argumentForResponse(response);
if (!alignedCorefIDOpt.isPresent()) {
log.info("Alignment failed for {}", response);
mentionAlignmentFailuresB.put(errKey(response), response.toString());
}
// this increments the alignment failure ID regardless of success or failure, but
// we don't care
final ScoringCorefID alignedCorefID = alignedCorefIDOpt.or(
// in case of alignment failure, we make a pseudo-entity from the CAS offsets
// it will always be wrong, but will be consistent for the same extent appearing in
// different event roles
new ScoringCorefID.Builder().scoringEntityType(ScoringEntityType.AlignmentFailure)
.withinTypeID(response.canonicalArgument().charOffsetSpan().asCharOffsetRange().toString())
.build());
return new DocLevelEventArg.Builder().docID(Symbol.from(doc.getDocId()))
.eventType(response.type()).eventArgumentType(response.role())
.corefID(alignedCorefID.globalID()).realis(realis).build();
}
示例3: IterableRowEmitter
import com.google.common.base.Optional; //导入方法依赖的package包/类
public IterableRowEmitter(RowReceiver rowReceiver,
final Iterable<? extends Row> rows,
Optional<Executor> executor) {
this.rowReceiver = rowReceiver;
topRowUpstream = new TopRowUpstream(
executor.or(MoreExecutors.directExecutor()),
this,
new Runnable() {
@Override
public void run() {
rowsIt = rows.iterator();
IterableRowEmitter.this.run();
}
}
);
rowReceiver.setUpstream(topRowUpstream);
this.rowsIt = rows.iterator();
}
示例4: testOr
import com.google.common.base.Optional; //导入方法依赖的package包/类
/**
* or : 返回Optional所包含的引用, 若引用缺失,返回指定的值
*/
@Test
public void testOr() {
String str = "123";
Optional<String> op1 = Optional.fromNullable(str);
// 此时Optional中不为null
String v1 = op1.or("default");
LOGGER.info(v1);
str = null;
op1 = Optional.fromNullable(str);
// 此时Optional中为null,则给or中的默认值
v1 = op1.or("default");
LOGGER.info(v1);
// or中给另一个Optional
Optional<String> op2 = op1.or(Optional.of("hehe"));
String s2 = op2.get();
LOGGER.info(s2);
// or中传一个lambda表达式,消费者
String s3 = op1.or(() -> "hi lambda");
LOGGER.info("s3 = {}", s3);
}
示例5: onMediaEvent
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public void onMediaEvent(MediaEvent event) {
MediaWrapper<?> wrapper = event.getMediaWrapper();
MediaExecutor<?> executor = executors.get(wrapper);
if (executor == null) {
logger.info("media executor is null");
return;
}
Optional<MediaEventController> eventControllerOpt = executor.getBaseMediaConfiguration().getMediaEventControllerOpt();
MediaEventController mediaEventController = eventControllerOpt.or(defaultMediaEventControllerProvider.get());
mediaEventController.onMediaEvent(event, executor, this);
}
示例6: IteratorPageDownstream
import com.google.common.base.Optional; //导入方法依赖的package包/类
public IteratorPageDownstream(final RowReceiver rowReceiver,
final PagingIterator<Void, Row> pagingIterator,
Optional<Executor> executor) {
this.pagingIterator = pagingIterator;
this.executor = executor.or(MoreExecutors.directExecutor());
this.rowReceiver = rowReceiver;
this.topRowUpstream = new TopRowUpstream(
this.executor,
new Runnable() {
@Override
public void run() {
try {
processBuckets(pausedIterator, pausedListener);
} catch (Throwable t) {
fail(t);
pausedListener.finish();
}
}
},
new Runnable() {
@Override
public void run() {
if (finished.compareAndSet(true, false)) {
try {
if (processBuckets(pagingIterator.repeat().iterator(), PageConsumeListener.NO_OP_LISTENER)) {
consumeRemaining();
}
finished.set(true);
rowReceiver.finish();
} catch (Throwable t) {
fail(t);
}
} else {
LOGGER.trace("Received repeat, but wasn't finished");
}
}
}
);
rowReceiver.setUpstream(topRowUpstream);
}
示例7: getRequestDetails
import com.google.common.base.Optional; //导入方法依赖的package包/类
private String getRequestDetails(Method httpMethod, String url) {
Optional<String> requestDetails = Optional.absent();
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
requestDetails = Optional.fromNullable(RequestPrinter.print((FilterableRequestSpecification) requestSpecification, httpMethod.name(), url, LogDetail.ALL,
new PrintStream(os), true));
} catch (IOException e) {
logUtils.error("Unable to log 'Request Details', error occured during retrieving the information");
}
return requestDetails.or("");
}
示例8: getBatchSchema
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public BatchSchema getBatchSchema(final FileSelection selection, final FileSystemWrapper dfs) {
final SabotContext context = formatPlugin.getContext();
try (
BufferAllocator sampleAllocator = context.getAllocator().newChildAllocator("sample-alloc", 0, Long.MAX_VALUE);
OperatorContextImpl operatorContext = new OperatorContextImpl(context.getConfig(), sampleAllocator, context.getOptionManager(), 1000);
SampleMutator mutator = new SampleMutator(context)
){
final ImplicitFilesystemColumnFinder explorer = new ImplicitFilesystemColumnFinder(context.getOptionManager(), dfs, GroupScan.ALL_COLUMNS);
Optional<FileStatus> fileName = Iterables.tryFind(selection.getStatuses(), new Predicate<FileStatus>() {
@Override
public boolean apply(@Nullable FileStatus input) {
return input.getLen() > 0;
}
});
final FileStatus file = fileName.or(selection.getStatuses().get(0));
EasyDatasetSplitXAttr dataset = new EasyDatasetSplitXAttr();
dataset.setStart(0l);
dataset.setLength(Long.MAX_VALUE);
dataset.setPath(file.getPath().toString());
try(RecordReader reader = new AdditionalColumnsRecordReader(((EasyFormatPlugin)formatPlugin).getRecordReader(operatorContext, dfs, dataset, GroupScan.ALL_COLUMNS), explorer.getImplicitFieldsForSample(selection))) {
reader.setup(mutator);
Map<String, ValueVector> fieldVectorMap = new HashMap<>();
for (VectorWrapper<?> vw : mutator.getContainer()) {
fieldVectorMap.put(vw.getField().getName(), vw.getValueVector());
}
reader.allocate(fieldVectorMap);
reader.next();
mutator.getContainer().buildSchema(BatchSchema.SelectionVectorMode.NONE);
return mutator.getContainer().getSchema();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例9: apply
import com.google.common.base.Optional; //导入方法依赖的package包/类
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
{
Optional<TRSRTransformation> normal = state.apply(part);
Optional<TRSRTransformation> multi = state.apply(Optional.of(new PartPart(model, index, part)));
if(normal.isPresent() && multi.isPresent())
{
return Optional.of(normal.get().compose(multi.get()));
}
return normal.or(multi);
}
示例10: fromJson
import com.google.common.base.Optional; //导入方法依赖的package包/类
public static DevtoolsEvent fromJson(JsonObject json) {
String method = json.getString("method");
Optional<JsonObject> params = Optional.fromNullable(json.getJsonObject("params"));
return new AutoValue_DevtoolsEvent(method, params.or(JavaxJson.EMPTY_OBJECT));
}
示例11: append
import com.google.common.base.Optional; //导入方法依赖的package包/类
private Optional<String> append(Optional<String> description, Optional<String> part) {
if (!description.isPresent() || !part.isPresent()) {
return description.or(part);
}
return Optional.of(description.get() + lineSeparator() + part.get());
}