/** * Tests a string against a set of valid choices to see if it is a * case-insensitive match. * * @param choices The choices available to match against * @param potentialChoice The potential choice * @return If matched, an {@link Optional} containing the matched value */ protected Optional<Object> getExactMatch(final Iterable<String> choices, final String potentialChoice) { return Iterables.tryFind(choices, potentialChoice::equalsIgnoreCase).toJavaUtil().map(this::getValue); }
/** * Returns the equivalent {@code java.util.Optional} value to the given {@code * com.google.common.base.Optional}, or {@code null} if the argument is null. * * <p>If {@code googleOptional} is known to be non-null, use {@code googleOptional.toJavaUtil()} * instead. * * <p>Unfortunately, the method reference {@code Optional::toJavaUtil} will not work, because it * could refer to either the static or instance version of this method. Write out the lambda * expression {@code o -> Optional.toJavaUtil(o)} instead. * * @since 21.0 */ public static <T> java.util.@Nullable Optional<T> toJavaUtil( @Nullable Optional<T> googleOptional) { return googleOptional == null ? null : googleOptional.toJavaUtil(); }
public void testToJavaUtil_static() { assertNull(Optional.toJavaUtil(null)); assertEquals(java.util.Optional.empty(), Optional.toJavaUtil(Optional.absent())); assertEquals(java.util.Optional.of("abc"), Optional.toJavaUtil(Optional.of("abc"))); }
public void testToJavaUtil_instance() { assertEquals(java.util.Optional.empty(), Optional.absent().toJavaUtil()); assertEquals(java.util.Optional.of("abc"), Optional.of("abc").toJavaUtil()); }
/** * Returns the equivalent {@code java.util.Optional} value to the given {@code * com.google.common.base.Optional}, or {@code null} if the argument is null. * * <p>If {@code googleOptional} is known to be non-null, use {@code googleOptional.toJavaUtil()} * instead. * * <p>Unfortunately, the method reference {@code Optional::toJavaUtil} will not work, because it * could refer to either the static or instance version of this method. Write out the lambda * expression {@code o -> Optional.toJavaUtil(o)} instead. * * @since 21.0 */ @NullableDecl public static <T> java.util.Optional<T> toJavaUtil(@NullableDecl Optional<T> googleOptional) { return googleOptional == null ? null : googleOptional.toJavaUtil(); }
@Override public BigDecimal magnitude(Object value) { Optional<?> narrowed = narrow(value); return narrowed.toJavaUtil() .map(componentGenerators().get(0)::magnitude) .orElse(ZERO); } }
/** * Attempts to find an enumerated value using {@link Enum#valueOf(Class, String)}. */ // TODO Deprecate in favor of `search(enumType).byName(name)` public static <E extends Enum<E>> Optional<E> tryByName(Class<E> enumClass, String name) { return Enums.getIfPresent(enumClass, name).toJavaUtil(); }
@Override public String toString() { String size = data.sizeIfKnown().toJavaUtil().map(Object::toString).orElse("?"); return "ImmutableTypedContent{" + "contentType=" + contentType + ", data.size=" + size + '}'; } }
@Override public BigDecimal magnitude(Object value) { Optional<?> narrowed = narrow(value); return narrowed.toJavaUtil() .map(componentGenerators().get(0)::magnitude) .orElse(ZERO); } }
/** * Get the {@link AceMode} by file extension. * <p> * First tries to match the given extension against an AceMode value, otherwise looks into AceMode's additional mappings (<code>endingModeMap</code>). */ private AceMode getAceModeByFileExtension(String extension) { // Trying the get AceMode from the Enum Optional<AceMode> aceModeValue = getIfPresent(AceMode.class, extension).toJavaUtil(); // Trying to get AceMode from the AceMode.endingModeMap return aceModeValue.orElseGet(() -> forFileEnding(extension)); } }
public static void streamHeapHistogram(OutputStream os, int nbRows) { Optional<InputStream> optIS = VirtualMachineWithoutToolsJar.heapHisto().toJavaUtil();
public static void streamHeapHistogram(OutputStream os, int nbRows) { Optional<InputStream> optIS = VirtualMachineWithoutToolsJar.heapHisto().toJavaUtil();
/** * Find an enumerated constant by name. If multiple constants match (e.g. the search was performed ignoring * case) an {@code IllegalArgumentException} is thrown. */ public Optional<E> byName(String name) { if (start) { return Enums.getIfPresent(enumType, name).toJavaUtil(); } else { return withName(name).collect(toOptional()); } }
/** * Returns the equivalent {@code java.util.Optional} value to the given {@code * com.google.common.base.Optional}, or {@code null} if the argument is null. * * <p>If {@code googleOptional} is known to be non-null, use {@code googleOptional.toJavaUtil()} * instead. * * <p>Unfortunately, the method reference {@code Optional::toJavaUtil} will not work, because it * could refer to either the static or instance version of this method. Write out the lambda * expression {@code o -> Optional.toJavaUtil(o)} instead. * * @since 21.0 */ @NullableDecl public static <T> java.util.Optional<T> toJavaUtil(@NullableDecl Optional<T> googleOptional) { return googleOptional == null ? null : googleOptional.toJavaUtil(); }
/** * Returns the equivalent {@code java.util.Optional} value to the given {@code * com.google.common.base.Optional}, or {@code null} if the argument is null. * * <p>If {@code googleOptional} is known to be non-null, use {@code googleOptional.toJavaUtil()} * instead. * * <p>Unfortunately, the method reference {@code Optional::toJavaUtil} will not work, because it * could refer to either the static or instance version of this method. Write out the lambda * expression {@code o -> Optional.toJavaUtil(o)} instead. * * @since 21.0 */ public static <T> java.util.@Nullable Optional<T> toJavaUtil( @Nullable Optional<T> googleOptional) { return googleOptional == null ? null : googleOptional.toJavaUtil(); }
}); return result.toJavaUtil();
Optional<GeogigTransaction> tryGetTransaction(Context repo) { Optional<GeogigTransaction> tx = com.google.common.base.Optional .toJavaUtil(repo.command(TransactionResolve.class).setId(transactionId).call()); return tx; }
static FluentFuture<Optional<NormalizedNode<?, ?>>> read(final DOMDataReadTransaction tx, final LogicalDatastoreType store, final YangInstanceIdentifier path) { return FluentFuture.from(tx.read(fromMdsal(store), path)).transform(opt -> opt.toJavaUtil(), MoreExecutors.directExecutor()); }
public void testToJavaUtil_static() { assertNull(Optional.toJavaUtil(null)); assertEquals(java.util.Optional.empty(), Optional.toJavaUtil(Optional.absent())); assertEquals(java.util.Optional.of("abc"), Optional.toJavaUtil(Optional.of("abc"))); }
public void testToJavaUtil_instance() { assertEquals(java.util.Optional.empty(), Optional.absent().toJavaUtil()); assertEquals(java.util.Optional.of("abc"), Optional.of("abc").toJavaUtil()); }