/** creates a {@link ValueResolver} instance which allows significantly more customization than * the various {@link #resolveValue(Object, Class, ExecutionContext)} methods here */ public static <T> ValueResolver<T> resolving(Object v, Class<T> type) { return new ValueResolver<T>(v, type); }
public <T> ValueResolver<T> as(Class<T> type) { return new ValueResolver<T>(v, type); } }
/** @see #resolveValue(Object, Class, ExecutionContext, String) */ public static <T> T resolveValue(Object v, Class<T> type, @Nullable ExecutionContext exec) throws ExecutionException, InterruptedException { return new ValueResolver<T>(v, type).context(exec).get(); }
/** attempt to resolve the given value as the given type, waiting on futures, submitting if necessary, * and coercing as allowed by TypeCoercions; * contextMessage (optional) will be displayed in status reports while it waits (e.g. the name of the config key being looked up). * if no execution context supplied (null) this method will throw an exception if the object is an unsubmitted task */ public static <T> T resolveValue(Object v, Class<T> type, @Nullable ExecutionContext exec, String contextMessage) throws ExecutionException, InterruptedException { return new ValueResolver<T>(v, type).context(exec).description(contextMessage).get(); }
/** * Resolves the given object, blocking on futures and coercing it to the given type. If the object is a * map or iterable (or a list of map of maps, etc, etc) then walks these maps/iterables to convert all of * their values to the given type. For example, the following will return a list containing a map with "1"="true": * * {@code Object result = resolveDeepValue(ImmutableList.of(ImmutableMap.of(1, true)), String.class, exec)} * * To perform a deep conversion of futures contained within Iterables or Maps without coercion of each element, * the type should normally be Object, not the type of the collection. This differs from * {@link #resolveValue(Object, Class, ExecutionContext, String)} which will accept Map and Iterable * as the required type. */ public static <T> T resolveDeepValue(Object v, Class<T> type, ExecutionContext exec, String contextMessage) throws ExecutionException, InterruptedException { return new ValueResolver<T>(v, type).context(exec).deep(true).description(contextMessage).get(); }
<S> ValueResolver<S> cloneReplacingValueAndType(Object newValue, Class<S> superType) { // superType expected to be either type or Object.class if (!superType.isAssignableFrom(type)) { throw new IllegalStateException("superType must be assignable from " + type); } ValueResolver<S> result = new ValueResolver<S>(newValue, superType) .context(exec).description(description) .embedResolutionInTask(embedResolutionInTask) .deep(forceDeep) .timeout(timeout) .immediately(immediately) .recursive(recursive); if (returnDefaultOnGet) { if (!superType.isInstance(defaultValue)) { throw new IllegalStateException("Existing default value " + defaultValue + " not compatible with new type " + superType); } @SuppressWarnings("unchecked") S typedDefaultValue = (S)defaultValue; result.defaultValue(typedDefaultValue); } if (swallowExceptions) result.swallowExceptions(); return result; }
? new ValueResolver<T>(result.get(), type, this).getMaybe() : result : result; Maybe<?> kk = new ValueResolver(entry.getKey(), type, this) .description( (description!=null ? description+", " : "") + "map key "+entry.getKey() ) .getMaybe(); if (kk.isAbsent()) return (Maybe<T>)kk; Maybe<?> vv = new ValueResolver(entry.getValue(), type, this) .description( (description!=null ? description+", " : "") + "map value for key "+kk.get() ) .getMaybe(); int count = 0; for (Object it : (Set)v) { Maybe<?> vv = new ValueResolver(it, type, this) .description( (description!=null ? description+", " : "") + "entry "+count ) .getMaybe(); int count = 0; for (Object it : (Iterable)v) { Maybe<?> vv = new ValueResolver(it, type, this) .description( (description!=null ? description+", " : "") + "entry "+count ) .getMaybe(); return new ValueResolver(v, type, this).getMaybe(); } else {