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

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

Introduction

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

Prototype

public static <T> Optional<T> of(T reference) 

Source Link

Document

Returns an Optional instance containing the given non-null reference.

Usage

From source file:edu.ksu.cis.santos.mdcf.dml.ast.MultiplicityAnnotation.java

public MultiplicityAnnotation(final int lo, final int hi, final Optional<String> typeName) {
    this.lo = lo;
    this.hi = hi;
    this.typeName = typeName.isPresent() ? Optional.of(typeName.get().intern()) : typeName;
}

From source file:com.gradleware.tooling.testing.GradleVersionExtractor.java

/**
 * Returns the Gradle version referenced by the given distribution location.
 *
 * @param uri the distribution location/*from   www .j a v  a2s . c o  m*/
 * @return the Gradle version of the distribution
 */
public static Optional<String> getVersion(URI uri) {
    Preconditions.checkNotNull(uri);

    Matcher m = PATTERN.matcher(uri.toString());
    if (m.find()) {
        return Optional.of(m.group(1));
    } else {
        return Optional.absent();
    }
}

From source file:com.rentmycourt.api.core.helpers.SimpleAuthenticator.java

/**
 *
 * @param credentials// w ww  .j a v a  2  s  . com
 * @return
 * @throws io.dropwizard.auth.AuthenticationException.<error>
 */
@Override
public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException {
    if ("secret".equals(credentials.getPassword())) {
        return Optional.of(new User(credentials.getUsername()));
    }
    return Optional.absent();
}

From source file:org.sonar.server.permission.ws.WsProjectRef.java

public static Optional<WsProjectRef> newOptionalWsProjectRef(@Nullable String uuid, @Nullable String key) {
    if (uuid == null && key == null) {
        return Optional.absent();
    }//from   w w  w . ja va  2  s  . c om

    return Optional.of(new WsProjectRef(uuid, key));
}

From source file:org.eclipse.mylyn.internal.wikitext.commonmark.inlines.PotentialBracketSpan.java

@Override
public Optional<? extends Inline> createInline(Cursor cursor) {
    char c = cursor.getChar();
    if (c == '!' && cursor.hasNext() && cursor.getNext() == '[') {
        return Optional.of(new PotentialBracketDelimiter(cursor.getLineAtOffset(), cursor.getOffset(), 2,
                cursor.getTextAtOffset(2)));
    }/* ww  w  .j a  v  a2  s .c om*/
    if (c == '[') {
        return Optional.of(new PotentialBracketDelimiter(cursor.getLineAtOffset(), cursor.getOffset(), 1,
                cursor.getTextAtOffset(1)));
    }
    if (c == ']') {
        return Optional.of(new PotentialBracketEndDelimiter(cursor.getLineAtOffset(), cursor.getOffset()));
    }
    return Optional.absent();
}

From source file:si.arnes.dropbookmarks.auth.HelloAuthenticator.java

@Override
public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException {
    if (password.equals(credentials.getPassword())) {
        return Optional.of(new User(0, credentials.getUsername(), credentials.getPassword()));
    }//from w w w  .  ja v a 2  s. c om
    return Optional.absent();
}

From source file:org.automagic.deps.doctor.TransitiveDepsGroup.java

public void add(TransitiveDependency dependency) {
    if (dependency.getHopCount() == 1) {
        topLevelDependency = Optional.of(dependency);
    }//from w  w w.j  av a2  s . c om
    dependencies.add(dependency);
}

From source file:cc.ilo.cc.ilo.pipeline.pipes.AbstractFilterPipe.java

@Override
public Optional<T> process(T input) throws Exception {
    if (accept(input)) {
        return Optional.of(input);
    } else {/* w w  w.  j  a  va 2s.c om*/
        return Optional.absent();
    }

}

From source file:org.fusesource.fabric.service.jclouds.functions.ToAdminAccess.java

public static Optional<AdminAccess> apply(CreateJCloudsContainerOptions input) {
    AdminAccess.Builder builder = AdminAccess.builder();
    //There are images that have issues with copying of public keys, creation of admin user accounts,etc
    //To allow//from  ww w  .j av a 2s.co m
    if (input.isAdminAccess()) {
        if (!Strings.isNullOrEmpty(input.getPublicKeyFile())) {
            File publicKey = new File(input.getPublicKeyFile());
            if (publicKey.exists()) {
                builder.adminPublicKey(publicKey);
            } else {
                LOGGER.warn("Public key has been specified file: {} files cannot be found. Ignoring.",
                        publicKey.getAbsolutePath());
                return Optional.of(AdminAccess.standard());
            }
        }

        if (!Strings.isNullOrEmpty(input.getUser())) {
            builder.adminUsername(input.getUser());
        }

        return Optional.of(builder.build());
    }
    return Optional.absent();
}

From source file:com.github.kevints.mesos.scheduler.server.LibprocessServletUtils.java

static Optional<String> parseMessageType(HttpServletRequest req) {
    String pathInfo = req.getPathInfo();
    if (pathInfo == null) {
        return Optional.absent();
    }/*from  w  w  w .  j  av a  2  s  . c om*/

    return Optional.of(Paths.get(pathInfo).getFileName().toString());
}