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

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

Introduction

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

Prototype

public static <T> Optional<T> fromNullable(@Nullable T nullableReference) 

Source Link

Document

If nullableReference is non-null, returns an Optional instance containing that reference; otherwise returns Optional#absent .

Usage

From source file:org.locationtech.geogig.osm.internal.log.ReadOSMMappingLogEntry.java

@Override
protected Optional<OSMMappingLogEntry> _call() {
    final File osmMapFolder = command(ResolveOSMMappingLogFolder.class).call();
    File file = new File(osmMapFolder, path);
    OSMMappingLogEntry entry = null;/*w w  w .  j ava 2s . c o  m*/
    if (file.exists()) {
        try {
            synchronized (file.getCanonicalPath().intern()) {
                String line = Files.readFirstLine(file, Charsets.UTF_8);
                entry = OSMMappingLogEntry.fromString(line);
            }
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
    }
    return Optional.fromNullable(entry);
}

From source file:org.eclipse.epp.internal.logging.aeri.ui.notifications.NewErrorNotification.java

@Override
public String getDescription() {
    StringBuilder b = new StringBuilder();
    Throwable exception = report.getStatus().getException();
    if (exception != null) {

        String message = toShortClassName(exception.getClassName()) + ": "
                + Optional.fromNullable(exception.getMessage()).or("");
        b.append(StringUtils.abbreviate(message, 120));
    }//w w w  .  ja v  a 2s .  com
    b.append("\n\nDo you want to report this error?");
    return b.toString();
}

From source file:org.jage.emas.util.ChainingContext.java

/**
 * Returns an optional next context./*from  w  ww.  j  a  v  a2s.c  o m*/
 *
 * @return an optional next context
 */
public final Optional<ChainingContext> getNextContext() {
    return Optional.fromNullable(next);
}

From source file:net.awairo.mcmod.common.v1.util.LimitedNumber.java

/**
 * ??????????Long????.//from  w  w w.j a v  a 2 s.  co  m
 * 
 * @return Long?{@link LimitedNumber}
 */
public static Builder<Long> ofLong(final Prop prop, final long defaultValue) {
    return new Builder<Long>() {
        {
            current(Optional.fromNullable(Longs.tryParse(prop.getString())).or(defaultValue));
            min(Long.MIN_VALUE);
            max(Long.MAX_VALUE);
            step(1L);
        }

        @Override
        protected LimitedNumber<Long> newInstance(Long current, Long min, Long max, Long step) {
            return new LimitedNumber<Long>(current, min, max, step) {
                @Override
                protected Long incrementValue(Long current, Long step) {
                    // Long???????
                    return current > 0 && Long.MAX_VALUE - current < step ? Long.MAX_VALUE : current + step;
                }

                @Override
                protected Long decrementValue(Long current, Long step) {
                    // Long???????
                    return current < 0 && current - Long.MIN_VALUE < step ? Long.MIN_VALUE : current - step;
                }

                @Override
                protected void updated() {
                    prop.set(current().toString());
                }
            };
        }
    };
}

From source file:ec.nbdemetra.jdbc.DbExplorerUtil.java

@Nonnull
static Optional<DatabaseConnection> findConnection(@Nonnull Node node) {
    DatabaseConnection result = null;//from  ww w  . j  a  v a2s  . co  m
    Node current = node;
    while (current != null && (result = current.getLookup().lookup(DatabaseConnection.class)) == null) {
        current = current.getParentNode();
    }
    return Optional.fromNullable(result);
}

From source file:org.apache.cassandra.cql3.hooks.ExecutionContext.java

public ExecutionContext(QueryState queryState, String queryString, QueryOptions queryOptions) {
    this.queryState = queryState;
    this.queryString = Optional.fromNullable(queryString);
    this.queryOptions = queryOptions;
}

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

@Override
public Optional<LinkPO> findById(long id) {
    return Optional.fromNullable(this.linkDAO.findById(id));
}

From source file:com.spotify.helios.agent.AddExtraHostContainerDecorator.java

@Override
public void decorateHostConfig(final Job job, final Optional<String> dockerVersion,
        final HostConfig.Builder hostConfig) {
    final List<String> hosts = Lists.newArrayList();
    hosts.addAll(this.extraHosts);
    //TODO write better backwards copatiblity
    hosts.addAll(Optional.fromNullable(job.getExtraHosts()).or(Collections.emptySet()));
    hostConfig.extraHosts(hosts);/*from  w  w w  .ja v a2  s. c om*/
}

From source file:org.mayocat.mail.MailTemplate.java

public MailTemplate locale(Locale locale) {
    this.locale = Optional.fromNullable(locale);
    return this;
}

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. jav  a 2  s  .com*/

    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);
    }
}