Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractBookMetaData |
|
| 1.5185185185185186;1.519 |
1 | /** | |
2 | * Distribution License: | |
3 | * JSword is free software; you can redistribute it and/or modify it under | |
4 | * the terms of the GNU Lesser General Public License, version 2.1 or later | |
5 | * as published by the Free Software Foundation. This program is distributed | |
6 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even | |
7 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
8 | * See the GNU Lesser General Public License for more details. | |
9 | * | |
10 | * The License is available on the internet at: | |
11 | * http://www.gnu.org/copyleft/lgpl.html | |
12 | * or by writing to: | |
13 | * Free Software Foundation, Inc. | |
14 | * 59 Temple Place - Suite 330 | |
15 | * Boston, MA 02111-1307, USA | |
16 | * | |
17 | * © CrossWire Bible Society, 2005 - 2016 | |
18 | * | |
19 | */ | |
20 | package org.crosswire.jsword.book.basic; | |
21 | ||
22 | import java.net.URI; | |
23 | ||
24 | import org.crosswire.common.util.Language; | |
25 | import org.crosswire.jsword.book.BookDriver; | |
26 | import org.crosswire.jsword.book.BookException; | |
27 | import org.crosswire.jsword.book.BookMetaData; | |
28 | import org.crosswire.jsword.book.FeatureType; | |
29 | import org.crosswire.jsword.book.KeyType; | |
30 | import org.crosswire.jsword.index.IndexStatus; | |
31 | import org.jdom2.Document; | |
32 | ||
33 | /** | |
34 | * An implementation of the Property Change methods from BookMetaData. | |
35 | * | |
36 | * @see gnu.lgpl.License The GNU Lesser General Public License for details. | |
37 | * @author Joe Walker | |
38 | */ | |
39 | ||
40 | /** | |
41 | * @author DM Smith | |
42 | * @see gnu.lgpl.License The GNU Lesser General Public License for details.<br> | |
43 | * The copyright to this program is held by its authors. | |
44 | */ | |
45 | 0 | public abstract class AbstractBookMetaData implements BookMetaData { |
46 | ||
47 | /* (non-Javadoc) | |
48 | * @see org.crosswire.jsword.book.BookMetaData#getKeyType() | |
49 | */ | |
50 | public KeyType getKeyType() { | |
51 | 0 | return KeyType.LIST; |
52 | } | |
53 | ||
54 | /* (non-Javadoc) | |
55 | * @see org.crosswire.jsword.book.BookMetaData#getDriver() | |
56 | */ | |
57 | public BookDriver getDriver() { | |
58 | 0 | return driver; |
59 | } | |
60 | ||
61 | /* (non-Javadoc) | |
62 | * @see org.crosswire.jsword.book.BookMetaData#getDriverName() | |
63 | */ | |
64 | public String getDriverName() { | |
65 | 0 | if (getDriver() == null) { |
66 | 0 | return null; |
67 | } | |
68 | ||
69 | 0 | return getDriver().getDriverName(); |
70 | } | |
71 | ||
72 | /* (non-Javadoc) | |
73 | * @see org.crosswire.jsword.book.BookMetaData#hasFeature(org.crosswire.jsword.book.FeatureType) | |
74 | */ | |
75 | public boolean hasFeature(FeatureType feature) { | |
76 | 0 | return false; |
77 | } | |
78 | ||
79 | /* (non-Javadoc) | |
80 | * @see org.crosswire.jsword.book.BookMetaData#getOsisID() | |
81 | */ | |
82 | public String getOsisID() { | |
83 | 0 | return getBookCategory().getName() + '.' + getInitials(); |
84 | } | |
85 | ||
86 | /* (non-Javadoc) | |
87 | * @see org.crosswire.jsword.book.BookMetaData#isSupported() | |
88 | */ | |
89 | public boolean isSupported() { | |
90 | 0 | return true; |
91 | } | |
92 | ||
93 | /* (non-Javadoc) | |
94 | * @see org.crosswire.jsword.book.BookMetaData#isEnciphered() | |
95 | */ | |
96 | public boolean isEnciphered() { | |
97 | 0 | return false; |
98 | } | |
99 | ||
100 | /* (non-Javadoc) | |
101 | * @see org.crosswire.jsword.book.BookMetaData#isLocked() | |
102 | */ | |
103 | public boolean isLocked() { | |
104 | 0 | return false; |
105 | } | |
106 | ||
107 | /* (non-Javadoc) | |
108 | * @see org.crosswire.jsword.book.BookMetaData#unlock(java.lang.String) | |
109 | */ | |
110 | public boolean unlock(String unlockKey) { | |
111 | 0 | return false; |
112 | } | |
113 | ||
114 | /* (non-Javadoc) | |
115 | * @see org.crosswire.jsword.book.BookMetaData#getUnlockKey() | |
116 | */ | |
117 | public String getUnlockKey() { | |
118 | 0 | return null; |
119 | } | |
120 | ||
121 | /* (non-Javadoc) | |
122 | * @see org.crosswire.jsword.book.BookMetaData#isQuestionable() | |
123 | */ | |
124 | public boolean isQuestionable() { | |
125 | 0 | return false; |
126 | } | |
127 | ||
128 | /* (non-Javadoc) | |
129 | * @see org.crosswire.jsword.book.BookMetaData#getLanguage() | |
130 | */ | |
131 | public Language getLanguage() { | |
132 | 0 | return this.language; |
133 | } | |
134 | ||
135 | /* (non-Javadoc) | |
136 | * @see org.crosswire.jsword.book.BookMetaData#setLanguage(org.crosswire.common.util.Language) | |
137 | */ | |
138 | public void setLanguage(Language language) { | |
139 | 0 | this.language = language; |
140 | 0 | } |
141 | ||
142 | /* (non-Javadoc) | |
143 | * @see org.crosswire.jsword.book.BookMetaData#getLibrary() | |
144 | */ | |
145 | public URI getLibrary() { | |
146 | 0 | return library; |
147 | } | |
148 | ||
149 | /* (non-Javadoc) | |
150 | * @see org.crosswire.jsword.book.BookMetaData#setLibrary(java.net.URI) | |
151 | */ | |
152 | public void setLibrary(URI library) throws BookException { | |
153 | 0 | this.library = library; |
154 | 0 | } |
155 | ||
156 | /* (non-Javadoc) | |
157 | * @see org.crosswire.jsword.book.BookMetaData#setLocation(java.net.URI) | |
158 | */ | |
159 | public void setLocation(URI location) { | |
160 | 0 | this.location = location; |
161 | 0 | } |
162 | ||
163 | /* (non-Javadoc) | |
164 | * @see org.crosswire.jsword.book.BookMetaData#getLocation() | |
165 | */ | |
166 | public URI getLocation() { | |
167 | 0 | return location; |
168 | } | |
169 | ||
170 | /* (non-Javadoc) | |
171 | * @see org.crosswire.jsword.book.BookMetaData#getIndexStatus() | |
172 | */ | |
173 | public IndexStatus getIndexStatus() { | |
174 | 0 | return indexStatus; |
175 | } | |
176 | ||
177 | /* (non-Javadoc) | |
178 | * @see org.crosswire.jsword.book.BookMetaData#setIndexStatus(org.crosswire.jsword.index.IndexStatus) | |
179 | */ | |
180 | public void setIndexStatus(IndexStatus newValue) { | |
181 | 0 | indexStatus = newValue; |
182 | 0 | } |
183 | ||
184 | /* (non-Javadoc) | |
185 | * @see org.crosswire.jsword.book.BookMetaData#reload() | |
186 | */ | |
187 | public void reload() throws BookException { | |
188 | // over ride this if partial loads are allowed | |
189 | 0 | } |
190 | ||
191 | /* (non-Javadoc) | |
192 | * @see org.crosswire.jsword.book.BookMetaData#putProperty(java.lang.String, java.lang.String) | |
193 | */ | |
194 | public void putProperty(String key, String value) { | |
195 | 0 | putProperty(key, value, false); |
196 | 0 | } |
197 | ||
198 | /* (non-Javadoc) | |
199 | * @see org.crosswire.jsword.book.BookMetaData#toOSIS() | |
200 | */ | |
201 | public Document toOSIS() { | |
202 | 0 | throw new UnsupportedOperationException("If you want to use this, implement it."); |
203 | } | |
204 | ||
205 | /** | |
206 | * @param driver The driver to set. | |
207 | */ | |
208 | public void setDriver(BookDriver driver) { | |
209 | 0 | this.driver = driver; |
210 | 0 | } |
211 | ||
212 | @Override | |
213 | public boolean equals(Object obj) { | |
214 | // Since this can not be null | |
215 | 0 | if (obj == null) { |
216 | 0 | return false; |
217 | } | |
218 | ||
219 | // We might consider checking for equality against all BookMetaDatas? | |
220 | // However currently we don't. | |
221 | ||
222 | // Check that that is the same as this | |
223 | // Don't use instanceof since that breaks inheritance | |
224 | 0 | if (!obj.getClass().equals(this.getClass())) { |
225 | 0 | return false; |
226 | } | |
227 | ||
228 | // The real bit ... | |
229 | 0 | BookMetaData that = (BookMetaData) obj; |
230 | ||
231 | 0 | return getBookCategory().equals(that.getBookCategory()) && getName().equals(that.getName()) && getInitials().equals(that.getInitials()); |
232 | } | |
233 | ||
234 | @Override | |
235 | public int hashCode() { | |
236 | 0 | return getName().hashCode(); |
237 | } | |
238 | ||
239 | /* | |
240 | * The sort order should be based on initials rather than name because name often begins with general words like 'The ...' | |
241 | * (non-Javadoc) | |
242 | * @see java.lang.Comparable#compareTo(java.lang.Object) | |
243 | */ | |
244 | public int compareTo(BookMetaData obj) { | |
245 | 0 | int result = this.getBookCategory().compareTo(obj.getBookCategory()); |
246 | 0 | if (result == 0) { |
247 | 0 | result = this.getAbbreviation().compareTo(obj.getAbbreviation()); |
248 | } | |
249 | 0 | if (result == 0) { |
250 | 0 | result = this.getInitials().compareTo(obj.getInitials()); |
251 | } | |
252 | 0 | if (result == 0) { |
253 | 0 | result = this.getName().compareTo(obj.getName()); |
254 | } | |
255 | 0 | return result; |
256 | } | |
257 | ||
258 | @Override | |
259 | public String toString() { | |
260 | 0 | String internal = getInitials(); |
261 | 0 | String abbreviation = getAbbreviation(); |
262 | 0 | if (internal.equals(abbreviation)) { |
263 | 0 | return internal; |
264 | } | |
265 | 0 | StringBuffer buf = new StringBuffer(internal); |
266 | 0 | buf.append('('); |
267 | 0 | buf.append(abbreviation); |
268 | 0 | buf.append(')'); |
269 | 0 | return buf.toString(); |
270 | } | |
271 | ||
272 | private BookDriver driver; | |
273 | 0 | private IndexStatus indexStatus = IndexStatus.UNDONE; |
274 | private Language language; | |
275 | private URI library; | |
276 | private URI location; | |
277 | ||
278 | } |