List of usage examples for com.google.common.base Optional absent
public static <T> Optional<T> absent()
From source file:testpackage.OptionalWrapper.java
public static Optional<String> none() { return Optional.absent(); }
From source file:springfox.documentation.schema.ClassSupport.java
public static Optional<? extends Class> classByName(String className) { try {// w w w. j a v a2s . c o m return Optional.of(Class.forName(className)); } catch (ClassNotFoundException e) { return Optional.absent(); } }
From source file:extrabiomes.module.summa.biome.WeightedRandomChooser.java
static <T extends WeightedRandomItem> Optional<T> getRandomItem(Random rand, Collection<T> collection, int limit) { if (limit > 0) { int choice = rand.nextInt(limit); for (final T item : collection) { choice -= item.itemWeight;/*w w w . j a va2s .c o m*/ if (choice < 0) return Optional.of(item); } } return Optional.absent(); }
From source file:extrabiomes.api.Biomes.java
/** * Retrieves a custom biome//from ww w. j a va 2s . com * * @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.eclipse.epp.internal.logging.aeri.ui.utils.Shells.java
public static Optional<Shell> getWorkbenchWindowShell() { IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (workbenchWindow != null) { Shell shell = workbenchWindow.getShell(); if (shell != null) { return Optional.of(shell); }// w ww . j a va 2 s . c om } return Optional.absent(); }
From source file:ch.epfl.eagle.daemon.util.Serialization.java
public static Optional<InetSocketAddress> strToSocket(String in) { String[] parts = in.split(":"); if (parts.length != 2) { return Optional.absent(); }// ww w . j a v a2 s. c o m String host = parts[0]; // This deals with the wonky way Java InetAddress toString() represents an address: // "hostname/IP" if (parts[0].contains("/")) { host = parts[0].split("/")[1]; } try { return Optional.of(new InetSocketAddress(host, Integer.parseInt(parts[1]))); } catch (NumberFormatException e) { return Optional.absent(); } }
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 {/* w w w . j ava 2s. c o m*/ return Optional.absent(); } }
From source file:extrabiomes.handlers.ConfigurationHandler.java
public static void init(File configFile) { Optional<EnhancedConfiguration> optionalConfig = Optional.absent(); try {/*from w w w. ja v a 2 s . co 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.puder.trs80.ActivityHelper.java
/** * Returns an extra value with the given key, if the intent, the extras and the key itself are * present.//from w ww . j a v a 2 s . c o m */ static Optional<Integer> getIntExtra(Intent intent, String key) { if (intent == null) { Log.i(TAG, "No intent."); return Optional.absent(); } if (!intent.hasExtra(key)) { Log.i(TAG, StrUtil.form("No extra named '%s'.", key)); return Optional.absent(); } return Optional.of(intent.getIntExtra(key, 0)); }
From source file:org.gluu.oxtrust.model.helper.SCIMHelper.java
/** * try to extract an email from the User. * If the User has a primary email address this email will be returned. * If not the first email address found will be returned. * If no Email has been found email.isPresent() == false * @param user a {@link User} with a possible email * @return an email if found//from w ww.j a v a2s . co m */ public static Optional<Email> getPrimaryOrFirstEmail(User user) { for (Email email : user.getEmails()) { if (email.isPrimary()) { return Optional.of(email); } } if (user.getEmails().size() > 0) { return Optional.of(user.getEmails().get(0)); } return Optional.absent(); }