1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.statcvs.model;
20
21 import java.util.Date;
22 import java.util.SortedSet;
23 import java.util.TreeSet;
24
25
26
27
28
29
30
31
32 public class SymbolicName implements Comparable {
33 private final String name;
34 private final SortedSet revisions = new TreeSet();
35 private Date date = null;
36
37
38
39
40
41
42
43 public SymbolicName(final String name, final Date date) {
44 this.name = name;
45 this.date = date;
46 }
47
48
49
50
51
52
53
54
55 public SymbolicName(final String name) {
56 this.name = name;
57 }
58
59
60
61
62
63
64 public String getName() {
65 return name;
66 }
67
68
69
70
71
72
73 protected void addRevision(final Revision rev) {
74 revisions.add(rev);
75 }
76
77
78
79
80
81
82 public SortedSet getRevisions() {
83 return revisions;
84 }
85
86
87
88
89
90
91 public Date getDate() {
92 if (date != null) {
93 return date;
94 }
95 if (revisions.isEmpty()) {
96 return null;
97 }
98 return ((Revision) revisions.last()).getDate();
99 }
100
101
102
103
104 public int compareTo(final Object o) {
105 final SymbolicName other = (SymbolicName) o;
106 if (getDate() == null || other.getDate() == null) {
107 return getName().compareTo(other.getName());
108 }
109 final int dateComp = getDate().compareTo(other.getDate());
110 return (dateComp != 0) ? dateComp : getName().compareTo(other.getName());
111 }
112
113
114
115
116 public String toString() {
117 return name + "[" + getDate() + "] (" + revisions.size() + " revisions)";
118 }
119
120
121
122
123 public boolean equals(final Object obj) {
124 if (obj instanceof SymbolicName) {
125 final SymbolicName other = (SymbolicName) obj;
126 return other != null ? ("" + getDate() + getName()).equals("" + other.getDate() + other.getName()) : false;
127 }
128 return false;
129 }
130
131
132
133
134 public int hashCode() {
135 return ("" + getDate() + getName()).hashCode();
136 }
137 }