Skip navigation links
dk.heick.properties.types.custom

Class RangeVO<T extends Comparable<T>>

    • Constructor Detail

      • RangeVO

        public RangeVO(PropertyType<T> rangeType,
                       T from,
                       T to,
                       String divider)
        Constructor
        Parameters:
        rangeType - the PropertyType which can convert a String to type T.
        from - the FROM value of type T, this must be less than or equal to TO.
        to - the TO value of type T, this must be greater than or equal to FROM.
        divider - the divider which is between FROM and TO, is must be not null and none empty.
    • Method Detail

      • getRangeType

        public PropertyType<T> getRangeType()
        Gets the PropertyType which can convert a String to type T.
        Returns:
        the propertyType.
      • getFrom

        public final T getFrom()
        Gets the FROM value of type T.
        Returns:
        the FROM value of type T.
      • getTo

        public final T getTo()
        Gets the TO value of type T.
        Returns:
        the TO value of type T.
      • getDivider

        public final String getDivider()
        Gets the divider
        Returns:
        the divider
      • validate

        public void validate(String propertyName)
                      throws PropertyException
        Validates the attributes of this object instance.
        Parameters:
        propertyName - the name of the Property of which this instance belongs to.
        Throws:
        PropertyException - if either RangeType, FROM or TO is null, or FROM is greater than TO.
      • toString

        public String toString()
        Constructs a String version of the Range.
        Overrides:
        toString in class Object
        Returns:
        A toString version of FROM, than the DIVIDER and lastly a toString version of TO.
      • isInRange

        public boolean isInRange(T value)
        Validates if the value of type T is inside the range, FROM and TO is both inclusive.
        Parameters:
        value - the the value of type T.
        Returns:
        true if the value is inside the FROM and TO range. If value is null, than false is returned.
      • isStringInRange

        public boolean isStringInRange(String value)
        Converts a string to a type T using the RangeType, is validates if it is inside the range, FROM and TO is both inclusive.
        Parameters:
        value - the string value
        Returns:
        true if the string value is succesfully converted to type T and is inside the range, otherwise false.
        See Also:
        isInRange(Comparable)