List of usage examples for com.google.common.base Optional fromNullable
public static <T> Optional<T> fromNullable(@Nullable T nullableReference)
From source file:extrabiomes.module.fabrica.scarecrow.ItemScarecrow.java
private static boolean spawnCreature(World world, double x, double y, double z) { //{/*from w w w . j a v a 2 s .co m*/ final Optional<Entity> entity = Optional.fromNullable(EntityList.createEntityByName(NAME, world)); if (entity.isPresent()) { entity.get().setLocationAndAngles(x, y, z, world.rand.nextFloat() * 360.0F, 0.0F); world.spawnEntityInWorld(entity.get()); } return entity.isPresent(); //} }
From source file:google.registry.export.sheet.SheetModule.java
@Provides @Parameter("id") static Optional<String> provideId(HttpServletRequest req) { return Optional.fromNullable(emptyToNull(req.getParameter("id"))); }
From source file:co.cask.cdap.common.http.SecurityRequestContext.java
/** * @return the userId set on the current thread *//* ww w . j av a 2 s .c o m*/ public static Optional<String> getUserId() { return Optional.fromNullable(userId.get()); }
From source file:com.github.nethad.clustermeister.api.impl.JobFactory.java
public static <T> Job<T> create(String name, Map<String, Object> jobData) { return new JobImpl(name, Optional.fromNullable(jobData)); }
From source file:org.puder.trs80.configuration.KeyboardLayout.java
public static Optional<KeyboardLayout> fromId(int id) { return Optional.fromNullable(mapped.get(id, null)); }
From source file:google.registry.tldconfig.idn.LanguageValidator.java
/** Return the language validator for the given language code (if one exists). */ static Optional<LanguageValidator> get(String language) { return Optional.fromNullable(LANGUAGE_VALIDATORS.get(language)); }
From source file:org.opendaylight.yangtools.yang.data.impl.codec.UnionStringCodec.java
static TypeDefinitionAwareCodec<?, UnionTypeDefinition> from(final UnionTypeDefinition normalizedType) { return new UnionStringCodec(Optional.fromNullable(normalizedType)); }
From source file:com.google.devtools.build.xcode.util.Mapping.java
/** * Returns the value mapped to the given key for a map. If the mapping is not present, an absent * {@code Optional} is returned.// w w w .j av a 2 s .c om * @throws NullPointerException if the map or key argument is null */ public static <K, V> Optional<V> of(Map<K, V> map, K key) { Preconditions.checkNotNull(key); return Optional.fromNullable(map.get(key)); }
From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.util.Env.java
@NotNull public static Optional<String> option(@NotNull final String key) { return Optional.fromNullable(System.getenv(key)); }
From source file:com.facebook.buck.timing.DefaultPerfTimer.java
private static boolean jvmSupportsCpuTime() { if (jvmSupportsCpuTime == TriState.UNSPECIFIED) { synchronized (lock) { if (jvmSupportsCpuTime == TriState.UNSPECIFIED) { bean = Optional.fromNullable(ManagementFactory.getThreadMXBean()); jvmSupportsCpuTime = TriState .forBooleanValue(bean.isPresent() && bean.get().isThreadCpuTimeSupported()); if (jvmSupportsCpuTime.asBoolean()) { bean.get().setThreadCpuTimeEnabled(true); }/*w ww.j a v a2 s.c o m*/ } } } return jvmSupportsCpuTime.asBoolean(); }