Package com.oss.asn1

Class ISO8601Duration

All Implemented Interfaces:
com.oss.asn1.Comparable, ISO8601TimeInterface, Serializable, Cloneable

public class ISO8601Duration extends AbstractISO8601Time
The ISO8601Duration class represents the ASN.1 DURATION type.
Since:
ASN.1/Java 6.0
See Also:
  • Constructor Details

    • ISO8601Duration

      public ISO8601Duration()
      The default constructor.
    • ISO8601Duration

      public ISO8601Duration(String value) throws BadTimeFormatException
      Constructs duration value from a string. String should be in the following basic format, "PnnYnnMnnDTnnHnnMnnS" or "PnnW" where nn is a one or more digit integer, which specifies an amount of years, months, weeks, days, hours, minutes or seconds depending on a designator which follows the "nn": Y,M,W,D,H,M or S. For reduced accuracy or decimal fraction representation any of the lowest order components may be omitted, decimal point with fractional value can be included into the lowest order component and zero valued components may be omitted. For example: "PT1.5H" represents one and a half an hour duration.
      Parameters:
      value - a string containing time of day value.
      Throws:
      BadTimeFormatException - if value has invalid format.
    • ISO8601Duration

      public ISO8601Duration(int years, int months, int days, int hours, int minutes, int seconds, ISO8601Duration.Fractional_part fractional_part)
      Constructs duration value from years, months, days, hour, minutes, seconds and fractional part components.
      Parameters:
      years - years value
      months - months value
      days - days value
      hours - hours value
      minutes - minutes value
      seconds - seconds value
      fractional_part - fractional part value
    • ISO8601Duration

      public ISO8601Duration(int weeks, ISO8601Duration.Fractional_part fractional_part)
      Constructs duration value weeks and fractional part components.
      Parameters:
      weeks - weeks value
      fractional_part - fractional part value
  • Method Details

    • clone

      public ISO8601Duration clone()
      Clone 'this' object.
      Returns:
      deep copy of 'this' object.
    • setValue

      public void setValue(String value) throws BadTimeFormatException
      Set an instance of this class from a String containing value notation of the DURATION.
      Specified by:
      setValue in class AbstractISO8601Time
      Parameters:
      value - a string containing duration value.
      Throws:
      BadTimeFormatException - if value has invalid format
    • getYears

      public final int getYears()
      Get the years component of 'this' object.
      Returns:
      int value indicating the years.
    • getMonths

      public final int getMonths()
      Get the months component of 'this' object.
      Returns:
      int value indicating the months.
    • getWeeks

      public final int getWeeks()
      Get the weeks component of 'this' object.
      Returns:
      int value indicating the weeks.
    • getDays

      public final int getDays()
      Get the days component of 'this' object.
      Returns:
      int value indicating the days.
    • getHours

      public final int getHours()
      Get the hours component of 'this' object.
      Returns:
      int value indicating the hours.
    • getMinutes

      public final int getMinutes()
      Get the minutes component of 'this' object.
      Returns:
      int value indicating the minutes.
    • getSeconds

      public final int getSeconds()
      Get the seconds component of 'this' object.
      Returns:
      int value indicating the seconds.
    • getFractional_part

      public final ISO8601Duration.Fractional_part getFractional_part()
      Get the fractional part component of 'this' object.
      Returns:
      fractional part.
    • setYears

      public final void setYears(int years)
      Set the years component of 'this' object.
      Parameters:
      years - the years to set.
    • setMonths

      public final void setMonths(int months)
      Set the months component of 'this' object.
      Parameters:
      months - the months to set.
    • setWeeks

      public final void setWeeks(int weeks)
      Set the weeks component of 'this' object.
      Parameters:
      weeks - the weeks to set.
    • setDays

      public final void setDays(int days)
      Set the days component of 'this' object.
      Parameters:
      days - the days to set.
    • setHours

      public final void setHours(int hours)
      Set the hours component of 'this' object.
      Parameters:
      hours - the hours to set.
    • setMinutes

      public final void setMinutes(int minutes)
      Set the minutes component of 'this' object.
      Parameters:
      minutes - the minutes to set.
    • setSeconds

      public final void setSeconds(int seconds)
      Set the seconds component of 'this' object.
      Parameters:
      seconds - the seconds to set.
    • setFractional_part

      public final void setFractional_part(ISO8601Duration.Fractional_part fractional_part)
      Set the fractional part component of 'this' object.
      Parameters:
      fractional_part - the fractional part to set.
    • get

      public int get(int field)
      Get field value.
      Parameters:
      field - field designator.
      Returns:
      field value.
    • set

      public void set(int field, int value)
      Set field value.
      Parameters:
      field - field designator.
      value - field value.
    • clear

      public void clear()
      Clears all the fields so they are set to UNDEFINED value.
    • equalTo

      public final boolean equalTo(ISO8601Duration that)
      Compare 'this' object to another ISO8601Duration object to see if their contents are the same.
      Parameters:
      that - the ISO8601Duration object to compare 'this' object to.
      Returns:
      true if contents of both objects are the same.
    • toFormattedString

      public final String toFormattedString(boolean isBer) throws com.oss.util.BadTimeValueException
      Converts this instance of ISO8601TimeInterface to the formatted string, suitable for the encoding.
      Specified by:
      toFormattedString in class AbstractISO8601Time
      Parameters:
      isBer - set to true if the time value is to be BER format
      Returns:
      string that contain the value, formatted accordingly to the ISO8601Duration format
      Throws:
      com.oss.util.BadTimeValueException - if the the value contains invalid components that make the formatting impossible
    • parseTime

      public ISO8601TimeInterface parseTime(String str, boolean isBer) throws BadTimeFormatException
      Takes formatted string that contains the value of ISO8601Duration, splits the string to the components and initializes this instance of the ISO8601Duration class. If the string has invalid format, a BadTimeFormatException exception is thrown. The method expects that the string has the format, specified in the description of the toFormattedString method.
      Specified by:
      parseTime in class AbstractISO8601Time
      Parameters:
      str - formatted string that contains the value of ISO8601Duration
      isBer - set to true if the time value is to be BER format
      Returns:
      reference to this object
      Throws:
      BadTimeFormatException - if str has invalid format
    • hashCode

      public int hashCode()
      Returns a hash code for this object
      Overrides:
      hashCode in class AbstractData
      Returns:
      a hash code for this object
    • getTypeName

      public String getTypeName()
      Returns the name of ASN.1 type this java class represents.
      Overrides:
      getTypeName in class AbstractData
      Returns:
      the name of the ASN.1 type.