org.cip4.jdflib.util
Class JDFDuration

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

public class JDFDuration
extends Object
implements Comparable<JDFDuration>

Author:
Dr. Rainer Prosi, Heidelberger Druckmaschinen AG Aug 10, 2009

Constructor Summary
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)
          Allocates a JDFDuration object and initializes it with 's'
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'
JDFDuration(String strDuration)
          Allocates a JDFDuration object and initializes it with a value of strDuration, represented as a formatted duration string.
 
Method Summary
 double addSeconds(double seconds)
          add seconds to a duration
 int compareTo(JDFDuration arg0)
           
static JDFDuration createDuration(String duration)
          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.
 int getDuration()
          the duration in seconds
 String getDurationISO()
          Format and return the duration set by 'setDuration(int i)' or 'setDurationString(String a_aDuration)' as an ISO conforming String.
 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(int seconds)
          setDuration: sets a duration for this in seconds.
 boolean setDurationISO(String a_aDuration)
          Set a duration.
 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(int s)
Allocates a JDFDuration object and initializes it with 's'

Parameters:
s - duration in seconds s may be fractional

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 Detail

    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

    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(int 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 int getDuration()
    the duration in seconds

    Returns:
    int - the 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:
    Comparable.compareTo(java.lang.Object)


    Copyright © 2013. All Rights Reserved.