Class JDFDuration

  • All Implemented Interfaces:
    java.lang.Comparable<JDFDuration>

    public class JDFDuration
    extends java.lang.Object
    implements java.lang.Comparable<JDFDuration>
    • Constructor Summary

      Constructors 
      Constructor Description
      JDFDuration()
      Allocates a JDFDuration object and initializes it with 0
      JDFDuration​(double s)
      Allocates a JDFDuration object and initializes it with 's'
      JDFDuration​(int s, int m, int h, int d)
      Allocates a JDFDuration object and initializes it with days, hours, minutes, seconds
      JDFDuration​(long s)
      Allocates a JDFDuration object and initializes it with 's'
      JDFDuration​(java.lang.String strDuration)
      Allocates a JDFDuration object and initializes it with a value of strDuration, represented as a formatted duration string.
      JDFDuration​(JDFDate start, JDFDate end)
      creates a duration from two dates; may be negative if start later end
      JDFDuration​(JDFDuration d)
      Makes a copy of theJDFDuration object 'd'
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      JDFDuration addOffset​(int seconds, int minutes, int hours, int days)
      add a given offset to this
      note: multiple calls stack
      double addSeconds​(double seconds)
      add seconds to a duration
      int compareTo​(JDFDuration arg0)  
      static JDFDuration createDuration​(java.lang.String duration)
      does some heuristics to create a duration if duration is purely numeric, we guess days
      boolean equals​(java.lang.Object other)
      Compares two JDFDuration objects for equality.
      The result is true if and only if the argument is not null and is a JDFDuration object that represents the same duration, as this object.
      long getDuration()
      the duration in seconds
      java.lang.String getDurationISO()
      Format and return the duration set by 'setDuration(int i)' or 'setDurationString(String a_aDuration)' as an ISO conforming String.
      For example: 'P1Y2M3DT10H30M'
      long getDurationMillis()
      the duration in milliseconds
      int hashCode()
      hashCode: complements equals() to fulfill the equals/hashCode contract
      boolean isLonger​(JDFDuration x)
      isLess - tests if the duration of this JDFDuration is longer than the duration of the specified JDFDuration.
      boolean isShorter​(JDFDuration x)
      isShorter - tests if the duration of this JDFDuration is less than the duration of the specified JDFDuration.
      void setDuration​(double seconds)
      setDuration: sets a duration for this in seconds, including fractions.
      void setDuration​(long seconds)
      setDuration: sets a duration for this in seconds.
      boolean setDurationISO​(java.lang.String a_aDuration)
      Set a duration.
      java.lang.String toString()
      for debug purposes
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • JDFDuration

        public JDFDuration()
        Allocates a JDFDuration object and initializes it with 0
      • JDFDuration

        public JDFDuration​(JDFDuration d)
        Makes a copy of theJDFDuration object 'd'
        Parameters:
        d - the duration
      • JDFDuration

        public JDFDuration​(JDFDate start,
                           JDFDate end)
        creates a duration from two dates; may be negative if start later end
        Parameters:
        start - the starting point
        end - the end point
      • JDFDuration

        public JDFDuration​(double s)
        Allocates a JDFDuration object and initializes it with 's'
        Parameters:
        s - duration in seconds s may be fractional
      • JDFDuration

        public JDFDuration​(long s)
        Allocates a JDFDuration object and initializes it with 's'
        Parameters:
        s - duration in seconds s
      • JDFDuration

        public JDFDuration​(int s,
                           int m,
                           int h,
                           int d)
        Allocates a JDFDuration object and initializes it with days, hours, minutes, seconds
        Parameters:
        d -
        h -
        m -
        s -
      • JDFDuration

        public JDFDuration​(java.lang.String strDuration)
                    throws java.util.zip.DataFormatException
        Allocates a JDFDuration object and initializes it with a value of strDuration, represented as a formatted duration string.
        Duration examples:
      • "P1Y2M3DT10H30M"
      • "P8MT12M"
      • Durations with overflows, e.g. P13M (13 Months) are also handled and correctly output, in this case P1Y1M
