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:org.geogit.api.plumbing.CommitFromDateOp.java

@Override
public Optional<RevCommit> call() {
    Preconditions.checkState(date != null);
    long time = date.getTime();
    Iterator<RevCommit> iter = command(LogOp.class).setFirstParentOnly(true).call();
    while (iter.hasNext()) {
        RevCommit commit = iter.next();/*  w  ww.jav a2s  .  c  o m*/
        if (commit.getCommitter().getTimestamp() < time) {
            return Optional.of(commit);
        }
    }
    return Optional.absent();
}

From source file:org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.mapping.EnumAttributeMappingStrategy.java

@Override
public Optional<String> mapAttribute(Object value) {
    if (value == null) {
        return Optional.absent();
    }//w  w w. j av  a2 s . c om

    String expectedClass = getOpenType().getTypeName();
    return Optional.of(enumResolver.toYang(expectedClass, value.toString()));
}

From source file:com.palantir.giraffe.ssh.PublicKeySshCredential.java

public static PublicKeySshCredential fromFile(String username, Path privateKeyFile) throws IOException {
    byte[] privateKey = Files.readAllBytes(privateKeyFile);
    return new PublicKeySshCredential(username, privateKey, Optional.of(privateKeyFile));
}

From source file:io.dockstore.common.Utilities.java

public static ImmutablePair<String, String> executeCommand(String command) {
    return executeCommand(command, true, Optional.of(ByteStreams.nullOutputStream()),
            Optional.of(ByteStreams.nullOutputStream()));
}

From source file:com.addthis.hydra.job.spawn.jersey.DefaultAuthenticator.java

@Override
public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException {
    if (!StringUtils.isEmpty(credentials.getUsername())) {
        return Optional.of(new User(credentials.getUsername(), credentials.getUsername(), true)); //default admin
    }//from w  w w.  jav a2  s  . com
    return Optional.absent();
}

From source file:com.google.template.soy.shared.RangeArgs.java

/**
 * Returns a optional {@link RangeArgs} object if the for loop expression is a {@code range(...)}
 * expression./*from  w  w w  .ja va  2  s. c  o  m*/
 */
public static final Optional<RangeArgs> createFromNode(ForNode node) {
    if (node.getExpr().getRoot() instanceof FunctionNode) {
        FunctionNode fn = (FunctionNode) node.getExpr().getRoot();
        if (fn.getSoyFunction() instanceof RangeFunction) {
            return Optional.of(create(fn.getChildren()));
        }
    }
    return Optional.absent();
}

From source file:si.klepra.dropwizardbookmarks.auth.HelloAuthenticator.java

@Override
public Optional<User> authenticate(BasicCredentials c) throws AuthenticationException {

    //call db or auth service here!
    if (configuration.getPassword().equals(c.getPassword())) {
        return Optional.of(new User());
    }//from w  ww.  j  a va2s .  c o  m
    return Optional.absent();
}

From source file:com.google.gerrit.server.change.ChangeTriplet.java

/**
 * Parse a triplet out of a string./*from   w w w  .j  ava 2s .co  m*/
 *
 * @param triplet string of the form "project~branch~id".
 * @return the triplet if the input string has the proper format, or absent if
 *     not.
 */
public static Optional<ChangeTriplet> parse(String triplet) {
    int t2 = triplet.lastIndexOf('~');
    int t1 = triplet.lastIndexOf('~', t2 - 1);
    if (t1 < 0 || t2 < 0) {
        return Optional.absent();
    }

    String project = Url.decode(triplet.substring(0, t1));
    String branch = Url.decode(triplet.substring(t1 + 1, t2));
    String changeId = Url.decode(triplet.substring(t2 + 1));

    ChangeTriplet result = new AutoValue_ChangeTriplet(new Branch.NameKey(new Project.NameKey(project), branch),
            new Change.Key(changeId));
    return Optional.of(result);
}

From source file:com.github.rinde.rinsim.core.model.comm.Message.java

static Message createDirect(CommUser from, CommUser to, MessageContents m, Predicate<CommUser> p) {
    return new AutoValue_Message(from, Optional.of(to), m, p);
}

From source file:im.dadoo.teak.biz.bo.impl.DefaultUserBO.java

@Override
public Optional<UserPO> insert(String name, String password) {
    UserPO userPO = this.userDAO.findByName(name);
    //????//from   w  ww  .  j  a v  a  2 s . com
    if (userPO == null) {
        userPO = new UserPO();
        userPO.setName(name);
        userPO.setPassword(password);
        return Optional.of(this.userDAO.insert(userPO));
    } else {
        return Optional.absent();
    }
}