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

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

Introduction

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

Prototype

public static <T> Optional<T> of(T reference) 

Source Link

Document

Returns an Optional instance containing the given non-null reference.

Usage

From source file:rickbw.incubator.choice.Choices.java

public static <F, T> Optional<T> map(final Optional<F> from, final Function<? super F, ? extends T> func) {
    if (from.isPresent()) {
        final T result = func.apply(from.get());
        return Optional.of(result);
    } else {/*from   w  w w  .j ava2 s. co  m*/
        return Optional.absent();
    }
}

From source file:extrabiomes.api.Biomes.java

/**
 * Retrieves a custom biome//from  ww w  .  j av  a2 s  .c  om
 * 
 * @param targetBiome
 *            The string name of the targertBiome. See
 *            {@link GetBiomeIDEvent#targetBiome} for valid values.
 * @return The requested biome. If the biome does not exist, the
 *         <code>Optional</code> value will not be present.
 */
public static Optional<BiomeGenBase> getBiome(String targetBiome) {
    final GetBiomeIDEvent event = new GetBiomeIDEvent(targetBiome);
    Api.getExtrabiomesXLEventBus().post(event);
    if (event.biomeID <= 0)
        return Optional.absent();
    return Optional.of(BiomeGenBase.biomeList[event.biomeID]);
}

From source file:org.apache.distributedlog.util.CommandLineUtils.java

public static Optional<String> getOptionalStringArg(CommandLine cmdline, String arg) {
    if (cmdline.hasOption(arg)) {
        return Optional.of(cmdline.getOptionValue(arg));
    } else {// w  w  w . java 2  s  .  com
        return Optional.absent();
    }
}

From source file:com.github.radium226.common.Either.java

public static <L, R> Either<L, R> left(L left) {
    return new Either(Optional.of(left), Optional.absent());
}

From source file:com.google.caliper.platform.dalvik.DalvikModule.java

@Provides
@Singleton//from   www .ja  v a  2  s  .c o  m
public static Optional<DalvikPlatform> provideOptionalPlatform() {
    if (System.getProperty("java.specification.name").equals("Dalvik Core Library")) {
        return Optional.of(new DalvikPlatform());
    } else {
        return Optional.absent();
    }
}

From source file:jetcd.EtcdClientFactory.java

public static EtcdClient newInstance(final Client client, final String server) {
    return new EtcdClientImpl(Optional.of(client), server);
}

From source file:hyper.momitor.util.etcd.HMEtcdClientFactory.java

public static HMEtcdClient newInstance(final Client client, final String server) {
    return new HMEtcdClientImpl(Optional.of(client), server);
}

From source file:extrabiomes.handlers.ConfigurationHandler.java

public static void init(File configFile) {
    Optional<EnhancedConfiguration> optionalConfig = Optional.absent();

    try {//  w  ww  .  j a  v a2  s.  c o m
        optionalConfig = Optional.of(new EnhancedConfiguration(configFile));
        final EnhancedConfiguration configuration = optionalConfig.get();

        for (final BiomeSettings setting : BiomeSettings.values()) {
            setting.load(configuration);
        }

        for (final DecorationSettings setting : DecorationSettings.values()) {
            setting.load(configuration);
        }

        for (final BlockSettings setting : BlockSettings.values()) {
            setting.load(configuration);
        }

        for (final ItemSettings setting : ItemSettings.values()) {
            setting.load(configuration);
        }

        configuration.addCustomCategoryComment("saplingreplanting",
                "Settings to configure the chance that saplings will replant themselves up despawning on valid soil.");
        for (final SaplingSettings setting : SaplingSettings.values()) {
            setting.load(configuration);
        }

        for (final ModuleControlSettings setting : ModuleControlSettings.values()) {
            setting.load(configuration);
        }

        Property bigTreeSaplingDropRateProperty = configuration.get(Configuration.CATEGORY_GENERAL,
                "Relative sapling drops", false);
        bigTreeSaplingDropRateProperty.comment = "Setting relative sapling drops to true will decrease the amount of saplings dropped by decaying fir and redwood leaf blocks to a more reasonable amount.";
        GeneralSettings.bigTreeSaplingDropModifier = bigTreeSaplingDropRateProperty.getBoolean(false);

        //
        Property consoleCommandsDisabled = configuration.get(Configuration.CATEGORY_GENERAL,
                "DisableConsoleCommands", true);
        consoleCommandsDisabled.comment = "Set to false to enable console commands.";
        GeneralSettings.consoleCommandsDisabled = consoleCommandsDisabled.getBoolean(true);

    } catch (final Exception e) {
        LogHelper.log(Level.SEVERE, e, "%s had had a problem loading its configuration", Reference.MOD_NAME);
    } finally {
        if (optionalConfig.isPresent())
            optionalConfig.get().save();
    }
}

From source file:org.locationtech.geogig.storage.impl.Blobs.java

public static Optional<String> getBlobAsString(BlobStore blobStore, String blobName) {
    Optional<byte[]> blob = getBlob(blobStore, blobName);
    Optional<String> str = Optional.absent();
    if (blob.isPresent()) {
        str = Optional.of(new String(blob.get(), Charsets.UTF_8));
    }/*from   w  ww  . j a  v  a2s  .c om*/
    return str;
}

From source file:com.facebook.presto.hive.util.DirectoryEntry.java

public static DirectoryEntry entryForFile(FileStatus fileStatus, BlockLocation[] blockLocation) {
    checkNotNull(fileStatus, "fileStatus is null");
    checkNotNull(blockLocation, "blockLocations is null");
    return new DirectoryEntry(fileStatus, Optional.of(blockLocation));
}