/** * 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); }
@Override public List<U> valueOf(String value) throws IllegalArgumentException { return parsePrimitives(value, delimiter, parser); } };
@Override protected void populate(T builder, Map<PropertyDescriptorField, String> fields) { super.populate(builder, fields); char delim = delimiterIn(fields, builder.multiValueDelimiter); builder.delim(delim).defaultValues(ValueParserConstants.multi(parser, delim) .valueOf(fields.get(PropertyDescriptorField.DEFAULT_VALUE))); }
private ValueParser<?> getValueParser(PropertyTypeId typeId) { ValueParser<?> parser = typeId.getValueParser(); if (typeId.isPropertyMultivalue()) { char delimiter = typeId.isPropertyNumeric() ? DEFAULT_NUMERIC_DELIMITER : DEFAULT_DELIMITER; parser = ValueParserConstants.multi(parser, delimiter); } return parser; }
@Override protected void populate(T builder, Map<PropertyDescriptorField, String> fields) { super.populate(builder, fields); char delim = delimiterIn(fields, builder.multiValueDelimiter); builder.delim(delim).defaultValues(ValueParserConstants.multi(parser, delim) .valueOf(fields.get(PropertyDescriptorField.DEFAULT_VALUE))); }
private static List<Class> typesFrom(String valueString) { return ValueParserConstants.parsePrimitives(valueString, MULTI_VALUE_DELIMITER, ValueParserConstants.CLASS_PARSER); }
/** * 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); }
private static List<Method> methodsFrom(String valueString) { return ValueParserConstants.parsePrimitives(valueString, MULTI_VALUE_DELIMITER, METHOD_PARSER); }
@Override public List<U> valueOf(String value) throws IllegalArgumentException { return parsePrimitives(value, delimiter, parser); } };
private static List<Method> methodsFrom(String valueString) { return ValueParserConstants.parsePrimitives(valueString, MULTI_VALUE_DELIMITER, METHOD_PARSER); }
private static List<Class> typesFrom(String valueString) { return ValueParserConstants.parsePrimitives(valueString, MULTI_VALUE_DELIMITER, ValueParserConstants.CLASS_PARSER); }