List of usage examples for com.google.common.base Optional absent
public static <T> Optional<T> absent()
From source file:li.klass.fhem.domain.MAXMode.java
public static Optional<MAXMode> modeFor(String value) { if (NumberUtil.isDecimalNumber(value)) { int mode = ValueExtractUtil.extractLeadingInt(value); switch (mode) { case 0:/*ww w. j av a 2s . c o m*/ return Optional.of(MAXMode.AUTO); case 1: return Optional.of(MAXMode.MANUAL); case 2: return Optional.of(MAXMode.TEMPORARY); case 3: return Optional.of(MAXMode.BOOST); default: throw new IllegalArgumentException("don't know how to handle heating mode " + mode); } } else { try { return Optional.of(MAXMode.valueOf(value.toUpperCase(Locale.getDefault()))); } catch (Exception e) { Log.e(MAXMode.class.getName(), "cannot set heating mode from value " + value, e); return Optional.absent(); } } }
From source file:com.facebook.buck.rules.coercer.LeafTypeCoercer.java
@Override public Optional<T> getOptionalValue() { return Optional.absent(); }
From source file:com.facebook.buck.apple.FatBinaryInfos.java
/** * Inspect the given build target and return information about it if its a fat binary. * * @return non-empty when the target represents a fat binary. * @throws com.facebook.buck.util.HumanReadableException * when the target is a fat binary but has incompatible flavors. *///from w w w . j ava2 s. c o m public static Optional<FatBinaryInfo> create( final Map<Flavor, AppleCxxPlatform> platformFlavorsToAppleCxxPlatforms, BuildTarget target) { ImmutableList<ImmutableSortedSet<Flavor>> thinFlavorSets = generateThinFlavors( platformFlavorsToAppleCxxPlatforms.keySet(), target.getFlavors()); if (thinFlavorSets.size() <= 1) { // Actually a thin binary return Optional.absent(); } if (!Sets.intersection(target.getFlavors(), FORBIDDEN_BUILD_ACTIONS).isEmpty()) { throw new HumanReadableException("%s: Fat binaries is only supported when building an actual binary.", target); } Predicate<Flavor> isPlatformFlavor = Predicates.in(platformFlavorsToAppleCxxPlatforms.keySet()); AppleCxxPlatform representativePlatform = null; AppleSdk sdk = null; for (SortedSet<Flavor> flavorSet : thinFlavorSets) { AppleCxxPlatform platform = Preconditions.checkNotNull( platformFlavorsToAppleCxxPlatforms.get(Iterables.find(flavorSet, isPlatformFlavor))); if (sdk == null) { sdk = platform.getAppleSdk(); representativePlatform = platform; } else if (sdk != platform.getAppleSdk()) { throw new HumanReadableException( "%s: Fat binaries can only be generated from binaries compiled for the same SDK.", target); } } FatBinaryInfo.Builder builder = FatBinaryInfo.builder().setFatTarget(target) .setRepresentativePlatform(Preconditions.checkNotNull(representativePlatform)); BuildTarget platformFreeTarget = target.withoutFlavors(platformFlavorsToAppleCxxPlatforms.keySet()); for (SortedSet<Flavor> flavorSet : thinFlavorSets) { builder.addThinTargets(platformFreeTarget.withFlavors(flavorSet)); } return Optional.of(builder.build()); }
From source file:org.opendaylight.yangtools.yang.model.util.type.AbstractRangedBaseType.java
AbstractRangedBaseType(final QName qname, final Number minValue, final Number maxValue) { super(qname); this.rangeConstraints = ImmutableList .of(BaseConstraints.newRangeConstraint(minValue, maxValue, Optional.absent(), Optional.absent())); }
From source file:org.apache.gobblin.util.io.MeteredInputStream.java
/** * Find the lowest {@link MeteredInputStream} in a chain of {@link FilterInputStream}s. *//*from www. j a va 2s.com*/ public static Optional<MeteredInputStream> findWrappedMeteredInputStream(InputStream is) { if (is instanceof FilterInputStream) { try { Optional<MeteredInputStream> meteredInputStream = findWrappedMeteredInputStream( FilterStreamUnpacker.unpackFilterInputStream((FilterInputStream) is)); if (meteredInputStream.isPresent()) { return meteredInputStream; } } catch (IllegalAccessException iae) { log.warn("Cannot unpack input stream due to SecurityManager.", iae); // Do nothing, we can't unpack the FilterInputStream due to security restrictions } } if (is instanceof MeteredInputStream) { return Optional.of((MeteredInputStream) is); } return Optional.absent(); }
From source file:serposcope.controllers.UserPreferences.java
public Result preferences(Context context) { return Results.ok().render("lang", lang.getLanguage(context, Optional.absent())); }
From source file:de.flapdoodle.logparser.StreamProcessException.java
public <T> Optional<T> entry(Class<T> type) { if (entry != null) { if (type.isInstance(entry)) { return Optional.of((T) entry); }/*from w w w.j a v a 2 s .c om*/ } return Optional.absent(); }
From source file:io.dohko.jdbi.OptionalContainerFactory.java
@Override public ContainerBuilder<Optional<?>> newContainerBuilderFor(Class<?> type) { return new ContainerBuilder<Optional<?>>() { private Optional<?> _optional = Optional.absent(); @Override/*w ww . ja v a2s . c om*/ public ContainerBuilder<Optional<?>> add(Object it) { this._optional = Optional.fromNullable(it); return this; } @Override public Optional<?> build() { return _optional; } }; }
From source file:google.registry.tldconfig.idn.IdnLabelValidator.java
/** * Returns name of first matching {@link IdnTable} if domain label is valid for the given TLD. * * <p>A label is valid if it is considered valid by at least one configured IDN table for that * TLD. If no match is found, an absent value is returned. *//*w w w . jav a 2 s . c o m*/ public static Optional<String> findValidIdnTableForTld(String label, String tld) { String unicodeString = Idn.toUnicode(label); for (IdnTableEnum idnTable : Optional.fromNullable(idnTableListsPerTld.get(tld)).or(DEFAULT_IDN_TABLES)) { if (idnTable.getTable().isValidLabel(unicodeString)) { return Optional.of(idnTable.getTable().getName()); } } return Optional.absent(); }
From source file:google.registry.testing.RegistryConfigRule.java
/** Creates a new instance where {@link #override(RegistryConfig)} will be called as needed. */ public RegistryConfigRule() { this.override = Optional.absent(); }