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

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

Introduction

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

Prototype

public abstract boolean isPresent();

Source Link

Document

Returns true if this holder contains a (non-null) instance.

Usage

From source file:org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObjectBuilder.java

private static String maybeAddComment(Optional<String> comment, boolean isJavadoc) {
    if (comment.isPresent()) {
        String input = comment.get();
        return StringUtil.writeComment(input, isJavadoc);
    } else {/*from  w  ww .  ja va 2 s.  co m*/
        return "";
    }
}

From source file:io.crate.planner.Limits.java

public static Optional<Symbol> mergeAdd(Optional<Symbol> s1, Optional<Symbol> s2) {
    if (s1.isPresent()) {
        if (s2.isPresent()) {
            return Optional.of(AddFunction.of(s1.get(), s2.get()));
        }/*from ww  w  .  ja va 2s  .co  m*/
        return s1;
    }
    return s2;
}

From source file:io.urmia.md.model.job.JobGetRequest.java

public static ObjectRequest fromJobGetHttpRequest(String uri) {
    int loc = uri.indexOf("/stor/");
    if (loc <= 0)
        throw new IllegalArgumentException("invalid job get uri: " + uri);

    String path = uri.substring(loc + 5);
    Optional<ObjectName> on = ObjectName.of(path);
    if (!on.isPresent())
        throw new IllegalArgumentException("invalid job get path: " + path);

    return new ObjectRequest(on.get());
}

From source file:org.pau.assetmanager.utils.UserUtil.java

/**
 * @return the current user that is logged in in the application
 * WATCH OUT: To call the method the thread should be running in a servlet container in a ZK environment.
 */// w  w w  .j a v  a  2s  .c  om
public static User getExecutionUser() {
    String username = Executions.getCurrent().getUserPrincipal().getName();
    Optional<User> optionalUser = UsersBusiness.getUserByUsername(username);
    if (optionalUser.isPresent()) {
        return optionalUser.get();
    } else {
        String message = "The execution user with name '" + username + "' does not exist in the database";
        logger.error(message);
        throw new AssetManagerRuntimeException(message);
    }
}

From source file:org.locationtech.geogig.storage.impl.Blobs.java

public static List<String> readLines(Optional<byte[]> blob) {
    List<String> lines = ImmutableList.of();
    if (blob.isPresent()) {
        String contents = new String(blob.get(), Charsets.UTF_8);
        lines = Splitter.on("\n").splitToList(contents);
    }/*  ww  w.  j a  v  a 2s  . c o m*/
    return lines;
}

From source file:com.eucalyptus.auth.euare.EuareRemoteRegionFilter.java

private static boolean isNonLocalRegion(final Optional<RegionInfo> regionInfo) {
    return regionInfo.isPresent()
            && !RegionConfigurations.getRegionName().asSet().contains(regionInfo.get().getName());
}

From source file:org.raml.jaxrs.model.HttpVerb.java

/**
 * Same as {@link #fromString(String)}, but throws if there is no corresponding verb.
 *
 * @param httpMethod the method to pair//from ww  w  . j a v  a 2 s .com
 * @return the corresponding http verb
 * @throws NoSuchElementException if there is no corresponding verb
 */
public static HttpVerb fromStringUnchecked(String httpMethod) {
    Optional<HttpVerb> verb = fromString(httpMethod);

    if (verb.isPresent())
        return verb.get();

    throw new NoSuchElementException(String.format("invalid http method: %s", httpMethod));
}

From source file:org.fabrician.enabler.util.DockerActivationInfo.java

public static DockerActivationInfo inject(final ActivationInfo info, final String containerIdentity,
        final DockerClient client) {
    Optional<Container> c = client.inspectContainer(containerIdentity);
    if (c.isPresent()) {
        DockerActivationInfo.instance(info, c.get()).inject();
    }//from   w  ww  .  ja v a  2 s.c o m
    return DockerActivationInfo.instance(info, null);
}

From source file:org.opendaylight.protocol.bgp.openconfig.impl.openconfig.BGPNeighborProviderImpl.java

private static String getPasswor(final Optional<Rfc2385Key> maybePassword) {
    if (maybePassword.isPresent()) {
        return maybePassword.get().getValue();
    }/*from  ww w .ja  v a2s  .c om*/
    return null;
}

From source file:com.eucalyptus.util.FUtils.java

/**
 * Flatten a nested optional./* w  w w. java 2s.  c  om*/
 *
 * @param option The optional to flatten
 * @param <T> The resulting optional type
 * @return The optional
 */
@Nonnull
public static <T> Optional<T> flatten(@Nullable final Optional<? extends Optional<T>> option) {
    if (option != null && option.isPresent()) {
        return option.get();
    }
    return Optional.absent();
}