/protocols/jain-megaco/megaco-api/src/main/java/javax/megaco/message/descriptor/TimeStamp.java

http://mobicents.googlecode.com/ · Java · 116 lines · 39 code · 18 blank · 59 comment · 0 complexity · 75ccf613be64f0b50f928704dd5c1b83 MD5 · raw file

  1. package javax.megaco.message.descriptor;
  2. import java.io.Serializable;
  3. import java.util.Calendar;
  4. import java.util.Date;
  5. import java.util.GregorianCalendar;
  6. /**
  7. * The TimeStamp object is a class that shall be used to set the time and date
  8. * at which the event was detected within the observed event descriptor. This is
  9. * an independent class derived from java.util.Object and shall not have any
  10. * derived classes.
  11. */
  12. public class TimeStamp implements Serializable {
  13. private GregorianCalendar gc = new GregorianCalendar();
  14. /**
  15. * Constructs a timestamp object that contains the date and time. This shall
  16. * be used within the observed event to detect the time at which the event
  17. * was detected. Time stamp should be valid GregorianCallendar date.
  18. *
  19. * @param year
  20. * -
  21. * @param month
  22. * - index of month, starting from 0 for January
  23. * @param day
  24. * - day of month
  25. * @param hour
  26. * - 24h format hour
  27. * @param min
  28. * -
  29. * @param sec
  30. * -
  31. * @throws IllegalArgumentException
  32. * - Thrown if an illegal date or time parameter is set.
  33. */
  34. public TimeStamp(int year, int month, int day, int hour, int min, int sec) throws IllegalArgumentException {
  35. // Lets use trick to validate.
  36. gc.setLenient(false);
  37. gc.set(gc.YEAR, year);
  38. gc.set(gc.MONTH, month);
  39. gc.set(gc.DAY_OF_MONTH, day);
  40. gc.set(gc.HOUR_OF_DAY, hour);
  41. gc.set(gc.MILLISECOND, min);
  42. gc.set(gc.SECOND, sec);
  43. // here we validate
  44. gc.getTime();
  45. }
  46. /**
  47. * The method is used the to retrieve the year from the absolute date set.
  48. *
  49. * @return year - The integer value of the year.
  50. */
  51. public int getYear() {
  52. return this.gc.get(gc.YEAR);
  53. }
  54. /**
  55. * The method can be used the to retrieve month set in the object.
  56. *
  57. * @return month - Integer value of the month.
  58. */
  59. public int getMonth() {
  60. return this.gc.get(gc.MONTH);
  61. }
  62. /**
  63. * The method can be used the to retrieve day set in the object.
  64. *
  65. * @return day - Integer value of the day.
  66. */
  67. public int getDay() {
  68. return this.gc.get(gc.DAY_OF_MONTH);
  69. }
  70. /**
  71. * The method is used the to retrieve the hour from the absolute time set.
  72. *
  73. * @return hour - The integer value of the hour.
  74. */
  75. public int getHour() {
  76. return this.gc.get(gc.HOUR_OF_DAY);
  77. }
  78. /**
  79. * The method is used the to retrieve the minutes from the absolute time
  80. * set.
  81. *
  82. * @return minutes - The integer value of the minutes.
  83. */
  84. public int getMinutes() {
  85. return this.gc.get(gc.MINUTE);
  86. }
  87. /**
  88. * The method is used the to retrieve the secs from the absolute time set.
  89. *
  90. * @return secs - The integer value of the secs.
  91. */
  92. public int getSecs() {
  93. return this.gc.get(gc.SECOND);
  94. }
  95. public java.lang.String toString() {
  96. return this.getClass().getSimpleName() + "[" + gc.toString() + "]";
  97. }
  98. }