/** * Returns a builder for an enumerated property. Such a property can be * defined for any type {@code <T>}, provided the possible values can be * indexed by strings. This is enforced by passing a {@code Map<String, T>} * at construction time, which maps labels to values. If {@link Map#get(Object)} * returns null for a given label, then the value is rejected. Null values * are hence prohibited. * * @param name Name of the property to build * @param nameToValue Map of labels to values. The null key is ignored. * @param <T> Value type of the property * * @return A new builder */ public static <T> GenericPropertyBuilder<T> enumProperty(String name, Map<String, T> nameToValue) { // TODO find solution to document the set of possible values // At best, map that requirement to a constraint (eg make parser return null if not found, and // add a non-null constraint with the right description.) return new GenericPropertyBuilder<>(name, ValueParserConstants.enumerationParser(nameToValue), (Class<T>) Object.class); }
/** * Returns a builder for an enumerated property. Such a property can be * defined for any type {@code <T>}, provided the possible values can be * indexed by strings. This is enforced by passing a {@code Map<String, T>} * at construction time, which maps labels to values. If {@link Map#get(Object)} * returns null for a given label, then the value is rejected. Null values * are hence prohibited. * * @param name Name of the property to build * @param nameToValue Map of labels to values. The null key is ignored. * @param <T> Value type of the property * * @return A new builder */ public static <T> GenericPropertyBuilder<T> enumProperty(String name, Map<String, T> nameToValue) { // TODO find solution to document the set of possible values // At best, map that requirement to a constraint (eg make parser return null if not found, and // add a non-null constraint with the right description.) return new GenericPropertyBuilder<>(name, ValueParserConstants.enumerationParser(nameToValue), (Class<T>) Object.class); }