/** * Returns a builder for a long integer property. The property descriptor * will by default accept any value conforming to the format specified * by {@link Long#parseLong(String)}, e.g. {@code 1234455678854}. * * <p>Note that that parser only supports decimal representations, and that neither * the character L nor l is permitted to appear at the end of the string as a type * indicator, as would be permitted in Java source. * * <p>Acceptable values may be further refined by {@linkplain PropertyBuilder#require(PropertyConstraint) adding constraints}. * The class {@link NumericConstraints} provides some useful ready-made constraints * for that purpose. * * @param name Name of the property to build * * @return A new builder * * @see NumericConstraints */ public static GenericPropertyBuilder<Long> longIntProperty(String name) { return new GenericPropertyBuilder<>(name, ValueParserConstants.LONG_PARSER, Long.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); }
/** * Returns a builder for an integer property. The property descriptor * will by default accept any value conforming to the format specified * by {@link Integer#parseInt(String)}, e.g. {@code 1234} or {@code -123}. * * <p>Note that that parser only supports decimal representations. * * <p>Acceptable values may be further refined by {@linkplain PropertyBuilder#require(PropertyConstraint) adding constraints}. * The class {@link NumericConstraints} provides some useful ready-made constraints * for that purpose. * * @param name Name of the property to build * * @return A new builder * * @see NumericConstraints */ public static GenericPropertyBuilder<Integer> intProperty(String name) { return new GenericPropertyBuilder<>(name, ValueParserConstants.INTEGER_PARSER, Integer.class); }
/** * Returns a builder for a double property. The property descriptor * will by default accept any value conforming to the format specified * by {@link Double#valueOf(String)}, e.g. {@code 0}, {@code .93}, or {@code 1e-1}. * Acceptable values may be further refined by {@linkplain PropertyBuilder#require(PropertyConstraint) adding constraints}. * The class {@link NumericConstraints} provides some useful ready-made constraints * for that purpose. * * @param name Name of the property to build * * @return A new builder * * @see NumericConstraints */ public static GenericPropertyBuilder<Double> doubleProperty(String name) { return new GenericPropertyBuilder<>(name, ValueParserConstants.DOUBLE_PARSER, Double.class); }
/** * Returns a builder for a character property. The property descriptor * will accept any single character string. No unescaping is performed * other than what the XML parser does itself. That means that Java * escape sequences are not expanded: e.g. "\n", will be represented as the * character sequence '\' 'n', so it's not a valid value for this type * of property. On the other hand, XML character references are expanded, * like {@literal &} ('&') or {@literal <} ('<'). * * @param name Name of the property to build * * @return A new builder */ public static GenericPropertyBuilder<Character> charProperty(String name) { return new GenericPropertyBuilder<>(name, ValueParserConstants.CHARACTER_PARSER, Character.class); }
/** * Returns a builder for a string property. The property descriptor * will accept any string, and performs no expansion of escape * sequences (e.g. {@code \n} in the XML will be represented as the * character sequence '\' 'n' and not the line-feed character '\n'). * This behaviour could be changed with PMD 7.0.0. * * @param name Name of the property to build * * @return A new builder */ public static GenericPropertyBuilder<String> stringProperty(String name) { return new GenericPropertyBuilder<>(name, ValueParserConstants.STRING_PARSER, String.class); }
/** * Returns a builder for a boolean property. The boolean is parsed from * the XML using {@link Boolean#valueOf(String)}, i.e. the only truthy * value is the string "true", and all other string values are falsy. * * @param name Name of the property to build * * @return A new builder */ public static GenericPropertyBuilder<Boolean> booleanProperty(String name) { return new GenericPropertyBuilder<>(name, ValueParserConstants.BOOLEAN_PARSER, Boolean.class); }
/** * Returns a builder for a long integer property. The property descriptor * will by default accept any value conforming to the format specified * by {@link Long#parseLong(String)}, e.g. {@code 1234455678854}. * * <p>Note that that parser only supports decimal representations, and that neither * the character L nor l is permitted to appear at the end of the string as a type * indicator, as would be permitted in Java source. * * <p>Acceptable values may be further refined by {@linkplain PropertyBuilder#require(PropertyConstraint) adding constraints}. * The class {@link NumericConstraints} provides some useful ready-made constraints * for that purpose. * * @param name Name of the property to build * * @return A new builder * * @see NumericConstraints */ public static GenericPropertyBuilder<Long> longIntProperty(String name) { return new GenericPropertyBuilder<>(name, ValueParserConstants.LONG_PARSER, Long.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); }
/** * Returns a builder for an integer property. The property descriptor * will by default accept any value conforming to the format specified * by {@link Integer#parseInt(String)}, e.g. {@code 1234} or {@code -123}. * * <p>Note that that parser only supports decimal representations. * * <p>Acceptable values may be further refined by {@linkplain PropertyBuilder#require(PropertyConstraint) adding constraints}. * The class {@link NumericConstraints} provides some useful ready-made constraints * for that purpose. * * @param name Name of the property to build * * @return A new builder * * @see NumericConstraints */ public static GenericPropertyBuilder<Integer> intProperty(String name) { return new GenericPropertyBuilder<>(name, ValueParserConstants.INTEGER_PARSER, Integer.class); }
/** * Returns a builder for a character property. The property descriptor * will accept any single character string. No unescaping is performed * other than what the XML parser does itself. That means that Java * escape sequences are not expanded: e.g. "\n", will be represented as the * character sequence '\' 'n', so it's not a valid value for this type * of property. On the other hand, XML character references are expanded, * like {@literal &} ('&') or {@literal <} ('<'). * * @param name Name of the property to build * * @return A new builder */ public static GenericPropertyBuilder<Character> charProperty(String name) { return new GenericPropertyBuilder<>(name, ValueParserConstants.CHARACTER_PARSER, Character.class); }
/** * Returns a builder for a string property. The property descriptor * will accept any string, and performs no expansion of escape * sequences (e.g. {@code \n} in the XML will be represented as the * character sequence '\' 'n' and not the line-feed character '\n'). * This behaviour could be changed with PMD 7.0.0. * * @param name Name of the property to build * * @return A new builder */ public static GenericPropertyBuilder<String> stringProperty(String name) { return new GenericPropertyBuilder<>(name, ValueParserConstants.STRING_PARSER, String.class); }
/** * Returns a builder for a double property. The property descriptor * will by default accept any value conforming to the format specified * by {@link Double#valueOf(String)}, e.g. {@code 0}, {@code .93}, or {@code 1e-1}. * Acceptable values may be further refined by {@linkplain PropertyBuilder#require(PropertyConstraint) adding constraints}. * The class {@link NumericConstraints} provides some useful ready-made constraints * for that purpose. * * @param name Name of the property to build * * @return A new builder * * @see NumericConstraints */ public static GenericPropertyBuilder<Double> doubleProperty(String name) { return new GenericPropertyBuilder<>(name, ValueParserConstants.DOUBLE_PARSER, Double.class); }
/** * Returns a builder for a boolean property. The boolean is parsed from * the XML using {@link Boolean#valueOf(String)}, i.e. the only truthy * value is the string "true", and all other string values are falsy. * * @param name Name of the property to build * * @return A new builder */ public static GenericPropertyBuilder<Boolean> booleanProperty(String name) { return new GenericPropertyBuilder<>(name, ValueParserConstants.BOOLEAN_PARSER, Boolean.class); }