texsoft.java.util
Class XsTime

java.lang.Object
  |
  +--texsoft.java.util.XsTime
All Implemented Interfaces:
java.lang.Comparable

public class XsTime
extends java.lang.Object
implements java.lang.Comparable

The XsTime class represents a simple time value.

It simply stores hours, minutes and seconds values without the other features of Date and Calendar.

An usefull feature of this class is that it implements the Comparable interface to allow searching and ordering.


Constructor Summary
XsTime()
          Creates a new XsTime object set to time 0:00:00.
XsTime(int h, int m, int s)
          Creates new XsTime object with given hour, minute, second values.
XsTime(java.lang.String s)
          Create a new XsTime object set to the time value from the string in the format HH[:MM[:SS]].
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this XsTime object with the specified object for order.
 int differenceMinutes(XsTime other)
          Returns the difference in minutes between the this object and other.
static int differenceMinutes(XsTime start, XsTime stop)
          Returns the diference in minutes between start and stop.
 int differenceSeconds(XsTime other)
          Returns the difference in seconds between the this object and other.
static int differenceSeconds(XsTime start, XsTime stop)
          Returns the diference in seconds between start and stop.
static XsTime getCurrent()
          Returns a new XsTime object set to current system time.
 int getHour()
          Get the hour component of the time.
 int getMinute()
          Get the minute component of the time.
 int getSecond()
          Get the second component of the time.
static void main(java.lang.String[] args)
          Sample code to test the class.
 int minutesValue()
          Returns the time value in minutes from midnight.
 int secondsValue()
          Returns the time value in seconds from midnight.
 void setTime(int h, int m, int s)
          Set time value of this XsTime object to given hour, minute, second values.
 void setTime(java.lang.String s)
          Set the time from to the string in the format HH[:MM[:SS]].
 java.lang.String toString()
          Return a String rapresentation of time value in the format HH:MM:SS.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XsTime

public XsTime()
Creates a new XsTime object set to time 0:00:00.


XsTime

public XsTime(int h,
              int m,
              int s)
Creates new XsTime object with given hour, minute, second values.

Values of hour, minute and second can be any, as they are converted in seconds, so the time value is stored as hour * 3600 + minute * 60 + second seconds.

Parameters:
h - hours component of time value.
m - minutes component of time value.
s - seconds component of time value.

XsTime

public XsTime(java.lang.String s)
Create a new XsTime object set to the time value from the string in the format HH[:MM[:SS]].

The separator is assumed to be the first non digit character in the String.

Parameters:
s - a String time value in the format HH[:MM[:SS]].
Method Detail

setTime

public void setTime(int h,
                    int m,
                    int s)
Set time value of this XsTime object to given hour, minute, second values.

Values of hour, minute and second can be any, as they are converted in seconds, so the time value is stored as hour * 3600 + minute * 60 + second seconds.

Parameters:
h - hours component of time value.
m - minutes component of time value.
s - seconds component of time value.

setTime

public void setTime(java.lang.String s)
Set the time from to the string in the format HH[:MM[:SS]]. The separator is assumed to be the first non digit character.

Parameters:
s - a String time value in the format HH[:MM[:SS]].

getHour

public int getHour()
Get the hour component of the time.

Returns:
hour component of the time.

getMinute

public int getMinute()
Get the minute component of the time.

Returns:
minute component of the time.

getSecond

public int getSecond()
Get the second component of the time.

Returns:
second component of the time.

minutesValue

public int minutesValue()
Returns the time value in minutes from midnight.

Returns:
time in minutes from midnight.

secondsValue

public int secondsValue()
Returns the time value in seconds from midnight.

Returns:
time value in seconds from midnight.

toString

public java.lang.String toString()
Return a String rapresentation of time value in the format HH:MM:SS.

Overrides:
toString in class java.lang.Object
Returns:
rapresentation of time value in the format HH:MM:SS.

getCurrent

public static XsTime getCurrent()
Returns a new XsTime object set to current system time.

Returns:
a new XsTime object set to current time

differenceMinutes

public static int differenceMinutes(XsTime start,
                                    XsTime stop)
Returns the diference in minutes between start and stop.

Parameters:
start - lower XsTime object.
stop - higher XsTime object.
Returns:
the difference is minutes from start to stop.

differenceMinutes

public int differenceMinutes(XsTime other)
Returns the difference in minutes between the this object and other.

Parameters:
other - time value to be compared to this object to find difference in minutes bewteeen them.
Returns:
difference in minutes between the this object and the argument.

differenceSeconds

public static int differenceSeconds(XsTime start,
                                    XsTime stop)
Returns the diference in seconds between start and stop.

Parameters:
start - lower XsTime object.
stop - higher XsTime object.
Returns:
the difference is seconds from start to stop.

differenceSeconds

public int differenceSeconds(XsTime other)
Returns the difference in seconds between the this object and other.

Parameters:
other - time value to be compared to this object to find difference in seconds bewteeen them.
Returns:
difference in seconds between the this object and the argument.

compareTo

public int compareTo(java.lang.Object o)
              throws java.lang.ClassCastException
Compares this XsTime object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

If compared to null always return positive value.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - the object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
java.lang.ClassCastException - if the specified object's type prevents it from being compared to this object.

main

public static void main(java.lang.String[] args)
Sample code to test the class.

Parameters:
args - command line arguments.