/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/util/RelativeSMPPDate.java

http://mobicents.googlecode.com/ · Java · 113 lines · 72 code · 14 blank · 27 comment · 14 complexity · a3b4f045d8c50437906631ce66516bf1 MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.protocols.smpp.util;
  23. /**
  24. * Implementation of {@link SMPPDate} representing a relative time
  25. * specification.
  26. *
  27. * @version $Id: RelativeSMPPDate.java 452 2009-01-15 16:56:36Z orank $
  28. */
  29. class RelativeSMPPDate extends SMPPDate {
  30. private static final long serialVersionUID = 2L;
  31. private int years;
  32. private int months;
  33. private int days;
  34. private int hours;
  35. private int minutes;
  36. private int seconds;
  37. public RelativeSMPPDate(int years,
  38. int months,
  39. int days,
  40. int hours,
  41. int minutes,
  42. int seconds) {
  43. this.years = years;
  44. this.months = months;
  45. this.days = days;
  46. this.hours = hours;
  47. this.minutes = minutes;
  48. this.seconds = seconds;
  49. }
  50. public int getDay() {
  51. return days;
  52. }
  53. public int getHour() {
  54. return hours;
  55. }
  56. public int getMinute() {
  57. return minutes;
  58. }
  59. public int getMonth() {
  60. return months;
  61. }
  62. public int getSecond() {
  63. return seconds;
  64. }
  65. public int getYear() {
  66. return years;
  67. }
  68. public char getSign() {
  69. return 'R';
  70. }
  71. public boolean isRelative() {
  72. return true;
  73. }
  74. @Override
  75. public int getLength() {
  76. return 17;
  77. }
  78. public boolean equals(Object obj) {
  79. if (obj == null || !(obj instanceof RelativeSMPPDate)) {
  80. return false;
  81. }
  82. RelativeSMPPDate other = (RelativeSMPPDate) obj;
  83. return years == other.years
  84. && months == other.months
  85. && days == other.days
  86. && hours == other.hours
  87. && minutes == other.minutes
  88. && seconds == other.seconds;
  89. }
  90. public int hashCode() {
  91. long val = (long) years * 10000000000L;
  92. val += (long) months * 100000000L;
  93. val += (long) days * 1000000L;
  94. val += (long) hours * 10000L;
  95. val += (long) minutes * 100;
  96. val += seconds;
  97. return new Long(val).hashCode();
  98. }
  99. }