List of usage examples for com.google.common.base Optional fromNullable
public static <T> Optional<T> fromNullable(@Nullable T nullableReference)
From source file:org.locationtech.geogig.rest.Variants.java
public static Optional<Variant> getVariantByExtension(Request request, List<Variant> supported) { String extension = RESTUtils.getStringAttribute(request, "extension"); Variant v = null;/*from w w w .j a v a 2 s.c o m*/ if ("xml".equals(extension) && supported.contains(XML)) { v = XML; } else if ("json".equals(extension) && supported.contains(JSON)) { v = JSON; } else if ("csv".equals(extension) && supported.contains(CSV)) { v = CSV; } return Optional.fromNullable(v); }
From source file:io.mesosphere.mesos.util.Functions.java
@NotNull public static <A> Optional<A> headOption(@NotNull final Iterable<A> iterable) { final Iterator<A> iter = iterable.iterator(); if (iter.hasNext()) { return Optional.fromNullable(iter.next()); } else {// w w w. j a v a 2s . co m return Optional.absent(); } }
From source file:org.locationtech.geogig.plumbing.ResolveGeogigDir.java
public static Optional<URL> lookup(final File directory) { try {//from w w w . j a v a 2s . com return Optional.fromNullable(lookupGeogigDirectory(directory)); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:org.jclouds.reflect.InvocationSuccess.java
public static InvocationSuccess create(Invocation invocation, @Nullable Object result) { return new InvocationSuccess(invocation, Optional.fromNullable(result)); }
From source file:ph.devcon.android.category.db.Category.java
public static Category toCategory(CategoryAPI categoryAPI) { Category category = null;//from www . j a v a2 s . c o m Optional<CategoryAPI> categoryAPIOptional = Optional.fromNullable(categoryAPI); if (categoryAPIOptional.isPresent()) { String categoryName = categoryAPIOptional.get().getName(); if (!Util.isNullOrEmpty(categoryName)) { category = new Category(); category.setName(categoryAPIOptional.get().getName()); } } return category; }
From source file:com.googlesource.gerrit.plugins.github.git.GitHubUser.java
private static Optional<String> initLogin(GHUser gitHubUser) { return Optional.fromNullable(gitHubUser != null ? gitHubUser.getLogin() : null); }
From source file:gobblin.compliance.utils.DatasetUtils.java
/** * Find {@link HivePartitionDataset} given complete partition name from a list of datasets * @param partitionName Complete partition name ie dbName@tableName@partitionName *///from www .jav a 2s .co m public static Optional<HivePartitionDataset> findDataset(String partitionName, List<HivePartitionDataset> datasets) { for (HivePartitionDataset dataset : datasets) { if (dataset.datasetURN().equalsIgnoreCase(partitionName)) { return Optional.fromNullable(dataset); } } log.warn("Unable to find dataset corresponding to " + partitionName); return Optional.<HivePartitionDataset>absent(); }
From source file:com.spotify.helios.common.Resolver.java
private static String env(final String name, final String defaultValue) { return Optional.fromNullable(getenv(name)).or(defaultValue); }
From source file:io.macgyver.core.Kernel.java
public static Optional<Throwable> getStartupError() { return Optional.fromNullable(startupError); }
From source file:org.apache.usergrid.persistence.model.entity.EntityMap.java
public static Optional<EntityMap> fromEntity(Optional<Entity> entity) { if (entity.isPresent()) { EntityMap map = fromEntity(entity.get()); return Optional.fromNullable(map); } else {/*from www . j ava 2 s. c o m*/ return Optional.absent(); } }