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.locationtech.geogig.storage.sqlite.SQLiteStorage.java

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

From source file:be.nbb.demetra.dfm.output.news.NewsWeightsViewFactory.java

private static ItemUI<IProcDocumentView<VersionedDfmDocument>, Optional<DfmNews>> newItemUI() {
    return new DefaultItemUI<IProcDocumentView<VersionedDfmDocument>, Optional<DfmNews>>() {
        @Override// w  w w . j av a 2s  .c o m
        public JComponent getView(IProcDocumentView<VersionedDfmDocument> host, Optional<DfmNews> information) {
            if (information.isPresent()) {
                NewsWeightsView v = new NewsWeightsView();
                v.setResults(host.getDocument().getCurrent().getDfmResults(), information.get());
                return v;
            } else {
                JLabel label = new JLabel("No results found", JLabel.CENTER);
                label.setFont(label.getFont().deriveFont(18f));
                return label;
            }
        }
    };
}

From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.util.Env.java

@NotNull
public static String get(@NotNull final String key) {
    final Optional<String> opt = option(key);
    if (opt.isPresent()) {
        return opt.get();
    } else {/*  w w w . j a v  a2  s.  co m*/
        throw new IllegalStateException(String.format("Environment variable %s is not defined", key));
    }
}

From source file:be.nbb.demetra.dfm.output.news.NewsImpactsViewFactory.java

private static ItemUI<IProcDocumentView<VersionedDfmDocument>, Optional<DfmNews>> newItemUI() {
    return new DefaultItemUI<IProcDocumentView<VersionedDfmDocument>, Optional<DfmNews>>() {
        @Override//from   ww  w. j a  v a 2  s  . com
        public JComponent getView(IProcDocumentView<VersionedDfmDocument> host, Optional<DfmNews> information) {
            if (information.isPresent()) {
                NewsImpactsView v = new NewsImpactsView();
                v.setResults(host.getDocument().getCurrent().getDfmResults(), information.get());
                return v;
            } else {
                JLabel label = new JLabel("No results found", JLabel.CENTER);
                label.setFont(label.getFont().deriveFont(18f));
                return label;
            }
        }
    };
}

From source file:net.caseif.flint.steel.util.helper.ChatHelper.java

private static boolean checkRoundBarrier(Optional<Challenger> ch) {
    return ch.isPresent() && ch.get().getRound().getConfigValue(ConfigNode.SEPARATE_ROUND_CHATS);
}

From source file:org.fabrician.enabler.util.BuildCmdOptions.java

public static String buildAll(RuntimeContext rtc) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < rtc.getVariableCount(); i++) {
        RuntimeContextVariable var = rtc.getVariable(i);
        Optional<String> option = build(var);
        if (option.isPresent()) {
            sb.append(option.get());//from   w ww .j  a  v  a2 s . c  om
        }
    }
    return sb.toString();
}

From source file:org.dswarm.graph.delta.match.model.util.CSEntityUtil.java

public static Optional<? extends Collection<ValueEntity>> getValueEntities(
        final Optional<? extends Collection<CSEntity>> csEntities) {

    if (!csEntities.isPresent() || csEntities.get().isEmpty()) {

        return Optional.absent();
    }/*from   ww w  .j a va  2  s .co  m*/

    final Set<ValueEntity> valueEntities = new HashSet<>();

    for (final CSEntity csEntity : csEntities.get()) {

        valueEntities.addAll(csEntity.getValueEntities());
    }

    return Optional.of(valueEntities);
}

From source file:com.shufudong.GuavaExample.collect.OptionalExample.java

/**
 * @return/* w  w w  . j  ava 2 s  .  c om*/
 * @category <p></p>
 * <ol>
 * <li> boolean isPresent()Optional?T?nulltrueTnullfalse</li>
 * <li>T get()Optional?TT???nullOptionalget()IllegalStateException</li>
 * <li>T or(T)Optional?T?Optional?T?T</li>
 * <li>T orNull()Optional??TOptional?null?fromNullable()</li>
 * <li>Set<T> asSet()??SetSet?Optional??TSet?T??Optional?T??Set</li>
 * </ol>
 * @throw
 */
public static void testMethodReturn() {
    Optional<Long> value = method();
    if (value.isPresent() == true) {
        System.out.println(": " + value.get());
    } else {

        System.out.println(": " + value.or(-12L));
    }

    System.out.println(" orNull: " + value.orNull());

    Optional<Long> valueNoNull = methodNoNull();
    if (valueNoNull.isPresent() == true) {
        Set<Long> set = valueNoNull.asSet();
        System.out.println(" set  size : " + set.size());
        System.out.println(": " + valueNoNull.get());
    } else {
        System.out.println(": " + valueNoNull.or(-12L));
    }

    System.out.println(" orNull: " + valueNoNull.orNull());
}

From source file:org.apache.aurora.scheduler.http.api.security.FieldGetters.java

public static <P extends TBase<P, ?>, C extends TBase<C, ?>, G extends TBase<G, ?>> FieldGetter<P, G> compose(
        final FieldGetter<P, C> parent, final FieldGetter<C, G> child) {

    return new FieldGetter<P, G>() {
        @Override// w w w .j  ava2 s  . com
        public Class<P> getStructClass() {
            return parent.getStructClass();
        }

        @Override
        public Class<G> getValueClass() {
            return child.getValueClass();
        }

        @Override
        public Optional<G> apply(P input) {
            Optional<C> parentValue = parent.apply(input);
            if (parentValue.isPresent()) {
                return child.apply(parentValue.get());
            } else {
                return Optional.absent();
            }
        }
    };
}

From source file:org.spongepowered.api.util.text.OptBool.java

/**
 * Coerces the given {@code Optional&lt;Boolean&gt;} into one of the three stored states.
 *
 * @param bool The boolean/*w  w w  .j  av a 2s. c o m*/
 * @return The constructed Optional, or {@link Optional#absent()}
 */
public static Optional<Boolean> of(Optional<Boolean> bool) {
    if (bool.isPresent()) {
        return of(bool.get().booleanValue());
    } else {
        return ABSENT;
    }
}