private static GenericPropertyBuilder<CommentRequirement> requirementPropertyBuilder(String name, String commentType) { DESCRIPTOR_NAME_TO_COMMENT_TYPE.put(name, commentType); return PropertyFactory.enumProperty(name, CommentRequirement.mappings()) .desc(commentType + ". Possible values: " + CommentRequirement.labels()) .defaultValue(CommentRequirement.Required); } }
private static PropertyDescriptor<Boolean> booleanPropertyFor(String id, String label) { PropertyDescriptor<Boolean> prop = PROPERTY_DESCRIPTORS_BY_ID.get(id); if (prop != null) { return prop; } prop = PropertyFactory.booleanProperty(id).defaultValue(true).desc("Include " + label + " column").build(); PROPERTY_DESCRIPTORS_BY_ID.put(id, prop); return prop; }
/** * 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 property having as value a list of {@code <T>}. The * format of the individual items is the same as for {@linkplain #enumProperty(String, Map)}. * * @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> GenericCollectionPropertyBuilder<T, List<T>> enumListProperty(String name, Map<String, T> nameToValue) { return enumProperty(name, nameToValue).toList().delim(MultiValuePropertyDescriptor.DEFAULT_DELIMITER); }
/** * 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); }
private static GenericPropertyBuilder<CommentRequirement> requirementPropertyBuilder(String name, String commentType) { DESCRIPTOR_NAME_TO_COMMENT_TYPE.put(name, commentType); return PropertyFactory.enumProperty(name, CommentRequirement.mappings()) .desc(commentType + ". Possible values: " + CommentRequirement.labels()) .defaultValue(CommentRequirement.Required); } }
/** * Returns a builder for a property having as value a list of characters. The * format of the individual items is the same as for {@linkplain #charProperty(String) charProperty}. * * @param name Name of the property to build * * @return A new builder */ public static GenericCollectionPropertyBuilder<Character, List<Character>> charListProperty(String name) { return charProperty(name).toList(); }
/** * Returns a builder for a property having as value a list of integers. The * format of the individual items is the same as for {@linkplain #intProperty(String) intProperty}. * * @param name Name of the property to build * * @return A new builder */ public static GenericCollectionPropertyBuilder<Integer, List<Integer>> intListProperty(String name) { return intProperty(name).toList().delim(MultiValuePropertyDescriptor.DEFAULT_NUMERIC_DELIMITER); }
/** * Returns a builder for a property having as value a list of strings. The * format of the individual items is the same as for {@linkplain #stringProperty(String) stringProperty}. * * @param name Name of the property to build * * @return A new builder */ public static GenericCollectionPropertyBuilder<String, List<String>> stringListProperty(String name) { return stringProperty(name).toList(); }
/** * Returns a builder for a property having as value a list of decimal numbers. The * format of the individual items is the same as for {@linkplain #doubleProperty(String) doubleProperty}. * * @param name Name of the property to build * * @return A new builder */ public static GenericCollectionPropertyBuilder<Double, List<Double>> doubleListProperty(String name) { return doubleProperty(name).toList().delim(MultiValuePropertyDescriptor.DEFAULT_NUMERIC_DELIMITER); }
/** * Returns a builder for a property having as value a list of long integers. The * format of the individual items is the same as for {@linkplain #longIntProperty(String)} longIntProperty}. * * @param name Name of the property to build * * @return A new builder */ public static GenericCollectionPropertyBuilder<Long, List<Long>> longIntListProperty(String name) { return longIntProperty(name).toList().delim(MultiValuePropertyDescriptor.DEFAULT_NUMERIC_DELIMITER); }
private static PropertyDescriptor<Boolean> booleanPropertyFor(String id, String label) { PropertyDescriptor<Boolean> prop = PROPERTY_DESCRIPTORS_BY_ID.get(id); if (prop != null) { return prop; } prop = PropertyFactory.booleanProperty(id).defaultValue(true).desc("Include " + label + " column").build(); PROPERTY_DESCRIPTORS_BY_ID.put(id, prop); return prop; }
public MockRule() { super(); setLanguage(LanguageRegistry.getLanguage("Dummy")); definePropertyDescriptor(PropertyFactory.intProperty("testIntProperty").desc("testIntProperty").require(inRange(1, 100)).defaultValue(1).build()); }
/** * 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); }