Debian Codegraph @

src/dr/util/Citation.java

raw symbols SCIP
1 /*
2 * Citation.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.util;
27
28 import java.util.Arrays;
29
30 /**
31 * @author Alexei Drummond
32 * @author Marc A. Suchard
33 * @author Andrew Rambaut
34 */
35 public class Citation {
36
37 private final Author[] authors;
38 private final String title;
39 private final int year;
40 private final String journal;
41 private final String location; // alternative for eJournal
42 private final int volume;
43 private final int startpage;
44 private final int endpage;
45 private final Status status;
46 private final String DOI;
47
48 public Citation(Author[] authors, Status status) {
49 this(authors, null, null, status);
50 if (status != Status.IN_PREPARATION) {
51 throw new CitationException("Only citations in preparation may not contain titles or journals");
52 }
53 }
54
55 public Citation(Author[] authors, String title, String journal,
56 Status status) {
57 this(authors, title, -1, journal, -1, -1, -1, null, status);
58 if (status == Status.PUBLISHED) {
59 throw new CitationException("Published citations must have years, volumes and pages");
60 }
61 }
62
63 public Citation(Author[] authors, String title, int year, String journal, int volume, int startpage, int endpage,
64 Status status) {
65 this(authors, title, year, journal, volume, startpage, endpage, null, status);
66 }
67
68 public Citation(Author[] authors, String title, int year, String journal, int volume, int startpage, int endpage) {
69 this(authors, title, year, journal, volume, startpage, endpage, null, Status.PUBLISHED);
70 }
71
72 public Citation(Author[] authors, String title, int year, String journal, int volume, int startpage, int endpage,
73 String DOI) {
74 this(authors, title, year, journal, volume, startpage, endpage, DOI, Status.PUBLISHED);
75 }
76
77 public Citation(Author[] authors, String title, int year, String journal, int volume, int startpage, int endpage,
78 String DOI, Status status) {
79 this.authors = authors;
80 this.title = title;
81 this.year = year;
82 this.journal = journal;
83 this.volume = volume;
84 this.startpage = startpage;
85 this.endpage = endpage;
86 this.location = null;
87 this.DOI = DOI;
88 this.status = status;
89 }
90
91 public Citation(Author[] authors, String title, int year, String journal, int volume, String location) {
92 this(authors, title, year, journal, volume, location, null);
93 }
94
95 public Citation(Author[] authors, String title, int year, String journal, String location) {
96 this(authors, title, year, journal, -1, location, null);
97 }
98
99 public Citation(Author[] authors, String title, int year, String journal, int volumn, String location,
100 String DOI) {
101 this.authors = authors;
102 this.title = title;
103 this.year = year;
104 this.journal = journal;
105 this.location = location;
106 this.volume = volumn;
107 this.startpage = -1;
108 this.endpage = -1;
109 this.DOI = DOI;
110 this.status = Status.PUBLISHED;
111 }
112
113 public Citation(Author[] authors, String title, int year, String journal, String location,
114 String DOI) {
115 this(authors, title, year, journal, -1, location, DOI);
116 }
117
118 public String toString() {
119 StringBuilder builder = new StringBuilder();
120 builder.append(authors[0].toString());
121 for (int i = 1; i < authors.length; i++) {
122 builder.append(", ");
123 builder.append(authors[i].toString());
124 }
125 builder.append(" (");
126 switch (status) {
127 case PUBLISHED: builder.append(year); break;
128 default: builder.append(status.getText());
129 }
130 builder.append(") ");
131 if (title != null) {
132 builder.append(title);
133 }
134 if (journal != null) {
135 builder.append(". ");
136 builder.append(journal);
137 }
138 if (status == Status.PUBLISHED) {
139 builder.append(". ");
140 if (location != null) {
141 builder.append(location);
142 } else {
143 builder.append(volume);
144 builder.append(", ");
145 builder.append(startpage);
146 if (endpage > 0) builder.append("-").append(endpage);
147 }
148
149 if (DOI != null) {
150 builder.append(". DOI:" + DOI);
151 }
152 }
153 return builder.toString();
154 }
155
156 public String toHTML() {
157 StringBuilder builder = new StringBuilder();
158 builder.append("<html>");
159 builder.append(authors[0].toString());
160 for (int i = 1; i < authors.length; i++) {
161 builder.append(", ");
162 builder.append(authors[i].toString());
163 }
164 builder.append(" (").append(year).append(") ");
165 builder.append(title).append(". ");
166 builder.append("<i>").append(journal).append("</i>");
167 if (location != null) {
168 builder.append(" ").append(location);
169 } else {
170 builder.append(" <b>").append(volume).append("</b>:");
171 builder.append(startpage);
172 if (endpage > 0) builder.append("-").append(endpage);
173 }
174 if (DOI != null) {
175 builder.append(" <a href=\"http://doi.org/").append(DOI).append("\">DOI:").append(DOI).append("</a>");
176 }
177 builder.append("</html>");
178
179 return builder.toString();
180 }
181
182 @Override
183 public boolean equals(Object o) {
184 if (this == o) return true;
185 if (o == null || getClass() != o.getClass()) return false;
186
187 Citation citation = (Citation) o;
188
189 if (year != citation.year) return false;
190 if (volume != citation.volume) return false;
191 if (startpage != citation.startpage) return false;
192 if (endpage != citation.endpage) return false;
193 // Probably incorrect - comparing Object[] arrays with Arrays.equals
194 if (!Arrays.equals(authors, citation.authors)) return false;
195 if (!title.equals(citation.title)) return false;
196 if (journal != null ? !journal.equals(citation.journal) : citation.journal != null) return false;
197 if (location != null ? !location.equals(citation.location) : citation.location != null) return false;
198 if (status != citation.status) return false;
199 return DOI != null ? DOI.equals(citation.DOI) : citation.DOI == null;
200
201 }
202
203 @Override
204 public int hashCode() {
205 int result = Arrays.hashCode(authors);
206 result = 31 * result + title.hashCode();
207 result = 31 * result + year;
208 result = 31 * result + (journal != null ? journal.hashCode() : 0);
209 result = 31 * result + (location != null ? location.hashCode() : 0);
210 result = 31 * result + volume;
211 result = 31 * result + startpage;
212 result = 31 * result + endpage;
213 result = 31 * result + status.hashCode();
214 result = 31 * result + (DOI != null ? DOI.hashCode() : 0);
215 return result;
216 }
217
218 public Status getStatus() {
219 return status;
220 }
221
222 public String getDOI() {
223 return DOI;
224 }
225
226 public enum Status {
227 IN_PREPARATION("in preparation"),
228 IN_SUBMISSION("in submission"),
229 IN_PRESS("in press"),
230 ACCEPTED("accepted"),
231 PUBLISHED("published");
232
233 Status(String text) {
234 this.text = text;
235 }
236
237 public String getText() {
238 return text;
239 }
240
241 private final String text;
242 }
243
244 public enum Category {
245 FRAMEWORK("Framework"),
246 SUBSTITUTION_MODELS("Substitution Models"),
247 PRIOR_MODELS("Prior Models"),
248 TRAIT_MODELS("Trait Models"),
249 DATA_MODELS("Data Models"),
250 SPECIES_MODELS("Species Models"),
251 COUNTING_PROCESSES("Counting Processes"), // TODO Decide where MarkovJumpsBTL goes (multiple categories?)
252 TREE_PRIORS("Tree Density Models"),
253 MOLECULAR_CLOCK("Molecular Clock Models"),
254 TREE_METRICS("Tree Metrics"),
255 MISC("Misc"); // Try to avoid this category
256
257
258 Category(String text) { this.text = text; }
259
260 public String toString() { return text; }
261
262 private final String text;
263 }
264
265 class CitationException extends RuntimeException {
266 CitationException(String message) {
267 super(message);
268 }
269 }
270 }