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:com.github.nethad.clustermeister.api.impl.ExecutorServiceMode.java

/**
 * Bundles Callables/Runnables and executes them after the given count.
 * @param batchSize number of Callables/Runnables to bundle
 * @return //from w  w w .  jav  a  2 s . co m
 */
public static ExecutorServiceMode batchSizeContraint(int batchSize) {
    return new GenericExecutorServiceMode(Optional.<Long>absent(), Optional.fromNullable(batchSize));
}

From source file:com.spotify.ffwd.noop.NoopOutputPlugin.java

@JsonCreator
public NoopOutputPlugin(@JsonProperty("flushInterval") Long flushInterval) {
    this.flushInterval = Optional.fromNullable(flushInterval).or(DEFAULT_FLUSH_INTERVAL);
}

From source file:eu.cloudwave.wp5.feedback.eclipse.base.infrastructure.config.ConfigLoaderImpl.java

/**
 * {@inheritDoc}// w  ww  .j  a v a2s. com
 */
@Override
public Optional<String> get(final String path, final String key) {
    final Properties properties = new Properties();
    final InputStream fileInputStream = getClass().getClassLoader().getResourceAsStream(path);
    try {
        properties.load(fileInputStream);
    } catch (final IOException e) {
        return Optional.absent();
    }
    return Optional.fromNullable(properties.getProperty(key));
}

From source file:com.eucalyptus.context.ContextPropagationChannelInterceptor.java

@Override
protected Optional<Context> obtainPropagatingContext(final Message<?> message,
        final MessageChannel messageChannel) {
    Optional<Context> context = Optional.fromNullable(Contexts.threadLocal());
    final String correlationId = message.getPayload() instanceof BaseMessage
            ? ((BaseMessage) message.getPayload()).getCorrelationId()
            : null;// ww w .  j a v a 2 s.co m
    if (!context.isPresent() || !context.get().getCorrelationId().equals(correlationId)) {
        if (Contexts.exists(correlationId)) {
            try {
                final Context messageContext = Contexts.lookup(correlationId);
                context = Optional.of(messageContext);
            } catch (NoSuchContextException ignored) {
            }
        }
    }
    return context;
}

From source file:com.weigandtconsulting.javaschool.cache.BookService.java

public static Optional<Book> getBookDetailsFromGoogleBooks(String isbn13) throws IOException {
    //        Properties properties = NetworkUtil.getProperties();
    //        String key = properties.getProperty(Constants.GOOGLE_API_KEY);
    String url = "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn13;
    String response = NetworkUtil.getHttpResponse(url);
    Map bookMap = NetworkUtil.getObjectMapper().readValue(response, Map.class);
    Object bookDataListObj = bookMap.get("items");
    Book book = null;/*ww w  . j  a v  a2s .c om*/
    if (bookDataListObj == null || !(bookDataListObj instanceof List)) {
        return Optional.fromNullable(book);
    }

    List bookDataList = (List) bookDataListObj;
    if (bookDataList.size() < 1) {
        return Optional.fromNullable(null);
    }

    Map bookData = (Map) bookDataList.get(0);
    Map volumeInfo = (Map) bookData.get("volumeInfo");
    book = new Book();
    book.setTitle(getFromJsonResponse(volumeInfo, "title", ""));
    book.setPublisher(getFromJsonResponse(volumeInfo, "publisher", ""));
    List authorDataList = (List) volumeInfo.get("authors");
    for (Object authorDataObj : authorDataList) {
        Author author = new Author();
        author.setName(authorDataObj.toString());
        book.addAuthor(author);
    }
    book.setIsbn13(isbn13);
    book.setSummary(getFromJsonResponse(volumeInfo, "description", ""));
    book.setPageCount(Integer.parseInt(getFromJsonResponse(volumeInfo, "pageCount", "0")));
    book.setPublishedDate(getFromJsonResponse(volumeInfo, "publishedDate", ""));

    return Optional.fromNullable(book);
}

From source file:android.support.test.espresso.Root.java

private Root(Builder builder) {
    this.decorView = checkNotNull(builder.decorView);
    this.windowLayoutParams = Optional.fromNullable(builder.windowLayoutParams);
}

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

@Override
public Optional<LinkPO> update(long id, String name, String url, String description) {
    LinkPO linkPO = this.linkDAO.findById(id);
    if (linkPO != null) {
        linkPO.setName(name);// w  ww .  ja v a2  s  .  co m
        linkPO.setUrl(url);
        linkPO.setDescription(description);
        this.linkDAO.updateAllById(linkPO);
    }
    return Optional.fromNullable(linkPO);
}

From source file:org.apache.brooklyn.rest.domain.ApiError.java

/**
 * @return An {@link ApiError.Builder} whose message is initialised to either the throwable's
 *         message or the throwable's class name if the message is null and whose details are
 *         initialised to the throwable's stack trace.
 *//*  w ww. j ava  2 s  . co m*/
public static Builder builderFromThrowable(Throwable t) {
    checkNotNull(t, "throwable");
    String message = Optional.fromNullable(t.getMessage()).or(t.getClass().getName());
    return builder().message(message).details(Throwables.getStackTraceAsString(t));
}

From source file:gobblin.metrics.InnerMeter.java

InnerMeter(MetricContext context, String name, ContextAwareMeter contextAwareMeter) {
    this.name = name;

    Optional<MetricContext> parentContext = context.getParent();
    if (parentContext.isPresent()) {
        this.parentMeter = Optional.fromNullable(parentContext.get().contextAwareMeter(name));
    } else {/*from w  w  w .j  ava  2  s  .c  o  m*/
        this.parentMeter = Optional.absent();
    }
    this.contextAwareMeter = new WeakReference<>(contextAwareMeter);
}

From source file:com.datastax.driver.core.schemabuilder.CreateType.java

CreateType(String keyspaceName, String typeName) {
    validateNotEmpty(keyspaceName, "Keyspace name");
    validateNotEmpty(typeName, "Custom type name");
    validateNotKeyWord(keyspaceName, String
            .format("The keyspace name '%s' is not allowed because it is a reserved keyword", keyspaceName));
    validateNotKeyWord(typeName, String
            .format("The custom type name '%s' is not allowed because it is a reserved keyword", typeName));
    this.typeName = typeName;
    this.keyspaceName = Optional.fromNullable(keyspaceName);
}