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:com.pinterest.teletraan.resource.SecurityZones.java

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

From source file:org.locationtech.geogig.porcelain.RemoteResolve.java

/**
 * Executes the remote-add operation./*from w w w.  j av  a2 s  .  com*/
 * 
 * @return the {@link Remote} that was added.
 */
@Override
protected Optional<Remote> _call() {
    if (name == null || name.isEmpty()) {
        throw new RemoteException(StatusCode.MISSING_NAME);
    }

    Optional<Remote> result = Optional.absent();

    ConfigDatabase config = configDatabase();
    List<String> allRemotes = config.getAllSubsections("remote");
    if (allRemotes.contains(name)) {

        String remoteSection = "remote." + name;
        Optional<String> remoteFetchURL = config.get(remoteSection + ".url");
        Optional<String> remoteFetch = config.get(remoteSection + ".fetch");
        Optional<String> remoteMapped = config.get(remoteSection + ".mapped");
        Optional<String> remoteMappedBranch = config.get(remoteSection + ".mappedBranch");
        Optional<String> remoteUserName = config.get(remoteSection + ".username");
        Optional<String> remotePassword = config.get(remoteSection + ".password");
        if (remoteFetchURL.isPresent() && remoteFetch.isPresent()) {
            Optional<String> remotePushURL = config.get(remoteSection + ".pushurl");

            Remote remote = new Remote(name, remoteFetchURL.get(), remotePushURL.or(remoteFetchURL.get()),
                    remoteFetch.get(), remoteMapped.or("false").equals("true"), remoteMappedBranch.orNull(),
                    remoteUserName.orNull(), remotePassword.orNull());
            result = Optional.of(remote);
        }
    }
    return result;
}

From source file:org.geogit.api.porcelain.RemoteResolve.java

/**
 * Executes the remote-add operation.//from ww w .j  av a  2 s  .  c o  m
 * 
 * @return the {@link Remote} that was added.
 */
@Override
public Optional<Remote> call() {
    if (name == null || name.isEmpty()) {
        throw new RemoteException(StatusCode.MISSING_NAME);
    }

    Optional<Remote> result = Optional.absent();

    List<String> allRemotes = config.getAllSubsections("remote");
    if (allRemotes.contains(name)) {

        String remoteSection = "remote." + name;
        Optional<String> remoteFetchURL = config.get(remoteSection + ".url");
        Optional<String> remoteFetch = config.get(remoteSection + ".fetch");
        Optional<String> remoteMapped = config.get(remoteSection + ".mapped");
        Optional<String> remoteMappedBranch = config.get(remoteSection + ".mappedBranch");
        if (remoteFetchURL.isPresent() && remoteFetch.isPresent()) {
            Optional<String> remotePushURL = config.get(remoteSection + ".pushurl");

            Remote remote = new Remote(name, remoteFetchURL.get(), remotePushURL.or(remoteFetchURL.get()),
                    remoteFetch.get(), remoteMapped.or("false").equals("true"), remoteMappedBranch.orNull());
            result = Optional.of(remote);
        }
    }
    return result;
}

From source file:com.palantir.atlasdb.cli.command.SweepCommand.java

private String encodeStartRow(Optional<byte[]> rowBytes) {
    return BaseEncoding.base16().encode(rowBytes.or(FIRST_ROW));
}

From source file:com.mycelium.wallet.ClearPinDialog.java

