List of usage examples for com.google.common.base Optional isPresent
public abstract boolean isPresent();
From source file:com.aegiswallet.widgets.AegisTypeface.java
public static void applyTypeface(TextView widget, Optional<Font> font) { Optional<Typeface> typeface = createTypeface(widget, font); if (typeface.isPresent()) { widget.setTypeface(typeface.get()); }// w w w. j ava 2 s.c om }
From source file:com.brq.wallet.BitcoinUriWithAddress.java
public static Optional<BitcoinUriWithAddress> parseWithAddress(String uri, NetworkParameters network) { Optional<? extends BitcoinUri> bitcoinUri = parse(uri, network); if (!bitcoinUri.isPresent()) { return Optional.absent(); }//w w w. j a va 2s. co m return fromBitcoinUri(bitcoinUri.get()); }
From source file:org.jclouds.aliyun.ecs.domain.IpProtocol.java
public static IpProtocol fromValue(String value) { Optional<IpProtocol> ipProtocol = Enums.getIfPresent(IpProtocol.class, value.toUpperCase()); checkArgument(ipProtocol.isPresent(), "Expected one of %s but was %s", Joiner.on(',').join(IpProtocol.values()), value); return ipProtocol.get(); }
From source file:org.apache.cassandra.utils.progress.jmx.LegacyJMXProgressSupport.java
protected static Optional<int[]> getLegacyUserdata(String tag, ProgressEvent event) { Optional<Status> status = getStatus(event); if (status.isPresent()) { int[] result = new int[2]; result[0] = getCmd(tag);/*ww w . j a va2 s .co m*/ result[1] = status.get().ordinal(); return Optional.of(result); } return Optional.absent(); }
From source file:com.sk89q.worldedit.world.biome.Biomes.java
/** * Find a biome that matches the given input name. * * @param biomes a list of biomes/* w w w. ja v a 2 s . c o m*/ * @param name the name to test * @param registry a biome registry * @return a biome or null */ @Nullable public static BaseBiome findBiomeByName(Collection<BaseBiome> biomes, String name, BiomeRegistry registry) { checkNotNull(biomes); checkNotNull(name); checkNotNull(registry); Function<String, ? extends Number> compare = new LevenshteinDistance(name, false, LevenshteinDistance.STANDARD_CHARS); WeightedChoice<BaseBiome> chooser = new WeightedChoice<BaseBiome>( Functions.compose(compare, new BiomeName(registry)), 0); for (BaseBiome biome : biomes) { chooser.consider(biome); } Optional<Choice<BaseBiome>> choice = chooser.getChoice(); if (choice.isPresent() && choice.get().getScore() <= 1) { return choice.get().getValue(); } else { return null; } }
From source file:com.complexible.common.base.Copyables.java
/** * If the {@link Optional} has ({@link Optional#isPresent isPresent a value} a {@link Copyable#copy} is made of the object. * Otherwise, with an absent value, the Optional is returned as-is * * @param theObj the object to copy//from ww w . j ava 2 s . c o m * @param <T> the object's type * @return an Optional which contains a copy of the object if a value is present on the optional. */ public static <T> Optional<T> copy(final Optional<T> theObj) { if (theObj.isPresent()) { return Optional.of(copy(theObj.get())); } else { // no value, no need to make a copy return theObj; } }
From source file:org.eclipse.recommenders.utils.rcp.UUIDHelper.java
public static String getUUID() { final Optional<String> uuid = lookupUUIDFromStore(); if (uuid.isPresent()) { return uuid.get(); }/* w ww . j av a2s . c o m*/ final String newUuid = generateGlobalUUID(); storeUUID(newUuid); return newUuid; }
From source file:org.sonar.server.computation.task.projectanalysis.step.UpdateQualityProfilesLastUsedDateStep.java
private static Set<QualityProfile> parseQualityProfiles(Optional<Measure> measure) { if (!measure.isPresent()) { return emptySet(); }// w w w . j ava2 s .c o m String data = measure.get().getStringValue(); return data == null ? emptySet() : QPMeasureData.fromJson(data).getProfiles(); }
From source file:com.treasuredata.client.model.TDSavedQueryBuilder.java
private static <T> void checkPresence(Optional<T> opt, String errorMessage) { if (!opt.isPresent()) { throw new TDClientException(TDClientException.ErrorType.INVALID_INPUT, errorMessage); }// w w w .ja va 2s.c o m }
From source file:edu.berkeley.sparrow.daemon.util.ConfigUtil.java
/** * Parses the list of backends from a {@link Configuration}. * * Returns a map of address of backends to a {@link TResourceVector} describing the * total resource capacity for that backend. *///from w ww . ja v a 2s . c om public static Set<InetSocketAddress> parseBackends(Configuration conf) { if (!conf.containsKey(SparrowConf.STATIC_NODE_MONITORS)) { throw new RuntimeException("Missing configuration node monitor list"); } Set<InetSocketAddress> backends = new HashSet<InetSocketAddress>(); for (String node : conf.getStringArray(SparrowConf.STATIC_NODE_MONITORS)) { Optional<InetSocketAddress> addr = Serialization.strToSocket(node); if (!addr.isPresent()) { LOG.warn("Bad backend address: " + node); continue; } backends.add(addr.get()); } return backends; }