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.protocol.bgp.rib.spi.PeerRoleUtil.java

public static PeerRole roleForChange(final Optional<NormalizedNode<?, ?>> maybePeerRole) {
    if (maybePeerRole.isPresent()) {
        final LeafNode<?> peerRoleLeaf = (LeafNode<?>) maybePeerRole.get();
        return PeerRole.valueOf(BindingMapping.getClassName((String) peerRoleLeaf.getValue()));
    }//from w  ww.jav a2s .  c o m
    return null;
}

From source file:info.rynkowski.hamsterclient.ui.utils.TimeConverter.java

public static @NonNull String toString(@NonNull Optional<Calendar> calendar, @NonNull String format) {
    if (calendar.isPresent()) {
        return toString(calendar.get(), format);
    }/*from  w  w  w .  j a va 2 s  . c  om*/
    return "";
}

From source file:com.facebook.buck.util.Optionals.java

public static <T> void addIfPresent(Optional<T> optional, ImmutableCollection.Builder<T> collection) {
    if (optional.isPresent()) {
        collection.add(optional.get());/*from  w  ww  .java  2  s  .  c o m*/
    }
}

From source file:org.raml.api.RamlTypes.java

public static RamlType fromType(Type type) {
    Optional<ScalarType> scalarTypeOptional = ScalarType.fromType(type);

    if (scalarTypeOptional.isPresent()) {
        return scalarTypeOptional.get();
    }/*ww  w.  j  a  v a 2s .  co  m*/

    throw new RuntimeException(format("unknown type: %s", type));
}

From source file:com.facebook.buck.util.Optionals.java

public static <K, T> void putIfPresent(Optional<T> optional, K key, ImmutableMap.Builder<K, T> collection) {
    if (optional.isPresent()) {
        collection.put(key, optional.get());
    }//from  w  w  w.j  av a 2s . c  om
}

From source file:org.opendaylight.yangtools.yang.data.api.schema.tree.spi.AbstractContainerNode.java

static TreeNode getChildFromData(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data,
        final PathArgument childId, final Version version) {
    final Optional<NormalizedNode<?, ?>> child = data.getChild(childId);
    return child.isPresent() ? TreeNodeFactory.createTreeNode(child.get(), version) : null;
}

From source file:org.geogit.storage.sqlite.SQLiteStorage.java

/**
 * Returns the .geogit directory for the platform object.
 *///from   w ww.ja va2 s . c  o m
public static File geogitDir(Platform platform) {
    Optional<URL> url = new ResolveGeogitDir(platform).call();
    if (!url.isPresent()) {
        throw new RuntimeException("Unable to resolve .geogit directory");
    }
    try {
        return new File(url.get().toURI());
    } catch (URISyntaxException e) {
        throw new RuntimeException("Error resolving .geogit directory", e);
    }
}

From source file:rickbw.incubator.choice.Choices.java

public static <F, T> Optional<T> map(final Optional<F> from, final Function<? super F, ? extends T> func) {
    if (from.isPresent()) {
        final T result = func.apply(from.get());
        return Optional.of(result);
    } else {//w ww . j  av  a2s .  c o  m
        return Optional.absent();
    }
}

From source file:cc.recommenders.utils.parser.VersionParserFactory.java

public static Version parse(final String version) {
    final Optional<IVersionParser> opt = getCompatibleParser(version);
    ensureIsTrue(opt.isPresent(), "Given version string '%s' has unknown format and can not be parsed.",
            version);/*from w  ww. j  a v  a  2 s.c  o  m*/
    return opt.get().parse(version);
}

From source file:com.facebook.buck.haskell.HaskellTestUtils.java

/**
 * Assume that we can find a haskell compiler on the system.
 *///from  ww w.  j av  a2 s  . co  m
public static void assumeSystemCompiler() {
    HaskellBuckConfig fakeConfig = new HaskellBuckConfig(FakeBuckConfig.builder().build(),
            new ExecutableFinder());
    Optional<Path> compilerOptional = fakeConfig.getSystemCompiler();
    assumeTrue(compilerOptional.isPresent());
}