Class DurationPropertyDefinition

  • All Implemented Interfaces:
    Comparable<PropertyDefinition<?>>, Comparator<Long>

    public final class DurationPropertyDefinition
    extends PropertyDefinition<Long>
    Duration property definition.

    A duration property definition comprises of:

    • a base unit - specifies the minimum granularity which can be used to specify duration property values. For example, if the base unit is in seconds then values represented in milliseconds will not be permitted. The default base unit is seconds
    • an optional maximum unit - specifies the biggest duration unit which can be used to specify duration property values. Values presented in units greater than this unit will not be permitted. There is no default maximum unit
    • lower limit - specifies the smallest duration permitted by the property. The default lower limit is 0 and can never be less than 0
    • an optional upper limit - specifies the biggest duration permitted by the property. By default, there is no upper limit
    • support for unlimited durations - when permitted users can specify "unlimited" durations. These are represented using the decoded value, -1, or the encoded string value "unlimited". By default, unlimited durations are not permitted. In addition, it is not possible to define an upper limit and support unlimited values.
    Decoded values are represented using long values in the base unit defined for the duration property definition.
    • Method Detail

      • createBuilder

        public static DurationPropertyDefinition.Builder createBuilder​(AbstractManagedObjectDefinition<?,​?> d,
                                                                       String propertyName)
        Create a duration property definition builder.
        Parameters:
        d - The managed object definition associated with this property definition.
        propertyName - The property name.
        Returns:
        Returns the new integer property definition builder.
      • getBaseUnit

        public DurationUnit getBaseUnit()
        Get the base unit for this property definition (values including limits are specified in this unit).
        Returns:
        Returns the base unit for this property definition (values including limits are specified in this unit).
      • getMaximumUnit

        public DurationUnit getMaximumUnit()
        Get the maximum unit for this property definition if specified.
        Returns:
        Returns the maximum unit for this property definition, or null if there is no maximum unit.
      • getLowerLimit

        public long getLowerLimit()
        Get the lower limit in milli-seconds.
        Returns:
        Returns the lower limit in milli-seconds.
      • getUpperLimit

        public Long getUpperLimit()
        Get the upper limit in milli-seconds.
        Returns:
        Returns the upper limit in milli-seconds, or null if there is no upper limit.
      • isAllowUnlimited

        public boolean isAllowUnlimited()
        Determine whether this property allows unlimited durations.
        Returns:
        Returns true if this this property allows unlimited durations.
      • validateValue

        public void validateValue​(Long value)
        Description copied from class: PropertyDefinition
        Determine if the provided property value is valid according to this property definition.
        Specified by:
        validateValue in class PropertyDefinition<Long>
        Parameters:
        value - The property value (must not be null).
      • encodeValue

        public String encodeValue​(Long value)
        Description copied from class: PropertyDefinition
        Encode the provided property value into its string representation.

        This default implementation simply returns invokes the Object.toString() method on the provided value.

        Overrides:
        encodeValue in class PropertyDefinition<Long>
        Parameters:
        value - The property value (must not be null).
        Returns:
        Returns the encoded property string value.
      • decodeValue

        public Long decodeValue​(String value)
        Description copied from class: PropertyDefinition
        Parse and validate a string representation of a property value.
        Specified by:
        decodeValue in class PropertyDefinition<Long>
        Parameters:
        value - The property string value (must not be null).
        Returns:
        Returns the decoded property value.
      • accept

        public <R,​P> R accept​(PropertyDefinitionVisitor<R,​P> v,
                                    P p)
        Description copied from class: PropertyDefinition
        Apply a visitor to this property definition.
        Specified by:
        accept in class PropertyDefinition<Long>
        Type Parameters:
        R - The return type of the visitor's methods.
        P - The type of the additional parameters to the visitor's methods.
        Parameters:
        v - The property definition visitor.
        p - Optional additional visitor parameter.
        Returns:
        Returns a result as specified by the visitor.
      • accept

        public <R,​P> R accept​(PropertyValueVisitor<R,​P> v,
                                    Long value,
                                    P p)
        Description copied from class: PropertyDefinition
        Apply a visitor to a property value associated with this property definition.
        Specified by:
        accept in class PropertyDefinition<Long>
        Type Parameters:
        R - The return type of the visitor's methods.
        P - The type of the additional parameters to the visitor's methods.
        Parameters:
        v - The property value visitor.
        value - The property value.
        p - Optional additional visitor parameter.
        Returns:
        Returns a result as specified by the visitor.
      • toString

        public void toString​(StringBuilder builder)
        Description copied from class: PropertyDefinition
        Append a string representation of the property definition to the provided string builder.

        This simple implementation just outputs the propertyName of the property definition. Sub-classes should override this method to provide more complete string representations.

        Overrides:
        toString in class PropertyDefinition<Long>
        Parameters:
        builder - The string builder where the string representation should be appended.
      • compare

        public int compare​(Long o1,
                           Long o2)
        Description copied from class: PropertyDefinition
        Compares two property values for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

        This default implementation normalizes both values using PropertyDefinition.normalizeValue(Object) and then performs a case-sensitive string comparison.

        Specified by:
        compare in interface Comparator<Long>
        Overrides:
        compare in class PropertyDefinition<Long>
        Parameters:
        o1 - the first object to be compared.
        o2 - the second object to be compared.
        Returns:
        a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.