Package net.sourceforge.pmd.properties
Class PropertyBuilder.GenericPropertyBuilder<T>
- java.lang.Object
-
- net.sourceforge.pmd.properties.PropertyBuilder<B,T>
-
- net.sourceforge.pmd.properties.PropertyBuilder.GenericPropertyBuilder<T>
-
- Type Parameters:
T
- Type of values the property handles
- Enclosing class:
- PropertyBuilder<B extends PropertyBuilder<B,T>,T>
public static class PropertyBuilder.GenericPropertyBuilder<T> extends PropertyBuilder<B,T>
Generic builder for a single-value property.- Author:
- Clément Fournier
- Since:
- 6.10.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.sourceforge.pmd.properties.PropertyBuilder
PropertyBuilder.GenericCollectionPropertyBuilder<V,C extends Iterable<V>>, PropertyBuilder.GenericPropertyBuilder<T>, PropertyBuilder.RegexPropertyBuilder
-
-
Field Summary
-
Fields inherited from class net.sourceforge.pmd.properties.PropertyBuilder
isXPathAvailable, typeId
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PropertyDescriptor<T>
build()
Builds the descriptor and returns it.protected PropertySerializer<T>
getParser()
<C extends Iterable<T>>
PropertyBuilder.GenericCollectionPropertyBuilder<T,C>map(Collector<? super T,?,? extends C> collector)
Returns a new builder that can be used to build a property with value type<C>
.B
require(PropertyConstraint<? super T> constraint)
Add a constraint on the values that this property may take.PropertyBuilder.GenericCollectionPropertyBuilder<T,List<T>>
toList()
Returns a new builder that can be used to build a property handling lists of Ts.PropertyBuilder.GenericPropertyBuilder<Optional<T>>
toOptional(String missingValue)
Returns a new builder that can be used to build a property handlingOptional<T>
.-
Methods inherited from class net.sourceforge.pmd.properties.PropertyBuilder
availableInXPath, defaultValue, desc, getName
-
-
-
-
Method Detail
-
getParser
protected PropertySerializer<T> getParser()
-
require
public B require(PropertyConstraint<? super T> constraint)
Description copied from class:PropertyBuilder
Add a constraint on the values that this property may take. The validity of values will be checked when parsing the XML, and invalid values will be reported. A rule will never be run if some of its properties violate some constraints.Constraints should be independent from each other, and should perform no side effects. PMD doesn't specify how many times a constraint predicate will be executed, or in what order.
- Specified by:
require
in classPropertyBuilder<B extends PropertyBuilder<B,T>,T>
- Parameters:
constraint
- The constraint- Returns:
- The same builder
- See Also:
NumericConstraints
-
toList
public PropertyBuilder.GenericCollectionPropertyBuilder<T,List<T>> toList()
Returns a new builder that can be used to build a property handling lists of Ts. The validators already added are converted to list validators. The default value cannot have previously been set.- Returns:
- A new list property builder
- Throws:
IllegalStateException
- if the default value has already been set- See Also:
map(Collector)
-
map
public <C extends Iterable<T>> PropertyBuilder.GenericCollectionPropertyBuilder<T,C> map(Collector<? super T,?,? extends C> collector)
Returns a new builder that can be used to build a property with value type<C>
. The validators already added are converted to collection validators. The default value cannot have previously been set. The returned builder will support conversion to and from a delimited string.Example usage:
// this can be set with // <value>a,b,c</value> PropertyDescriptor<Set<String>> whitelistSet = PropertyFactory.stringProperty("whitelist") .desc(...) .map(Collectors.toSet()) .emptyDefaultValue() .build();
- Returns:
- A new list property builder
- Throws:
IllegalStateException
- if the default value has already been set
-
toOptional
public PropertyBuilder.GenericPropertyBuilder<Optional<T>> toOptional(String missingValue)
Returns a new builder that can be used to build a property handlingOptional<T>
. The validators already added are used on the validator property. If the default value was previously set, it is converted to an optional withOptional.of(Object)
.- Parameters:
missingValue
- The string representation of the empty optional.- Returns:
- A new property builder for an optional.
-
build
public PropertyDescriptor<T> build()
Description copied from class:PropertyBuilder
Builds the descriptor and returns it.- Specified by:
build
in classPropertyBuilder<B extends PropertyBuilder<B,T>,T>
- Returns:
- The built descriptor
-
-