Package net.sourceforge.pmd.properties
Class EnumeratedMultiProperty<E>
- java.lang.Object
-
- net.sourceforge.pmd.properties.EnumeratedMultiProperty<E>
-
- Type Parameters:
E- The type of the values
- All Implemented Interfaces:
java.lang.Comparable<PropertyDescriptor<?>>,EnumeratedPropertyDescriptor<E,java.util.List<E>>,MultiValuePropertyDescriptor<E>,PropertyDescriptor<java.util.List<E>>
public final class EnumeratedMultiProperty<E> extends java.lang.Object implements EnumeratedPropertyDescriptor<E,java.util.List<E>>
Multi-valued property which can take only a fixed set of values of any type, then selected via String labels. The mappings method returns the set of mappings between the labels and their values.- Version:
- Refactored June 2017 (6.0.0)
- Author:
- Brian Remedios, Clément Fournier
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEnumeratedMultiProperty.EnumMultiPBuilder<E>
-
Field Summary
-
Fields inherited from interface net.sourceforge.pmd.properties.MultiValuePropertyDescriptor
DEFAULT_DELIMITER, DEFAULT_NUMERIC_DELIMITER
-
-
Constructor Summary
Constructors Constructor Description EnumeratedMultiProperty(java.lang.String theName, java.lang.String theDescription, java.lang.String[] theLabels, E[] theChoices, int[] choiceIndices, float theUIOrder)Deprecated.EnumeratedMultiProperty(java.lang.String theName, java.lang.String theDescription, java.lang.String[] theLabels, E[] theChoices, int[] choiceIndices, java.lang.Class<E> valueType, float theUIOrder)Deprecated.EnumeratedMultiProperty(java.lang.String theName, java.lang.String theDescription, java.util.Map<java.lang.String,E> choices, java.util.List<E> defaultValues, java.lang.Class<E> valueType, float theUIOrder)Constructor using a map to define the label-value mappings.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddAttributesTo(java.util.Map<PropertyDescriptorField,java.lang.String> attributes)Adds this property's attributes to the map.java.lang.StringasDelimitedString(java.util.List<V> values)Formats the object onto a string suitable for storage within the property map.java.lang.StringasString(E item)Returns a string representation of the value, even if it's null.java.util.Map<PropertyDescriptorField,java.lang.String>attributeValuesById()Returns a map representing all the property attributes of the receiver in string form.intcompareTo(PropertyDescriptor<?> otherProperty)protected EcreateFrom(java.lang.String toParse)Parse a string and returns an instance of a single value (not a list).protected java.lang.StringdefaultAsString()Returns a string representation of the default value.java.util.List<V>defaultValue()Default value to use when the user hasn't specified one or when they wish to revert to a known-good state.java.lang.Stringdescription()Describes the property and the role it plays within the rule it is specified for.booleanequals(java.lang.Object obj)java.lang.StringerrorFor(java.util.List<E> values)Validation function that returns a diagnostic error message for a sample property value.inthashCode()booleanisDefinedExternally()True if this descriptor was defined in the ruleset xml.booleanisMultiValue()Returns whether the property is multi-valued, i.e.java.util.Map<java.lang.String,E>mappings()Returns an immutable map of the label - value mappings defined by this descriptor.charmultiValueDelimiter()Return the character being used to delimit multiple property values within a single string.java.lang.Stringname()The name of the property without spaces as it serves as the key into the property map.static <E> EnumeratedMultiProperty.EnumMultiPBuilder<E>named(java.lang.String name)intpreferredRowCount()If the datatype is a String then return the preferred number of rows to allocate in the text widget, returns a value of one for all other types.java.lang.StringpropertyErrorFor(Rule rule)A convenience method that returns an error string if the rule holds onto a property value that has a problem.java.lang.StringtoString()java.lang.Class<E>type()Denotes the value datatype.floatuiOrder()Denotes the relative order the property field should occupy if we are using an auto-generated UI to display and edit property values.protected java.lang.StringvalueErrorFor(V value)Checks a single value for a "missing value" error.java.util.List<V>valueFrom(java.lang.String valueString)Returns the value represented by this string.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sourceforge.pmd.properties.PropertyDescriptor
asDelimitedString, attributeValuesById, defaultValue, description, isDefinedExternally, isMultiValue, name, preferredRowCount, propertyErrorFor, uiOrder, valueFrom
-
-
-
-
Constructor Detail
-
EnumeratedMultiProperty
@Deprecated public EnumeratedMultiProperty(java.lang.String theName, java.lang.String theDescription, java.lang.String[] theLabels, E[] theChoices, int[] choiceIndices, java.lang.Class<E> valueType, float theUIOrder)Deprecated.UseEnumeratedMultiProperty(String, String, Map, List, Class, float). Will be removed in 7.0.0Constructor using arrays to define the label-value mappings. The correct construction of the property depends on the correct ordering of the arrays.- Parameters:
theName- NametheDescription- DescriptiontheLabels- Labels of the choicestheChoices- Values that can be chosenchoiceIndices- Indices of the default valuesvalueType- Type of the valuestheUIOrder- UI order
-
EnumeratedMultiProperty
@Deprecated public EnumeratedMultiProperty(java.lang.String theName, java.lang.String theDescription, java.lang.String[] theLabels, E[] theChoices, int[] choiceIndices, float theUIOrder)Deprecated.UseEnumeratedMultiProperty(String, String, Map, List, Class, float). Will be removed in 7.0.0Constructor using arrays to define the label-value mappings. The correct construction of the property depends on the correct ordering of the arrays.- Parameters:
theName- NametheDescription- DescriptiontheLabels- Labels of the choicestheChoices- Values that can be chosenchoiceIndices- Indices of the default valuestheUIOrder- UI order
-
EnumeratedMultiProperty
public EnumeratedMultiProperty(java.lang.String theName, java.lang.String theDescription, java.util.Map<java.lang.String,E> choices, java.util.List<E> defaultValues, java.lang.Class<E> valueType, float theUIOrder)Constructor using a map to define the label-value mappings. The default values are specified with a list.- Parameters:
theName- NametheDescription- Descriptionchoices- Map of labels to valuesdefaultValues- List of default valuesvalueType- Type of the valuestheUIOrder- UI order
-
-
Method Detail
-
mappings
public java.util.Map<java.lang.String,E> mappings()
Description copied from interface:EnumeratedPropertyDescriptorReturns an immutable map of the label - value mappings defined by this descriptor.- Specified by:
mappingsin interfaceEnumeratedPropertyDescriptor<E,java.util.List<E>>- Returns:
- an immutable map of the label - value mappings defined by this descriptor.
-
type
public java.lang.Class<E> type()
Description copied from interface:PropertyDescriptorDenotes the value datatype. For multi value properties, this is not the List class but the list's component class.- Specified by:
typein interfaceMultiValuePropertyDescriptor<E>- Specified by:
typein interfacePropertyDescriptor<E>- Returns:
- Class literal of the value type
-
errorFor
public java.lang.String errorFor(java.util.List<E> values)
Description copied from interface:PropertyDescriptorValidation function that returns a diagnostic error message for a sample property value. Returns null if the value is acceptable.- Specified by:
errorForin interfacePropertyDescriptor<E>- Parameters:
values- The value to check.- Returns:
- A diagnostic message.
-
createFrom
protected E createFrom(java.lang.String toParse)
Parse a string and returns an instance of a single value (not a list).- Parameters:
toParse- String to parse- Returns:
- An instance of a value
-
asString
public java.lang.String asString(E item)
Returns a string representation of the value, even if it's null.- Parameters:
item- The value to describe- Returns:
- A string representation of the value
-
named
public static <E> EnumeratedMultiProperty.EnumMultiPBuilder<E> named(java.lang.String name)
-
isMultiValue
public final boolean isMultiValue()
Description copied from interface:PropertyDescriptorReturns whether the property is multi-valued, i.e. an array of strings,As unary property rule properties will return a value of one, you must use the get/setProperty accessors when working with the actual values. When working with multi-value properties then the get/setProperties accessors must be used.
- Specified by:
isMultiValuein interfacePropertyDescriptor<V>- Returns:
- boolean
-
propertyErrorFor
public java.lang.String propertyErrorFor(Rule rule)
Description copied from interface:PropertyDescriptorA convenience method that returns an error string if the rule holds onto a property value that has a problem. Returns null otherwise.- Specified by:
propertyErrorForin interfacePropertyDescriptor<V>- Parameters:
rule- Rule- Returns:
- String
-
valueErrorFor
protected java.lang.String valueErrorFor(V value)
Checks a single value for a "missing value" error.- Parameters:
value- Value to check- Returns:
- A descriptive String of the error or null if there was none
-
defaultAsString
protected java.lang.String defaultAsString()
Returns a string representation of the default value.- Returns:
- A string representation of the default value.
-
defaultValue
public java.util.List<V> defaultValue()
Description copied from interface:PropertyDescriptorDefault value to use when the user hasn't specified one or when they wish to revert to a known-good state.- Specified by:
defaultValuein interfacePropertyDescriptor<V>- Returns:
- Object
-
multiValueDelimiter
public char multiValueDelimiter()
Description copied from interface:MultiValuePropertyDescriptorReturn the character being used to delimit multiple property values within a single string. You must ensure that this character does not appear within any rule property values to avoid deserialization errors.- Specified by:
multiValueDelimiterin interfaceMultiValuePropertyDescriptor<V>- Returns:
- char
-
asDelimitedString
public final java.lang.String asDelimitedString(java.util.List<V> values)
Description copied from interface:PropertyDescriptorFormats the object onto a string suitable for storage within the property map.- Specified by:
asDelimitedStringin interfacePropertyDescriptor<V>- Parameters:
values- Object- Returns:
- String
-
valueFrom
public java.util.List<V> valueFrom(java.lang.String valueString) throws java.lang.IllegalArgumentExceptionDescription copied from interface:PropertyDescriptorReturns the value represented by this string.- Specified by:
valueFromin interfacePropertyDescriptor<V>- Parameters:
valueString- The string to parse- Returns:
- The value represented by the string
- Throws:
java.lang.IllegalArgumentException- if the given string cannot be parsed
-
addAttributesTo
protected void addAttributesTo(java.util.Map<PropertyDescriptorField,java.lang.String> attributes)
Adds this property's attributes to the map. Subclasses can override this to add morePropertyDescriptorField.- Parameters:
attributes- The map to fill
-
description
public java.lang.String description()
Description copied from interface:PropertyDescriptorDescribes the property and the role it plays within the rule it is specified for. Could be used in a tooltip.- Specified by:
descriptionin interfacePropertyDescriptor<T>- Returns:
- String
-
uiOrder
public float uiOrder()
Description copied from interface:PropertyDescriptorDenotes the relative order the property field should occupy if we are using an auto-generated UI to display and edit property values. If the value returned has a non-zero fractional part then this is can be used to place adjacent fields on the same row.Example:
..would have their fields placed like:
name -> 0.0 description 1.0 minValue -> 2.0 maxValue -> 2.1
name: [ ] description: [ ] minimum: [ ] maximum: [ ]- Specified by:
uiOrderin interfacePropertyDescriptor<T>- Returns:
- float
-
compareTo
public final int compareTo(PropertyDescriptor<?> otherProperty)
- Specified by:
compareToin interfacejava.lang.Comparable<T>
-
preferredRowCount
public int preferredRowCount()
Description copied from interface:PropertyDescriptorIf the datatype is a String then return the preferred number of rows to allocate in the text widget, returns a value of one for all other types. Useful for multi-line XPATH editors.- Specified by:
preferredRowCountin interfacePropertyDescriptor<T>- Returns:
- int
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
name
public java.lang.String name()
Description copied from interface:PropertyDescriptorThe name of the property without spaces as it serves as the key into the property map.- Specified by:
namein interfacePropertyDescriptor<T>- Returns:
- String
-
attributeValuesById
public final java.util.Map<PropertyDescriptorField,java.lang.String> attributeValuesById()
Description copied from interface:PropertyDescriptorReturns a map representing all the property attributes of the receiver in string form.- Specified by:
attributeValuesByIdin interfacePropertyDescriptor<T>- Returns:
- map
-
isDefinedExternally
public boolean isDefinedExternally()
Description copied from interface:PropertyDescriptorTrue if this descriptor was defined in the ruleset xml. This precision is necessary for theRuleSetWriterto write out the property correctly: if it was defined externally, then its definition must be written out, otherwise only its value.- Specified by:
isDefinedExternallyin interfacePropertyDescriptor<T>- Returns:
- True if the descriptor was defined in xml
-
-