Parameters:
strDuration - - formatted duration
Throws:
java.util.zip.DataFormatException - if strDuration is not a valid string representation of JDFDuration
  • Method Detail

    • createDuration

      public static JDFDuration createDuration​(java.lang.String duration)
      does some heuristics to create a duration if duration is purely numeric, we guess days
      Parameters:
      duration -
      Returns:
    • addSeconds

      public double addSeconds​(double seconds)
      add seconds to a duration
      Parameters:
      seconds - number of seconds to add
      Returns:
      the new duration in seconds
    • addOffset

      public JDFDuration addOffset​(int seconds,
                                   int minutes,
                                   int hours,
                                   int days)
      add a given offset to this
      note: multiple calls stack
      Parameters:
      seconds - seconds to add to this
      minutes - minutes to add to this
      hours - hours to add to this
      days - days to add to this
    • toString

      public java.lang.String toString()
      for debug purposes
      Overrides:
      toString in class java.lang.Object
      Returns:
      Object informations
    • getDurationISO

      public java.lang.String getDurationISO()
      Format and return the duration set by 'setDuration(int i)' or 'setDurationString(String a_aDuration)' as an ISO conforming String.
      For example: 'P1Y2M3DT10H30M'
      Returns:
      String - the duration formatted as an ISO 8601 conforming String if duration is '0' return value is 'PT00M'
    • setDurationISO

      public boolean setDurationISO​(java.lang.String a_aDuration)
      Set a duration. Durations are not bound to time or date and can be set independently
      Parameters:
      a_aDuration - formatted duration string 'P1Y2M3DT10H30M'
      Returns:
      true - the duration was set
      false - the duration was not set, because a NumberFormatException was thrown (-> parseInt())
    • setDuration

      public void setDuration​(long seconds)
      setDuration: sets a duration for this in seconds. This duration is used in multiple classes of the JDF (e.g. Heating time).
      Parameters:
      seconds - the duration in seconds.
    • setDuration

      public void setDuration​(double seconds)
      setDuration: sets a duration for this in seconds, including fractions. This duration is used in multiple classes of the JDF (e.g. Heating time).
      Parameters:
      seconds - the duration in seconds.
    • getDuration

      public long getDuration()
      the duration in seconds
      Returns:
      duration in seconds; '0' default
    • getDurationMillis

      public long getDurationMillis()
      the duration in milliseconds
      Returns:
      duration in seconds; '0' default
    • isLonger

      public boolean isLonger​(JDFDuration x)
      isLess - tests if the duration of this JDFDuration is longer than the duration of the specified JDFDuration. Compares the integer durations, thus -PT15S is shorter than -PT5S
      Parameters:
      x - the JDFDuration object to compare to this
      Returns:
      boolean - true if the duration of this JDFDuration is longer than the duration of the JDFDuration 'x'.
    • isShorter

      public boolean isShorter​(JDFDuration x)
      isShorter - tests if the duration of this JDFDuration is less than the duration of the specified JDFDuration. Compares the integer durations, thus -PT15S is shorter than -PT5S
      Parameters:
      x - the JDFDuration object to compare to this
      Returns:
      boolean - true if the duration of this JDFDuration is shorter than the duration of the JDFDuration 'x'.
    • equals

      public boolean equals​(java.lang.Object other)
      Compares two JDFDuration objects for equality.
      The result is true if and only if the argument is not null and is a JDFDuration object that represents the same duration, as this object.

      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      hashCode: complements equals() to fulfill the equals/hashCode contract
      Overrides:
      hashCode in class java.lang.Object
    • compareTo

      public int compareTo​(JDFDuration arg0)
      Specified by:
      compareTo in interface java.lang.Comparable<JDFDuration>
      Parameters:
      arg0 -
      Returns:
      See Also:
      Comparable.compareTo(java.lang.Object)