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:net.diogobohm.timed.impl.codec.TaskCodecImpl.java

@Override
public Task decode(DBTask task, Activity activity, Project project, Set<Tag> tags) {
    Date start = null;//w  w  w  .  j  av  a  2 s  .  com
    Optional<Date> end = Optional.absent();
    String description = task.getDescription();

    try {
        start = DATETIME_FORMATTER.parse(task.getStartDateTime());
        if (task.getFinishDateTime() != null) {
            end = Optional.of(DATETIME_FORMATTER.parse(task.getFinishDateTime()));
        }
    } catch (ParseException ex) {
        ex.printStackTrace();
    }

    return new Task(activity, project, start, end, description, tags);
}

From source file:org.opendaylight.unimgr.mef.nrp.common.MountPointHelper.java

/**
 * Find a node's NETCONF mount point and then retrieve its DataBroker.
 * e.g./*from  w  w w .  j  a  v  a2s.co  m*/
 * http://localhost:8080/restconf/config/network-topology:network-topology/
 *        topology/topology-netconf/node/{nodeName}/yang-ext:mount/
 */
public static Optional<DataBroker> getDataBroker(MountPointService mountService, String nodeName) {
    NodeId nodeId = new NodeId(nodeName);

    InstanceIdentifier<Node> nodeInstanceId = InstanceIdentifier.builder(NetworkTopology.class)
            .child(Topology.class, new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())))
            .child(Node.class, new NodeKey(nodeId)).build();

    final Optional<MountPoint> nodeOptional = mountService.getMountPoint(nodeInstanceId);

    if (!nodeOptional.isPresent()) {
        return Optional.absent();
    }

    MountPoint nodeMountPoint = nodeOptional.get();
    return Optional.of(nodeMountPoint.getService(DataBroker.class).get());
}

From source file:org.eclipse.buildship.core.workspace.internal.EclipseVmUtil.java

private static Optional<IVMInstall> findRegisteredVM(String version) {
    Optional<IExecutionEnvironment> possibleExecutionEnvironment = findExecutionEnvironment(version);
    if (!possibleExecutionEnvironment.isPresent()) {
        return Optional.absent();
    }//from   w w  w .j  ava 2 s  .  c  om

    IExecutionEnvironment executionEnvironment = possibleExecutionEnvironment.get();
    IVMInstall defaultVm = executionEnvironment.getDefaultVM();
    if (defaultVm != null) {
        return Optional.of(defaultVm);
    } else {
        IVMInstall firstVm = Iterables.getFirst(Arrays.asList(executionEnvironment.getCompatibleVMs()), null);
        return Optional.fromNullable(firstVm);
    }
}

From source file:com.treasuredata.client.TDClientHttpException.java

public Optional<Date> getRetryAfter() {
    if (retryAfter == -1) {
        return Optional.absent();
    } else {/* w  ww . j a  va2 s  . c  o  m*/
        return Optional.of(new Date(retryAfter));
    }
}

From source file:com.dangdang.ddframe.rdb.sharding.parser.result.merger.AggregationColumn.java

@Override
public Optional<String> getColumnName() {
    return Optional.of(expression);
}

From source file:org.eclipse.buildship.core.util.file.FileUtils.java

/**
 * Derives the absolute path from the specified {@code File} instance.
 *
 * @param file the file from which to get the absolute path
 * @return the absolute path if the file is not {@code null}, otherwise
 * {@link Optional#absent()}//from w w w  . j av a  2 s .c  o m
 */
public static Optional<String> getAbsolutePath(File file) {
    if (file == null) {
        return Optional.absent();
    } else {
        return Optional.of(file.getAbsolutePath());
    }
}

From source file:org.opennms.newts.stress.Query.java

Optional<Timestamp> getEnd() {
    return Optional.of(m_end);
}

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

@Override
public Optional<String> mapAttribute(Object value) {
    if (value == null) {
        return Optional.absent();
    }/*w ww  . ja v  a2s  .c  om*/

    String expectedClass = getOpenType().getClassName();
    String realClass = value.getClass().getName();
    Preconditions.checkArgument(realClass.equals(expectedClass),
            "Type mismatch, expected " + expectedClass + " but was " + realClass);

    WriterPlugin prefferedPlugin = writerPlugins.get(value.getClass().getCanonicalName());
    prefferedPlugin = prefferedPlugin == null ? writerPlugins.get(DEFAULT_WRITER_PLUGIN) : prefferedPlugin;
    return Optional.of(prefferedPlugin.writeObject(value));
}

From source file:org.sosy_lab.cpachecker.cfa.model.c.CStatementEdge.java

@Override
public Optional<CStatement> getRawAST() {
    return Optional.of((CStatement) statement);
}

From source file:nih.quack.jythonpygments.Lexers.java

/**
 * Lookup a Pygments lexer by an alias.//from   w ww. ja va 2s  .  com
 *
 * @param gateway
 * @param alias   language alias for which a lexer is queried
 */
public Optional<Object> lookupLexer(PyGateway gateway, String alias) {
    Object result = lexerCache.get(alias);

    if (result == null) {
        result = evalLookupLexer(gateway, alias, NULL);
        lexerCache.put(alias, result);
    }

    if (result == NULL) {
        return Optional.absent();
    } else {
        return Optional.of(result);
    }
}