List of usage examples for com.google.common.base Optional fromNullable
public static <T> Optional<T> fromNullable(@Nullable T nullableReference)
From source file:com.kegare.caveworld.util.Version.java
private static void initialize() { CURRENT = Optional.of(Strings.nullToEmpty(Caveworld.metadata.version)); LATEST = Optional.fromNullable(CURRENT.orNull()); ModContainer mod = CaveUtils.getModContainer(); File file = mod == null ? null : mod.getSource(); if (file != null && file.exists()) { if (file.isFile()) { String name = FilenameUtils.getBaseName(file.getName()); if (StringUtils.endsWithIgnoreCase(name, "dev")) { DEV_DEBUG = true;//from w ww . jav a2 s. c o m } } else if (file.isDirectory()) { DEV_DEBUG = true; } } else if (!FMLForgePlugin.RUNTIME_DEOBF) { DEV_DEBUG = true; } if (Caveworld.metadata.version.endsWith("dev")) { DEV_DEBUG = true; } else if (DEV_DEBUG) { Caveworld.metadata.version += "-dev"; } }
From source file:io.urmia.util.ArgumentParseUtil.java
static Optional<String> getArgument(String[] args, String shortName, String longName) { int i = 0;/*from w w w.ja v a 2 s . c o m*/ while (i < args.length && args[i].startsWith("-")) { String arg = args[i++]; if (arg.equals(shortName) || arg.equals(longName)) if (i < args.length) return Optional.fromNullable(args[i]); } return Optional.absent(); }
From source file:org.ctoolkit.services.endpoints.TransformerHelper.java
/** * Converts to <code>Boolean</code> value if presented. * * @param map the map of properties taken from input JSON * @param key the JSON property as a key * @return the optional <code>Boolean</code> value *//* w ww . j a v a 2 s .com*/ public static Optional<Boolean> toBoolean(Map<String, Object> map, String key) { checkNotNull(key); return Optional.fromNullable((Boolean) map.get(key)); }
From source file:org.atlasapi.application.MongoSourceLicenseStore.java
@Override public Optional<SourceLicense> licenseFor(Publisher source) { return Optional.fromNullable( translator.fromDBObject(sourceLicenses.findOne(where().idEquals(source.key()).build()))); }
From source file:org.spongepowered.api.entity.living.meta.OcelotTypes.java
public static Optional<OcelotType> valueOf(String name) { return Optional.fromNullable(null); }
From source file:com.github.fge.grappa.transform.LoadingOpcode.java
public static int forType(@Nonnull Type type) { Objects.requireNonNull(type); // Will throw IllegalStateException if optional .isAbsent() return Optional.fromNullable(LOADING_OPCODES.get(type.getSort())).get(); }
From source file:org.opendaylight.yangtools.yang.data.impl.codec.BitsStringCodec.java
static TypeDefinitionAwareCodec<?, BitsTypeDefinition> from(final BitsTypeDefinition normalizedType) { return new BitsStringCodec(Optional.fromNullable(normalizedType)); }
From source file:io.brooklyn.camp.dto.ApiErrorDto.java
/** * @return An {@link ApiErrorDto.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. c o m public static Builder fromThrowable(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:extrabiomes.module.amica.thermalexpansion.ThermalExpansionAPI.java
ThermalExpansionAPI() { try {//w w w . jav a 2s . c om final Class cls = Class.forName("thermalexpansion.api.crafting.CraftingHelpers"); addSawmillLogToPlankRecipe = Optional .fromNullable(cls.getMethod("addSawmillLogToPlankRecipe", ItemStack.class, ItemStack.class)); craftingHelpers = Optional.of(cls.newInstance()); } catch (final Exception e) { e.printStackTrace(); craftingHelpers = Optional.absent(); addSawmillLogToPlankRecipe = Optional.absent(); } }
From source file:com.almuradev.guide.content.PageRegistry.java
public static Optional<Page> removePage(String identifier) { return Optional.fromNullable(PAGES.remove(identifier)); }