Example usage for com.google.common.base Optional or

List of usage examples for com.google.common.base Optional or

Introduction

In this page you can find the example usage for com.google.common.base Optional or.

Prototype

@Beta
public abstract T or(Supplier<? extends T> supplier);

Source Link

Document

Returns the contained instance if it is present; supplier.get() otherwise.

Usage

From source file:org.apache.aurora.scheduler.reconciliation.TaskReconciler.java

public void triggerExplicitReconciliation(Optional<Integer> batchSize) {
    doExplicitReconcile(batchSize.or(settings.explicitBatchSize));
}

From source file:springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper.java

private Path mapOperations(ApiDescription api, Optional<Path> existingPath) {
    Path path = existingPath.or(new Path());
    for (springfox.documentation.service.Operation each : nullToEmptyList(api.getOperations())) {
        Operation operation = mapOperation(each);
        path.set(each.getMethod().toString().toLowerCase(), operation);
    }/*  w w  w  . jav a2 s  .  c o m*/
    return path;
}

From source file:google.registry.rde.imports.RdeContactInput.java

/**
 * Creates a new {@link RdeContactInput}
 *
 * @param mapShards Number of readers that should be created
 * @param importBucketName Name of GCS bucket for escrow file imports
 * @param importFileName Name of escrow file in GCS
 *///  w  w w  .j a  v a 2  s  .c  o m
public RdeContactInput(Optional<Integer> mapShards, String importBucketName, String importFileName) {
    this.numReaders = mapShards.or(DEFAULT_READERS);
    this.importBucketName = importBucketName;
    this.importFileName = importFileName;
}

From source file:com.addthis.hydra.job.web.resources.TaskResource.java

@GET
@Path("/start")
@Produces(MediaType.APPLICATION_JSON)/*from  w  w w .  j a v a2s.c  om*/
public Response startTask(@QueryParam("job") Optional<String> jobId, @QueryParam("task") Optional<Integer> task,
        @QueryParam("priority") Optional<Integer> priority) {
    try {
        int bonusPriority = priority.or(0);
        // if there is any bonus priority, go ahead and let this task jump to the head of its queue (break ties)
        spawn.startTask(jobId.or(""), task.or(-1), bonusPriority, bonusPriority > 0);
        return Response.ok().build();
    } catch (Exception ex) {
        return Response.serverError().entity(ex.getMessage()).build();
    }
}

From source file:google.registry.rde.imports.RdeHostInput.java

/**
 * Creates a new {@link RdeHostInput}/*  w  w w . j  av a2 s .  c  om*/
 *
 * @param mapShards Number of readers that should be created
 * @param importBucketName Name of GCS bucket for escrow file imports
 * @param importFileName Name of escrow file in GCS
 */
public RdeHostInput(Optional<Integer> mapShards, String importBucketName, String importFileName) {
    this.numReaders = mapShards.or(DEFAULT_READERS);
    checkArgument(numReaders > 0, "Number of shards must be greater than zero");
    this.importBucketName = importBucketName;
    this.importFileName = importFileName;
}

From source file:org.apache.gobblin.runtime.scheduler.AbstractJobSpecScheduler.java

public AbstractJobSpecScheduler(Optional<Logger> log) {
    _log = log.or(LoggerFactory.getLogger(getClass()));
    _callbacksDispatcher = new JobSpecSchedulerListeners(_log);
}

From source file:nebula.plugin.metrics.dispatcher.ClientESMetricsDispatcher.java

@Override
protected String index(String indexName, String type, String source, Optional<String> id) {
    IndexRequestBuilder index = client.prepareIndex(indexName, type).setSource(source);
    index.setId(id.or(UUID.randomUUID().toString()));
    IndexResponse indexResponse = index.execute().actionGet();
    return indexResponse.getId();
}

From source file:com.pinterest.teletraan.resource.HostTypes.java

@GET
public Collection<HostTypeBean> getAll(@QueryParam("pageIndex") Optional<Integer> pageIndex,
        @QueryParam("pageSize") Optional<Integer> pageSize) throws Exception {
    return hostTypeDAO.getAll(pageIndex.or(DEFAULT_INDEX), pageSize.or(DEFAULT_SIZE));
}

From source file:com.pinterest.teletraan.resource.Placements.java

@GET
public Collection<PlacementBean> getAll(@QueryParam("pageIndex") Optional<Integer> pageIndex,
        @QueryParam("pageSize") Optional<Integer> pageSize) throws Exception {
    return placementDAO.getAll(pageIndex.or(DEFAULT_INDEX), pageSize.or(DEFAULT_SIZE));
}

From source file:com.gmail.walles.johan.headsetharry.handlers.SmsPresenter.java

@NonNull
@Override//from www  .ja v  a2  s .  co  m
public Optional<List<TextWithLocale>> getAnnouncement(Intent intent) {
    CharSequence body = Optional.fromNullable(intent.getCharSequenceExtra(EXTRA_BODY)).or("");

    // It's OK for the sender to be null, we'll just say it's unknown
    CharSequence sender = intent.getCharSequenceExtra(EXTRA_SENDER);

    Optional<Locale> smsBodyLocale = identifyLanguage(body);
    Translations translations = new Translations(context, smsBodyLocale.or(Locale.getDefault()), R.string.sms,
            R.string.empty_sms, R.string.unknown_language_sms, R.string.unknown_sender,
            R.string.what_from_where_colon_body);

    String presentableSender;
    if (TextUtils.isEmpty(sender)) {
        presentableSender = translations.getString(R.string.unknown_sender);
    } else {
        presentableSender = LookupUtils.getNameForNumber(context, sender.toString())
                .or(translations.getString(R.string.unknown_sender));
    }

    if (TextUtils.isEmpty(body)) {
        return Optional.of(translations.format(R.string.what_from_where_colon_body,
                translations.getString(R.string.empty_sms), presentableSender, body));
    }

    String sms;
    if (smsBodyLocale.isPresent()) {
        sms = translations.getString(R.string.sms);
    } else {
        sms = translations.getString(R.string.unknown_language_sms);
    }
    return Optional.of(translations.format(R.string.what_from_where_colon_body, sms, presentableSender,
            smsBodyLocale.or(Locale.getDefault()), body));
}