Class JDFDuration

java.lang.Object
org.cip4.jdflib.util.JDFDuration
All Implemented Interfaces:
Comparable<JDFDuration>

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

    Constructors
    Constructor
    Description
    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(String strDuration)
    Allocates a JDFDuration object and initializes it with a value of strDuration, represented as a formatted duration string.
    creates a duration from two dates; may be negative if start later end
    Makes a copy of theJDFDuration object 'd'
  • Method Summary

    Modifier and Type
    Method
    Description
    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
     
    does some heuristics to create a duration if duration is purely numeric, we guess days
    boolean
    equals(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
    the duration in seconds
    Format and return the duration set by 'setDuration(int i)' or 'setDurationString(String a_aDuration)' as an ISO conforming String.
    For example: 'P1Y2M3DT10H30M'
    long
    the duration in milliseconds
    int
    hashCode: complements equals() to fulfill the equals/hashCode contract
    boolean
    isLess - tests if the duration of this JDFDuration is longer than the duration of the specified JDFDuration.
    boolean
    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(String a_aDuration)
    Set a duration.
    for debug purposes

    Methods inherited from class java.lang.Object

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

    • 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(String strDuration) throws 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:
      DataFormatException - if strDuration is not a valid string representation of JDFDuration
  • Method Details

    • createDuration

      public static JDFDuration createDuration(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 String toString()
      for debug purposes
      Overrides:
      toString in class Object
      Returns:
      Object informations
    • getDurationISO

      public 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(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(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 Object
    • hashCode

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

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