public final class PassageKeyFactory extends Object
It is strongly recommended to use this factory to create passages if there is no driving need to create them for a specific purpose.
Most of the methods take the same arguments:
Most of the methods will throw:
The GNU Lesser General Public License for details.
Modifier and Type | Field and Description |
---|---|
private static PassageType |
defaultType
The default type
|
private static PassageKeyFactory |
keyf
How we create Passages
|
Modifier | Constructor and Description |
---|---|
private |
PassageKeyFactory()
This class implements a Singleton pattern.
|
Modifier and Type | Method and Description |
---|---|
protected static int |
binarySize(int max)
Write to buffer (starting at index) the given number using a set of bytes
as required by the max possible value for the number
|
Key |
createEmptyKeyList(Versification v11n)
Create an empty list of keys for the v11n
|
protected static int |
fromBinary(byte[] buffer,
int[] index,
int max)
Read and return an int from the buffer (starting at index[0]) using a set
of bytes as required by the max possible value for the number, and
incrementing index[0] by that number of bytes.
|
(package private) static Passage |
fromBinaryRepresentation(byte[] buffer)
Write out the object to the given ObjectOutputStream
|
static int |
getDefaultPassage()
Get the default passage type as the ordinal value of the PassageType.
|
static PassageType |
getDefaultType()
Get the default PassageType.
|
Key |
getGlobalKeyList(Versification v11n)
Get a Passage containing all the Verses in this Versification.
|
Passage |
getKey(Versification v11n,
String passageReference)
Convert the passageReference into a Passage.
|
Passage |
getKey(Versification v11n,
String passageReference,
Key basis)
Convert the passageReference into a Passage.
|
static Passage |
getReadOnlyPassage(Passage ref,
boolean ignore)
Get a new Passage based on another Passage that synchronizes all access
to its members.
|
static Passage |
getSynchronizedPassage(Passage ref)
Get a new Passage based on another Passage that synchronizes all access
to its members.
|
Key |
getValidKey(Versification v11n,
String passageReference)
Convert the passageReference into a Passage or an empty Passage,
if there is an error.
|
Key |
getValidKey(Versification v11n,
String passageReference,
Key basis)
Convert the passageReference into a Passage or an empty Passage,
if there is an error.
|
static PassageKeyFactory |
instance()
This PassageKeyFactory is accessed through this instance.
|
private String |
mungOsisRef(String passageReference)
Replace spaces with semi-colons, because the parser expects them.
|
private String |
normalize(String passageReference)
The internals of a Passage require that references are separated with a
reference delimiter.
|
static Passage |
readPassage(Reader in)
Read a passage from a given stream
|
static void |
setDefaultPassage(int newDefaultType)
Set the default PassageType.
|
static void |
setDefaultType(PassageType newDefaultType)
Set the default PassageType
|
protected static int |
toBinary(byte[] buffer,
int index,
int number,
int max)
Write to buffer (starting at index) the given number using a set of bytes
as required by the max possible value for the number
|
(package private) static byte[] |
toBinaryRepresentation(Passage ref)
Convert us to a binary representation.
|
private static PassageType defaultType
private static PassageKeyFactory keyf
private PassageKeyFactory()
public static PassageKeyFactory instance()
public Key createEmptyKeyList(Versification v11n)
v11n
- The Versification to which this Passage belongs.public Key getGlobalKeyList(Versification v11n)
Book.getGlobalKeyList()
which gets the
verses in the Book, which may be a small part of the whole.v11n
- The Versification to which this Passage belongs.public Key getValidKey(Versification v11n, String passageReference, Key basis)
v11n
- The Versification to which this Passage belongs.passageReference
- A String containing the text of the Passagebasis
- The basis by which to interpret passageReferencepublic Key getValidKey(Versification v11n, String passageReference)
v11n
- The Versification to which this Passage belongs.passageReference
- A String containing the text for the Passagepublic Passage getKey(Versification v11n, String passageReference, Key basis) throws NoSuchKeyException
v11n
- The Versification to which this Passage belongs.passageReference
- A String containing the text for the Passagebasis
- The basis by which to interpret passageReferenceNoSuchKeyException
- If the passageReference has anything that could not be understood as a Versepublic Passage getKey(Versification v11n, String passageReference) throws NoSuchKeyException
v11n
- The Versification to which this Passage belongs.passageReference
- A String containing the text for the PassageNoSuchKeyException
- If the passageReference has anything that could not be understood as a Versepublic static void setDefaultType(PassageType newDefaultType)
newDefaultType
- The new default PassageType.public static PassageType getDefaultType()
public static void setDefaultPassage(int newDefaultType)
newDefaultType
- The new default type.public static int getDefaultPassage()
setDefaultPassage(int)
public static Passage getSynchronizedPassage(Passage ref)
ref
- The passage to synchronizepublic static Passage getReadOnlyPassage(Passage ref, boolean ignore)
ref
- The passage to synchronizeignore
- Do we throw up if someone tries to change usstatic byte[] toBinaryRepresentation(Passage ref)
ref
- The Passage to convertstatic Passage fromBinaryRepresentation(byte[] buffer) throws NoSuchKeyException
buffer
- The stream to read our state fromNoSuchKeyException
- If the buffer is invalidpublic static Passage readPassage(Reader in) throws IOException, NoSuchKeyException
in
- The stream to read fromIOException
- If there was trouble reading the streamNoSuchKeyException
- if the data was not a valid passageprotected static int binarySize(int max)
max
- The number to writeprotected static int toBinary(byte[] buffer, int index, int number, int max)
buffer
- Where to write toindex
- The offset to start atnumber
- The number to writemax
- The max sizeprotected static int fromBinary(byte[] buffer, int[] index, int max)
buffer
- The buffer to read fromindex
- The offset to start atmax
- The max number of bytes to readprivate String mungOsisRef(String passageReference)
passageReference
- private String normalize(String passageReference)
passageReference
-