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

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

Introduction

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

Prototype

public static <T> Optional<T> absent() 

Source Link

Document

Returns an Optional instance with no contained reference.

Usage

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

public static Optional<String> getBlobAsString(BlobStore blobStore, String blobName) {
    Optional<byte[]> blob = getBlob(blobStore, blobName);
    Optional<String> str = Optional.absent();
    if (blob.isPresent()) {
        str = Optional.of(new String(blob.get(), Charsets.UTF_8));
    }// w w  w . j ava  2 s.c  o m
    return str;
}

From source file:com.github.radium226.common.Either.java

public static <L, R> Either<L, R> left(L left) {
    return new Either(Optional.of(left), Optional.absent());
}

From source file:org.apache.distributedlog.util.CommandLineUtils.java

public static Optional<String> getOptionalStringArg(CommandLine cmdline, String arg) {
    if (cmdline.hasOption(arg)) {
        return Optional.of(cmdline.getOptionValue(arg));
    } else {//from  w  w w.ja v  a 2s . c om
        return Optional.absent();
    }
}

From source file:com.google.caliper.platform.dalvik.DalvikModule.java

@Provides
@Singleton//  ww  w . ja v a  2s . c om
public static Optional<DalvikPlatform> provideOptionalPlatform() {
    if (System.getProperty("java.specification.name").equals("Dalvik Core Library")) {
        return Optional.of(new DalvikPlatform());
    } else {
        return Optional.absent();
    }
}

From source file:com.github.jeluard.guayaba.base.Optionals.java

/**
 * @param <T>/*from w  w w  . j a  v a  2  s . c  o  m*/
 * @param optional
 * @return an {@link Optional} returning encapsulated {@link Optional}
 */
public static <T> Optional<T> flatten(final Optional<Optional<T>> optional) {
    Preconditions.checkNotNull(optional, "null optional");

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

    return optional.get();
}

From source file:org.opendaylight.vpnservice.mdsalutil.MDSALDataStoreUtils.java

public static <T extends DataObject> Optional<T> read(final DataBroker broker,
        final LogicalDatastoreType datastoreType, InstanceIdentifier<T> path) {

    ReadOnlyTransaction tx = broker.newReadOnlyTransaction();

    Optional<T> result = Optional.absent();
    try {//from  w w w. j a v a  2  s.  com
        result = tx.read(datastoreType, path).get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    return result;
}

From source file:org.onos.yangtools.yang.model.util.SchemaNodeUtils.java

public static final Optional<SchemaNode> getOriginalIfPossible(final SchemaNode node) {
    if (node instanceof DerivableSchemaNode) {
        @SuppressWarnings("unchecked")
        final Optional<SchemaNode> ret = (Optional<SchemaNode>) (((DerivableSchemaNode) node).getOriginal());
        return ret;
    }//from   w ww  .  jav  a2s  . c o m
    return Optional.absent();
}

From source file:de.flapdoodle.guava.Expectations.java

private static <T> Optional<T> intNoneOrOne(Iterator<T> iterator) {
    Preconditions.checkNotNull(iterator, "iterator is null");
    if (!iterator.hasNext()) {
        return Optional.absent();
    }//from ww w  .  j  a v  a  2  s .c  o m
    return Optional.of(iterator.next());
}

From source file:org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils.java

public static Optional<SchemaNode> getOriginalIfPossible(final SchemaNode node) {
    if (node instanceof DerivableSchemaNode) {
        @SuppressWarnings("unchecked")
        final Optional<SchemaNode> ret = (Optional<SchemaNode>) (((DerivableSchemaNode) node).getOriginal());
        return ret;
    }//from ww  w  .  j  ava 2  s  .c o  m
    return Optional.absent();
}

From source file:org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractDataTreeCandidateNode.java

private static Optional<NormalizedNode<?, ?>> getChild(
        final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> container,
        final PathArgument identifier) {
    return container == null ? Optional.absent() : container.getChild(identifier);
}