Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/eireneh/bible/book/raw/InstsMem.java


1   
2   package com.eireneh.bible.book.raw;
3   
4   import java.io.*;
5   import java.util.Vector;
6   
7   import com.eireneh.bible.passage.*;
8   
9   /**
10  * InstsMem is a Base implementation of the Insts interface using the in
11  * memory model (Mem). 
12  * 
13  * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
14  * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
15  * Distribution Licence:<br />
16  * Project B is free software; you can redistribute it
17  * and/or modify it under the terms of the GNU General Public License,
18  * version 2 as published by the Free Software Foundation.<br />
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * General Public License for more details.<br />
23  * The License is available on the internet
24  * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
25  * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26  * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
27  * The copyright to this program is held by it's authors.
28  * </font></td></tr></table>
29  * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
30  * @see docs.Licence
31  * @author Joe Walker
32  * @version D0.I0.T0
33  */
34  public abstract class InstsMem extends Mem implements Insts
35  {
36      /**
37      * Basic constructor
38      * @param raw Reference to the RawBible that is using us
39      * @param filename The leaf name to read/write
40      * @param create Should we start all over again
41      */
42      public InstsMem(RawBible raw, String leafname, boolean create) throws Exception
43      {
44          super(raw, leafname, create);
45      }
46  
47      /**
48      * Basic constructor
49      * @param raw Reference to the RawBible that is using us
50      * @param filename The leaf name to read/write
51      * @param create Should we start all over again
52      * @param messages We append stuff here if something went wrong
53      */
54      public InstsMem(RawBible raw, String leafname, boolean create, StringBuffer messages)
55      {
56          super(raw, leafname, create, messages);
57      }
58  
59      /**
60      * Start all over again and clear the decks for more data.
61      */
62      public void init()
63      {
64          array = new int[Books.versesInBible()][];
65      }
66  
67      /**
68      * Load the Resource from a stream. This has been renamed from the
69      * default load() to ensure that the custom versions are called.
70      * @param in The stream to read from
71      */
72      protected void defaultLoad(InputStream in) throws IOException, ClassNotFoundException
73      {
74          ObjectInputStream obj_in = new ObjectInputStream(in);
75  
76          array = (int[][]) obj_in.readObject();
77          obj_in.close();
78      }
79  
80      /**
81      * Ensure that all changes to the index of words are written to a
82      * stream. This has been renamed from the default save() to ensure
83      * that the custom versions are called.
84      * @param out The stream to write to
85      */
86      public void defaultSave(OutputStream out) throws IOException
87      {
88          ObjectOutputStream obj_out = new ObjectOutputStream(out);
89  
90          obj_out.writeObject(array);
91          obj_out.close();
92      }
93  
94      /**
95      * Retrieve an ordered list of the words in a Verse
96      * @param verse The Verse to retrieve words for
97      * @return An array of word indexes
98      */
99      public int[] getIndexes(Verse verse)
100     {
101         return array[verse.getOrdinal()-1];
102     }
103 
104     /**
105     * Retrieve an ordered list of the words in a Verse
106     * @param verse The Verse to retrieve words for
107     * @return An array of word indexes
108     */
109     public int[] getIndexes(int ordinal)
110     {
111         return array[ordinal-1];
112     }
113 
114     /**
115     * Set a list of word indexes as the test to a Verse
116     * @param verse The Verse to set the words for
117     * @param indexes The array of word indexes
118     */
119     public void setIndexes(int[] indexes, Verse verse)
120     {
121         array[verse.getOrdinal()-1] = indexes;
122     }
123 
124     /** The store of data */
125     protected int[][] array;
126 }
127