当前位置: 首页>>代码示例>>Java>>正文


Java Optional.or方法代码示例

本文整理汇总了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");
  }
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:17,代码来源:KBP2015Scorer.java

示例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();
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:26,代码来源:ScoreKBPAgainstERE.java

示例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();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:IterableRowEmitter.java

示例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);
}
 
开发者ID:cbooy,项目名称:cakes,代码行数:27,代码来源:OptionalDemo.java

示例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);
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:15,代码来源:AbstractMediaProcessor.java

示例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);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:41,代码来源:IteratorPageDownstream.java

示例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("");
}
 
开发者ID:HotelsDotCom,项目名称:heat,代码行数:11,代码来源:RestAssuredRequestMaker.java

示例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);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:39,代码来源:EasyFormatDatasetAccessor.java

示例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);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:11,代码来源:MultiModelState.java

示例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));
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:6,代码来源:DevtoolsEvent.java

示例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());
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:7,代码来源:MessageAssertionChain.java


注:本文中的com.google.common.base.Optional.or方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。