public ClearPinDialog(final Context context, boolean hidden) {
    super(context, hidden, true);
    final MbwManager mbwManager = MbwManager.getInstance(context);

    Button btnForgotPin = (Button) findViewById(R.id.btn_forgot_pin);

    if (mbwManager.getPin().isResettable()) {
        Optional<Integer> resetPinRemainingBlocksCount = mbwManager.getResetPinRemainingBlocksCount();
        if (resetPinRemainingBlocksCount.or(1) == 0) {
            // reset procedure was started and is already old enough -> provide option to reset PIN
            btnForgotPin.setText("Reset PIN now");
            btnForgotPin.setOnClickListener(new View.OnClickListener() {
                @Override//w w w .ja  v  a2s.com
                public void onClick(View v) {
                    mbwManager.savePin(Pin.CLEAR_PIN);
                    if (onPinValid != null)
                        onPinValid.pinEntered(ClearPinDialog.this, Pin.CLEAR_PIN);
                }
            });
        } else if (resetPinRemainingBlocksCount.isPresent()) {
            // reset procedure was started, but the target blockheight isn't reached
            btnForgotPin.setText(String.format(context.getString(R.string.pin_forgotten_reset_wait_button_text),
                    Utils.formatBlockcountAsApproxDuration(this.getContext(),
                            resetPinRemainingBlocksCount.get())));

            btnForgotPin.setEnabled(false);
        } else {
            // no reset procedure was started
            btnForgotPin.setOnClickListener(startResetListener(context, mbwManager));
        }

    } else {
        // The current PIN is not marked as resettable - sorry, you are on your own
        btnForgotPin.setVisibility(View.GONE);
    }

}

From source file:com.spotify.hdfs2cass.cassandra.utils.CassandraClusterInfo.java

public void validateThriftAccessible(final Optional<Integer> rpcPort) {
    Config.setClientMode(true);//from www.ja v a  2s  .  c  om

    int port = rpcPort.or(ConfigHelper.getOutputRpcPort(new Configuration()));

    ExternalSSTableLoaderClient client = new ExternalSSTableLoaderClient(this.host, port, null, null);
    client.init(this.keyspace);
    if (client.getCFMetaData(this.keyspace, this.columnFamily) == null) {
        throw new CrunchRuntimeException(
                "Column family not accessible: " + this.keyspace + "." + this.columnFamily);
    }
}

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

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

From source file:edu.sdsc.scigraph.owlapi.curies.CurieUtil.java

/***
 * Returns the CURIE of an IRI, if mapped.
 * //from   w ww. j a  v a 2 s  .  c om
 * @param iri
 * @return An {@link Optional} CURIE
 */
public Optional<String> getCurie(String iri) {
    checkNotNull(iri);
    Optional<String> candidate = Optional.absent();
    for (String prefix : curieMap.inverse().keySet()) {
        if (iri.startsWith(prefix) && candidate.or("").length() < prefix.length()) {
            candidate = Optional.of(prefix);
        }
    }
    if (candidate.isPresent()) {
        return Optional.of(String.format("%s:%s", curieMap.inverse().get(candidate.get()),
                iri.substring(candidate.get().length(), iri.length())));
    } else {
        return Optional.absent();
    }
}

From source file:com.raskasa.dropwizard.okhttp.samples.ExternalServiceResource.java

@GET
public String sayHello(@QueryParam("name") Optional<String> user) {
    Request request = new Request.Builder()
            .url(String.format("https://api.github.com/users/%s/repos", user.or("dropwizard"))).build();

    try {//from  ww w.  ja  v a 2s. co  m
        final CountDownLatch latch = new CountDownLatch(1);
        final Holder holder = new Holder();
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {
                latch.countDown();
            }

            @Override
            public void onResponse(Response response) throws IOException {
                holder.setResponse(response.body().string());
                latch.countDown();
            }
        });
        latch.await();
        return holder.getResponse();
    } catch (InterruptedException e) {
        return "Error making network request.  Try again?";
    }
}

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

@GET
public List<RatingBean> getAll(@QueryParam("pageIndex") Optional<Integer> pageIndex,
        @QueryParam("pageSize") Optional<Integer> pageSize) throws Exception {
    return ratingsHandler.getRatingDAO().getRatingsInfos(pageIndex.or(DEFAULT_INDEX),
            pageSize.or(DEFAULT_SIZE));//from ww  w .  j  a  v a2s.c  o  m
}