net.sourceforge.pmd.lang.rule.properties
Class AbstractProperty<T>

java.lang.Object
  extended by net.sourceforge.pmd.lang.rule.properties.AbstractProperty<T>
Type Parameters:
T -
All Implemented Interfaces:
Comparable<PropertyDescriptor<?>>, PropertyDescriptor<T>
Direct Known Subclasses:
AbstractEnumeratedProperty, AbstractPackagedProperty, AbstractScalarProperty, CharacterMultiProperty, CharacterProperty, FileProperty, StringMultiProperty, StringProperty

public abstract class AbstractProperty<T>
extends Object
implements PropertyDescriptor<T>

Author:
Brian Remedios

Field Summary
static char DEFAULT_DELIMITER
          Default delimiter for multi properties.
static char DEFAULT_NUMERIC_DELIMITER
          Default delimiter for numeric properties.
 
Constructor Summary
protected AbstractProperty(String theName, String theDescription, T theDefault, float theUIOrder)
           
protected AbstractProperty(String theName, String theDescription, T theDefault, float theUIOrder, char delimiter)
          Constructor for AbstractPMDProperty.
 
Method Summary
protected  void addAttributesTo(Map<String,String> attributes)
           
static boolean areEqual(Object value, Object otherValue)
           
 String asDelimitedString(T values)
          Formats the object onto a string suitable for storage within the property map.
 String asDelimitedString(T values, char delimiter)
          Return the specified values as a single string using the delimiter.
protected  String asString(Object value)
          Return the value as a string that can be easily recognized and parsed when we see it again.
 Map<String,String> attributeValuesById()
          Returns a map representing all the property attributes of the receiver in string form.
 Object[][] choices()
          Returns a set of choice tuples if available, returns null if none are defined.
 int compareTo(PropertyDescriptor<?> otherProperty)
          
protected  String defaultAsString()
           
protected  boolean defaultHasNullValue()
          Method defaultHasNullValue.
 T defaultValue()
          Default value to use when the user hasn't specified one or when they wish to revert to a known-good state.
 String description()
          Describes the property and the role it plays within the rule it is specified for.
 boolean equals(Object obj)
          
 String errorFor(Object value)
          Validation function that returns a diagnostic error message for a sample property value.
 int hashCode()
          
protected static boolean isArray(Object value)
           
 boolean isMultiValue()
          Returns whether the property is multi-valued, i.e.
 boolean isRequired()
          Denotes whether the value is required before the rule can be executed.
 char multiValueDelimiter()
          Return the character being used to delimit multiple property values within a single string.
 String name()
          The name of the property without spaces as it serves as the key into the property map.
 int preferredRowCount()
          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.
 String propertyErrorFor(Rule rule)
          A convenience method that returns an error string if the rule holds onto a property value that has a problem.
 String toString()
          
protected  String typeErrorFor(Object value)
           
 float uiOrder()
          Denotes the relative order the property field should occupy if we are using an auto-generated UI to display and edit property values.
protected  String valueErrorFor(Object value)
           
protected  String valuesErrorFor(Object value)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sourceforge.pmd.PropertyDescriptor
type, valueFrom
 

Field Detail

DEFAULT_DELIMITER

public static final char DEFAULT_DELIMITER
Default delimiter for multi properties. Note: Numeric properties usual use the 44.

See Also:
Constant Field Values

DEFAULT_NUMERIC_DELIMITER

public static final char DEFAULT_NUMERIC_DELIMITER
Default delimiter for numeric properties.

See Also:
Constant Field Values
Constructor Detail

AbstractProperty

protected AbstractProperty(String theName,
                           String theDescription,
                           T theDefault,
                           float theUIOrder)

AbstractProperty

protected AbstractProperty(String theName,
                           String theDescription,
                           T theDefault,
                           float theUIOrder,
                           char delimiter)
Constructor for AbstractPMDProperty.

Parameters:
theName - String
theDescription - String
theDefault - Object
theUIOrder - float
Throws:
IllegalArgumentException
Method Detail

multiValueDelimiter

public char multiValueDelimiter()
Return 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:
multiValueDelimiter in interface PropertyDescriptor<T>
Returns:
char

name

