1 /*
2 * jSDP: A Java implementation of SDP protocol Copyright (C) 2007 Claudio Di
3 * Vita
4 */
5 package net.sourceforge.jsdp.util;
6
7 import java.io.Serializable;
8 import java.util.Date;
9
10 import net.sourceforge.jsdp.SDPException;
11 import net.sourceforge.jsdp.Time;
12
13 /**
14 * Represents an adjustment time and his offset from the base time, for a
15 * repeated session scheduling.
16 *
17 * @since 0.1.0
18 *
19 * @version 1.0
20 *
21 * @author <a href="mailto:cdivita@users.sourceforge.net">Claudio Di Vita</a>
22 *
23 * @see net.sourceforge.jsdp.TimeZone
24 */
25 public class ZoneAdjustment implements Cloneable, Serializable {
26
27 /** The class Stream Unique Identifier, SUID */
28 private static final long serialVersionUID = -5613785303341511624L;
29
30 /** The adjustment offset */
31 protected long offset;
32
33 /** The NTP representation of adjustment time */
34 protected long time;
35
36 /**
37 * Creates a new <tt>ZoneAdjustment</tt>
38 */
39 protected ZoneAdjustment() {
40
41 super();
42 }
43
44 /**
45 * Creates a new <tt>ZoneAdjustment</tt>.
46 *
47 * @param time the adjustment time
48 *
49 * @param offset the adjustment offset
50 *
51 * @throws SDPException if the NTP representation of the adjustment time is
52 * negative
53 */
54 public ZoneAdjustment(final Date time, final long offset) throws SDPException {
55
56 super();
57
58 setTime(Time.getNTP(time));
59 this.offset = offset;
60 }
61
62 /**
63 * Creates a new <tt>ZoneAdjustment</tt>.
64 *
65 * @param time the adjustment time
66 *
67 * @param offset the adjustment offset
68 *
69 * @throws SDPException if the adjustment time is negative
70 */
71 public ZoneAdjustment(final long time, final long offset) throws SDPException {
72
73 super();
74
75 setTime(time);
76 this.offset = offset;
77 }
78
79 /**
80 * Returns a clone of this zone adjustment.
81 *
82 * @return a clone of this zone adjustment
83 */
84 public Object clone() {
85
86 ZoneAdjustment adjustment = new ZoneAdjustment();
87
88 adjustment.time = this.time;
89 adjustment.offset = this.offset;
90
91 return adjustment;
92 }
93
94 /**
95 * Returns the adjustment offset.
96 *
97 * @return the adjustment offset
98 */
99 public long getOffset() {
100
101 return offset;
102 }
103
104 /**
105 * Returns the adjustment time.
106 *
107 * @return the adjustment time
108 */
109 public long getTime() {
110
111 return time;
112 }
113
114 /**
115 * Sets the adjustment offset.
116 *
117 * @param offset the adjustment offset
118 */
119 public void setOffset(final long offset) {
120
121 this.offset = offset;
122 }
123
124 /**
125 * Sets the adjustment time.
126 *
127 * @param time the adjustment time
128 *
129 * @throws SDPException if the adjustment time is negative
130 */
131 public void setTime(final long time) throws SDPException {
132
133 if (time < 0) {
134 throw new SDPException("Adjustment time must be > 0");
135 }
136
137 this.time = time;
138 }
139
140 /**
141 * Returns a string representation of the object. The representation has the
142 * form: <b><time> <offset></b>
143 *
144 * @return the string representation of the object
145 */
146 public String toString() {
147
148 return time + " " + offset;
149 }
150 }