Source code: jtemporal/TimedObject.java
1 /*
2 Copyright (C) 2002 Thomas A Beck (http://thomas.beck.name)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
18 package jtemporal;
19
20 import java.util.*;
21
22 /**
23 * Associates a period to an Object.
24 * The semantics of the period is free.
25 * Is immutable when the value is also immutable.
26 * @author Thomas Beck
27 */
28 public class TimedObject {
29 private final Period period;
30 private final Object value;
31
32 /**
33 * Unique constructir initializing the final field.
34 */
35 public TimedObject(Period period, Object value){
36 this.value = value;
37 this.period = period;
38 }
39
40 /**
41 * @return the period associated to the value
42 */
43 public Period getPeriod(){
44 return period;
45 }
46
47 /**
48 * @return the value
49 */
50 public Object getValue(){
51 return value;
52 }
53
54
55 public boolean equals(Object o) {
56 if (o == null) return false;
57 if (o == this) return true;
58 if (!(o instanceof TimedObject)) return false;
59 TimedObject to = (TimedObject)o;
60 return value.equals(to.value)
61 && period.equals(to.period);
62 }
63
64 /**
65 * Computes a hashcode for this TimedObject.
66 * @return a hash code value for this object.
67 */
68 public int hashCode() {
69 return this.value.hashCode() ^ this.period.hashCode();
70 }
71
72 public String toString() {
73 return "TimedObject:("+this.period+","+this.value+")";
74 }
75
76 /*public int objectHashCode() {
77 return super.hashCode();
78 }*/
79 }