Source code: com/eireneh/bible/book/Version.java
1
2 package com.eireneh.bible.book;
3
4 import java.util.Date;
5 import java.net.URL;
6
7 /**
8 * A Version represents a method of translating the Bible. All Bibles with
9 * the same Version should return identical text for any call to
10 * <code>Bible.getText(VerseRange)</code>. The implication of this is that
11 * there may be many instances of the Version "NIV", as there are several
12 * different versions of the NIV - Original American-English, Anglicized,
13 * and Inclusive Language editions at least.
14 *
15 * <p>Versions like Strings must be compared using <code>.equals()<code>
16 * instead of ==. A Bible must have the ability to handle a version
17 * unknown to ProjectB. So Bibles must be able to add versions to the
18 * system, and the system must cope with versions that already exist.</p>
19 *
20 * <p>I recommend that all Versions are created by the Bibles class and
21 * not using <code>new Version()</code> or <code>new BasicVersion()</code>
22 * because implementations of Bible should not all need to know all the
23 * ins and outs of the versions that they provide because that would mean
24 * lots of duplication of data - a centralized store of fine details would
25 * be better.</p>
26 *
27 * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
28 * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
29 * Distribution Licence:<br />
30 * Project B is free software; you can redistribute it
31 * and/or modify it under the terms of the GNU General Public License,
32 * version 2 as published by the Free Software Foundation.<br />
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36 * General Public License for more details.<br />
37 * The License is available on the internet
38 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
39 * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
40 * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
41 * The copyright to this program is held by it's authors.
42 * </font></td></tr></table>
43 * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
44 * @see docs.Licence
45 * @author Joe Walker
46 * @version D0.I0.T0
47 * @stereotype role
48 */
49 public abstract class Version
50 {
51 /**
52 * The name of the version, for example "King James Version" or
53 * "Bible in Basic English" or "Greek". In general it should be
54 * possible to deduce the initials from the name by removing all the
55 * non-capital letters.
56 * @return The name of this version
57 */
58 public abstract String getName();
59
60 /**
61 * The edition of this version, for example "Anglicised" (NIV),
62 * "Stephanus" (Greek). For 2 versions to be equal both the name and
63 * the edition must be equal. In general the text returned by this
64 * method should not include the word "Edition"
65 * @return The name of the edition
66 */
67 public abstract String getEdition();
68
69 /**
70 * The full name including edition of the version, for example
71 * "New International Version, Anglicised". The format is "name, edition"
72 * @return The full name of this version
73 */
74 public String getFullName()
75 {
76 return VersionFactory.getFullName(getName(), getEdition());
77 }
78
79 /**
80 * Do the 2 versions have matching names and editions.
81 * @param obj The object to compare to
82 * @return true if the names and editions match
83 */
84 public boolean equals(Object obj)
85 {
86 // Since this can not be null
87 if (obj == null)
88 return false;
89
90 // Check that that is the same as this
91 // Don't use instanceof since that breaks inheritance
92 if (!obj.getClass().equals(this.getClass()))
93 return false;
94
95 // If super does equals ...
96 if (super.equals(obj) == false)
97 return false;
98
99 // The real bit ...
100 Version that = (Version) obj;
101 if (!getName().equals(that.getName()))
102 return false;
103
104 return getEdition().equals(that.getEdition());
105 }
106
107 /**
108 * Get a moderately unique id for this Object.
109 * @return The hashing number
110 */
111 public int hashCode()
112 {
113 return (getName()+getEdition()).hashCode();
114 }
115
116 /**
117 * Do the 2 versions have matching names.
118 * @param version The version to compare to
119 * @return true if the names match
120 */
121 public boolean isSameFamily(Version version)
122 {
123 return getName().equals(version.getName());
124 }
125
126 /**
127 * The initials of the version - how most people will know it, for
128 * example "NIV", "KJV"
129 * @return The versions initials
130 */
131 public abstract String getInitials();
132
133 /**
134 * The date of first publishing. This does not need to be accurate and
135 * 2 versions can be considered equal even if they have different
136 * first publishing dates for that reason. In general "1 Jan 1970"
137 * means published in 1970, and so on. <b>A null return from this
138 * method is entirely valid</b> if the date of first publishing is not
139 * known.
140 * @return The date of first publishing
141 */
142 public abstract Date getFirstPublished();
143
144 /**
145 * Is this version sold for commercial profit like the NIV, or kept
146 * open like the NET version.
147 * @return A STATUS_* constant
148 */
149 public abstract int getOpenness();
150
151 /**
152 * Not sure about this one - Do we need a way of getting at the dist.
153 * licence? Are we going to be able to tie it down to a single Version
154 * policy like this?
155 * @return String detailing the users right to distribute this version
156 */
157 public abstract URL getLicence();
158
159 /**
160 * Get a human readable version of this Version -just bounce to
161 * getFullName()
162 * @return The full name of this version
163 */
164 public String toString()
165 {
166 return getFullName();
167 }
168
169 /** We have no way of knowing exactly how many words there are in a Version ... */
170 public static final int GUESS_WORDS = 18500;
171
172 /** If the data of unknown distribution status */
173 public static final int STATUS_UNKNOWN = -1;
174
175 /** If the data free of copyright restrictions */
176 public static final int STATUS_PD = 0;
177
178 /** Does the data have a licence that permits free use */
179 public static final int STATUS_FREE = 1;
180
181 /** Is the data freely redistributable */
182 public static final int STATUS_COPYABLE = 2;
183
184 /** Is the data sold for commercial profit */
185 public static final int STATUS_COMMERCIAL = 3;
186
187 /** The name-edition separator */
188 protected static final String SEPARATOR = ",";
189 }