KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > examples > madlib > MadLibBean


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.examples.madlib;
8
9
10 import java.util.ArrayList JavaDoc;
11
12
13 /**
14  * <p>
15  * This JavaBean is used in playing the MadLib game.
16  * </p>
17  *
18  * @author Brian Pontarelli
19  */

20 public class MadLibBean {
21     
22     private String JavaDoc title;
23     private ArrayList JavaDoc numbers = new ArrayList JavaDoc();
24     private ArrayList JavaDoc words = new ArrayList JavaDoc();
25     private MadLib madLib;
26     private String JavaDoc finalMadLib;
27      
28
29     /**
30      * Construsts a new <code>MadLibBean</code>
31      */

32     public MadLibBean() {
33         // Empty
34
}
35     
36
37     /**
38      * Gets the MadLib object the user is using.
39      *
40      * @return The MadLib object that the user is using
41      */

42     public MadLib getMadLib() {
43         return madLib;
44     }
45     
46     /**
47      * Sets the MadLib object the user is using.
48      *
49      * @param madLib The MadLib object that the user is using
50      */

51     public void setMadLib(MadLib madLib) {
52         this.madLib = madLib;
53     }
54     
55     /**
56      * Gets the title of this MadLib
57      *
58      * @return The title
59      */

60     public String JavaDoc getTitle() {
61         return title;
62     }
63
64     /**
65      * Sets the title of this MadLib
66      *
67      * @param title The title
68      */

69     public void setTitle(String JavaDoc title) {
70         this.title = title;
71     }
72
73     /**
74      * Returns the number at the given index.
75      *
76      * @param index The index of the number to retrieve
77      * @return The number or null if the index is invalid
78      */

79     public Integer JavaDoc getNumber(int index) {
80         if (index >= numbers.size()) {
81             return null;
82         }
83         
84         return (Integer JavaDoc) numbers.get(index);
85     }
86
87     /**
88      * Sets the number at the given index in the list of numbers
89      *
90      * @param index The index to set the number at
91      * @param number The number to set
92      */

93     public void setNumber(int index, Integer JavaDoc number) {
94         numbers.ensureCapacity(index + 1);
95         numbers.add(index, number);
96     }
97
98     /**
99      * Gets the word at the given index
100      *
101      * @param index The index of the word to retrieve
102      * @return The word or null if the index is invalid
103      */

104     public String JavaDoc getWord(int index) {
105         if (index >= words.size()) {
106             return null;
107         }
108         
109         return (String JavaDoc) words.get(index);
110     }
111
112     /**
113      * Sets the word at the given index in the list of words
114      *
115      * @param index The index to set the word at
116      * @param word The word to set
117      */

118     public void setWord(int index, String JavaDoc word) {
119         words.ensureCapacity(index + 1);
120         words.add(index, word);
121     }
122
123     /**
124      * Returns the number of numbers added to this bean.
125      *
126      * @return The number of numbers added to this bean
127      */

128     public int getNumberOfNumbers() {
129         return numbers.size();
130     }
131
132     /**
133      * Returns the number of words added to this bean.
134      *
135      * @return The number of words added to this bean
136      */

137     public int getNumberOfWords() {
138         return words.size();
139     }
140
141     /**
142      * Gets the final MadLib String that was created using the raw text and the
143      * inputs from the user.
144      *
145      * @return The MadLib text
146      */

147     public String JavaDoc getFinalMadLib() {
148         return finalMadLib;
149     }
150
151     /**
152      * Sets the final MadLib String that was created using the raw text and the
153      * inputs from the user.
154      *
155      * @param finalMadLib The final MadLib text
156      */

157     public void setFinalMadLib(String JavaDoc finalMadLib) {
158         this.finalMadLib = finalMadLib;
159     }
160
161     /**
162      * Resets the data stored in this MadLib bean
163      */

164     public void reset() {
165         numbers.clear();
166         words.clear();
167         finalMadLib = null;
168     }
169 }
Popular Tags