aboutsummaryrefslogtreecommitdiff
path: root/src/org/gnunet/util/AbsoluteTime.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/gnunet/util/AbsoluteTime.java')
-rw-r--r--src/org/gnunet/util/AbsoluteTime.java37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/org/gnunet/util/AbsoluteTime.java b/src/org/gnunet/util/AbsoluteTime.java
index 2856fb2..d9df13a 100644
--- a/src/org/gnunet/util/AbsoluteTime.java
+++ b/src/org/gnunet/util/AbsoluteTime.java
@@ -32,6 +32,9 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> {
32 private static final Logger logger = LoggerFactory 32 private static final Logger logger = LoggerFactory
33 .getLogger(AbsoluteTime.class); 33 .getLogger(AbsoluteTime.class);
34 34
35 /**
36 * Constant for 'the beginning of time' in our frame.
37 */
35 public final static AbsoluteTime ZERO = new AbsoluteTime(0); 38 public final static AbsoluteTime ZERO = new AbsoluteTime(0);
36 public final static AbsoluteTime FOREVER = new AbsoluteTime(Long.MAX_VALUE); 39 public final static AbsoluteTime FOREVER = new AbsoluteTime(Long.MAX_VALUE);
37 40
@@ -95,16 +98,25 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> {
95 } 98 }
96 99
97 100
101 /**
102 * {@inheritDoc}
103 */
98 @Override 104 @Override
99 public boolean equals(Object other) { 105 public boolean equals(Object other) {
100 return other instanceof AbsoluteTime && compareTo((AbsoluteTime) other) == 0; 106 return other instanceof AbsoluteTime && compareTo((AbsoluteTime) other) == 0;
101 } 107 }
102 108
109 /**
110 * {@inheritDoc}
111 */
103 @Override 112 @Override
104 public int hashCode() { 113 public int hashCode() {
105 return (int) this.abs_value; 114 return (int) this.abs_value;
106 } 115 }
107 116
117 /**
118 * {@inheritDoc}
119 */
108 @Override 120 @Override
109 public int compareTo(AbsoluteTime other) { 121 public int compareTo(AbsoluteTime other) {
110 if (this.abs_value < other.abs_value) { 122 if (this.abs_value < other.abs_value) {
@@ -115,7 +127,10 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> {
115 } 127 }
116 return 0; 128 return 0;
117 } 129 }
118 130
131 /**
132 * {@inheritDoc}
133 */
119 @Override 134 @Override
120 public String toString() { 135 public String toString() {
121 if (this.isForever()) { 136 if (this.isForever()) {
@@ -132,8 +147,12 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> {
132 public boolean isDue() { 147 public boolean isDue() {
133 return this.abs_value < now().abs_value; 148 return this.abs_value < now().abs_value;
134 } 149 }
135 150
136 151 /**
152 * Does this AbsoluteTime value represent forever?
153 *
154 * @return this==FOREVER
155 */
137 public boolean isForever() { 156 public boolean isForever() {
138 return this.abs_value == Long.MAX_VALUE; 157 return this.abs_value == Long.MAX_VALUE;
139 } 158 }
@@ -220,10 +239,22 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> {
220 return new AbsoluteTime(abs_value - duration.getMilliseconds()); 239 return new AbsoluteTime(abs_value - duration.getMilliseconds());
221 } 240 }
222 241
242 /**
243 * Get a serializable message corresponding to this AbsoluteTime.
244 *
245 * @return a serializable message corresponding to this AbsoluteTime
246 */
223 public AbsoluteTimeMessage asMessage() { 247 public AbsoluteTimeMessage asMessage() {
224 return new AbsoluteTimeMessage(this); 248 return new AbsoluteTimeMessage(this);
225 } 249 }
226 250
251 /**
252 * Get the AbsoluteTime from a AbsoluteTimeMessage.
253 *
254 * @param m serializable representation of an AbsoluteTime
255 *
256 * @return the real AbsoluteTime associated with m
257 */
227 public static AbsoluteTime fromNetwork(AbsoluteTimeMessage m) { 258 public static AbsoluteTime fromNetwork(AbsoluteTimeMessage m) {
228 return m.value__ < 0 ? AbsoluteTime.FOREVER : new AbsoluteTime(m.value__); 259 return m.value__ < 0 ? AbsoluteTime.FOREVER : new AbsoluteTime(m.value__);
229 } 260 }