public String name()
The name of the property without spaces as it serves as the key into the property map.

Specified by:
name in interface PropertyDescriptor<T>
Returns:
String

description

public String description()
Describes the property and the role it plays within the rule it is specified for. Could be used in a tooltip.

Specified by:
description in interface PropertyDescriptor<T>
Returns:
String

defaultValue

public T defaultValue()
Default value to use when the user hasn't specified one or when they wish to revert to a known-good state.

Specified by:
defaultValue in interface PropertyDescriptor<T>
Returns:
Object

defaultHasNullValue

protected boolean defaultHasNullValue()
Method defaultHasNullValue.

Returns:
boolean

isMultiValue

public boolean isMultiValue()
Returns 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:
isMultiValue in interface PropertyDescriptor<T>
Returns:
boolean

isRequired

public boolean isRequired()
Denotes whether the value is required before the rule can be executed. Has no meaning for primitive types such as booleans, ints, etc.

Specified by:
isRequired in interface PropertyDescriptor<T>
Returns:
boolean

uiOrder

public float uiOrder()
Denotes 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: name -> 0.0 description 1.0 minValue -> 2.0 maxValue -> 2.1 ..would have their fields placed like: name: [ ] description: [ ] minimum: [ ] maximum: [ ]

Specified by:
uiOrder in interface PropertyDescriptor<T>
Returns:
float

asString

protected String asString(Object value)
Return the value as a string that can be easily recognized and parsed when we see it again.

Parameters:
value - Object
Returns:
String

asDelimitedString

public String asDelimitedString(T values)
Formats the object onto a string suitable for storage within the property map.

Specified by:
asDelimitedString in interface PropertyDescriptor<T>
Parameters:
values - Object
Returns:
String

asDelimitedString

public String asDelimitedString(T values,
                                char delimiter)
Return the specified values as a single string using the delimiter.

Parameters:
values - Object
delimiter - char
Returns:
String
See Also:
PropertyDescriptor.asDelimitedString(Object)

compareTo

public int compareTo(PropertyDescriptor<?> otherProperty)

Specified by:
compareTo in interface Comparable<PropertyDescriptor<?>>

errorFor

public String errorFor(Object value)
Validation function that returns a diagnostic error message for a sample property value. Returns null if the value is acceptable.

Specified by:
errorFor in interface PropertyDescriptor<T>
Parameters:
value - Object
Returns:
String

valueErrorFor

protected String valueErrorFor(Object value)
Parameters:
value - Object
Returns:
String

valuesErrorFor

protected String valuesErrorFor(Object value)
Parameters:
value - Object
Returns:
String

isArray

protected static boolean isArray(Object value)
Parameters:
value - Object
Returns:
boolean

typeErrorFor

protected String typeErrorFor(Object value)
Parameters:
value - Object
Returns:
String

propertyErrorFor

public String propertyErrorFor(Rule rule)
A convenience method that returns an error string if the rule holds onto a property value that has a problem. Returns null otherwise.

Specified by:
propertyErrorFor in interface PropertyDescriptor<T>
Parameters:
rule - Rule
Returns:
String

choices

public Object[][] choices()
Returns a set of choice tuples if available, returns null if none are defined.

Specified by:
choices in interface PropertyDescriptor<T>
Returns:
Object[][]

preferredRowCount

public int preferredRowCount()
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. Useful for multi-line XPATH editors.

Specified by:
preferredRowCount in interface PropertyDescriptor<T>
Returns:
int

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

toString

public String toString()

Overrides:
toString in class Object

defaultAsString

protected String defaultAsString()
Returns:
String

areEqual

public static final boolean areEqual(Object value,
                                     Object otherValue)
Parameters:
value - Object
otherValue - Object
Returns:
boolean

attributeValuesById

public Map<String,String> attributeValuesById()
Description copied from interface: PropertyDescriptor
Returns a map representing all the property attributes of the receiver in string form.

Specified by:
attributeValuesById in interface PropertyDescriptor<T>
Returns:
Map

addAttributesTo

protected void addAttributesTo(Map<String,String> attributes)
Parameters:
attributes - Map


Copyright © 2002-2015 InfoEther. All Rights Reserved.