Gets optional if true.

@param <T>    the type parameter
@param bool   the bool
@param target the target
@return the optional if true
13958
public static <T> Optional<T> getOptionalIfTrue(boolean bool, T target) {
        return bool ? Optional.ofNullable(target) : Optional.empty();
    }
614881
public <T extends Enum<T>> Optional<T> answer(final Class<T> enumClass) {
        return fromNullable(askBuilder.answer(enumClass));
    }
827577
@SuppressWarnings("unchecked")
    public static <T> Optional<Class<T>> optional(String dependency) {
        try {
            return Optional.of((Class<T>) Class.forName(dependency));
        } catch (ClassNotFoundException | NoClassDefFoundError e) {
            return Optional.empty();
        }
    }
866626
public static <T> boolean any(Optional<? extends T>... optionals) {
        return Iterables.any(Arrays.asList(optionals), isPresent());
    }
585956
public boolean isAssignableTo(Class<?> target) {

        LettuceAssert.notNull(target, "Target type must not be null");

        return LettuceClassUtils.isAssignable(target, getParameterType());
    }
555631
public static <T> Optional<T> getNullableOptional(final Map map, final Class<T> clazz, final Object... path) {
        return getNullable(map, Optional.class, path);
    }
1055079
public <T extends Annotation> Optional<T> getAnnotation( String annotation ) {
        return CreatorUtils.getAnnotation( annotation, accessors );
    }
338625
public static <E> OptionalFunction<Selection<Element>, E> getValue() {
    return OptionalFunction.of(selection -> selection.result().getValue());
  }
257957
public static <T> OptionalValue<T> ofNullable(ResourceKey key, T value) {
        return new GenericOptionalValue<T>(RUNTIME_SOURCE, key, value);
    }
563767
public static <T> @NonNull Optional<T> cast(final @Nullable Object object, final @NonNull Class<T> type) {
    return type.isInstance(object) ? Optional.of((T) object) : Optional.empty();
  }
724180
protected <T> Optional<T> executeGetRequest(URI uri, GenericType<T> returnType)
    {
        return executeGetRequest(uri, null, null, returnType);
    }
654386
public static <T> OptionalValue<T> ofNullable(T value) {
        return new GenericOptionalValue<T>(RUNTIME_SOURCE, DEFAULT_KEY, value);
    }
1312575
public static <T> Optional<Optional<T>> dotGetOptional(
            final Map map, final String pathString, final Class<T> clazz
    ) {
        return dotGet(map, Optional.class, pathString).map(opt -> (Optional<T>) opt);
    }
1256565
public static <T> @NonNull Optional<T> cast(final @NonNull Optional<?> optional, final @NonNull Class<T> type) {
    // not necessary to re-wrap, we can just cast
    return isInstance(optional, type) ? (Optional<T>) optional : Optional.empty();
  }
252600
public static <R> Optional<R> supplierIfTrue(boolean bool,
            Supplier<R> supplier) {
        return bool ? Optional.ofNullable(supplier.get()) : Optional.empty();
    }
634576
public final Parser<T> optional(T defaultValue) {
    return Parsers.or(this, Parsers.constant(defaultValue));
  }
72630
public static Optional<Boolean> toBoolean(Object arg) {
        if ( arg instanceof Boolean ) {
            return Optional.of( (Boolean) arg );
        }
        else if(arg instanceof String) {
            if("true".equalsIgnoreCase( (String)arg )) {
                return Optional.of( Boolean.TRUE );
            }
            else if("false".equalsIgnoreCase( (String)arg )) {
                return Optional.of( Boolean.FALSE );
            }
        }
        return Optional.empty();
    }