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
  • Method Details

    • getParser

      protected PropertySerializer<T> getParser()
    • require

      public PropertyBuilder.GenericPropertyBuilder<T> 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 class PropertyBuilder<B extends PropertyBuilder<B,T>,T>
      Parameters:
      constraint - The constraint
      Returns:
      The same builder
      See Also:
    • 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

      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 handling Optional<T>. The validators already added are used on the validator property. If the default value was previously set, it is converted to an optional with Optional.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 class PropertyBuilder<B extends PropertyBuilder<B,T>,T>
      Returns:
      The built descriptor