001: /*
002: * Created on 16 juin 2005
003: *
004:
005: */
006: package abook.data;
007:
008: import java.io.Serializable;
009: import java.util.ArrayList;
010: import java.util.Collection;
011:
012: /**
013: * Provides object of type Book mapping the data stored in the sql database
014: */
015: public class Book implements Serializable {
016:
017: private long bookId;
018: private String longTitle;
019: private String shortTitle;
020: private double totalDuration; // seconds
021: private String releaseDate;
022: private String imageFilePath;
023: private String urlBook;
024: private String urlSummary;
025: private String publisher;
026: private String bookKind;
027: private String bookType;
028: private int popularity;
029: private Collection authors;
030: private Collection narrators;
031: private String mainAuthor;
032: private String mainNarrator;
033:
034: /**
035: * Constructs a new Book object
036: * @param bookId The book identifier.
037: * @param title The book title.
038: */
039: public Book(String title, long bookId) {
040: this .longTitle = title;
041: if (title.length() < 15) {
042: this .shortTitle = title;
043: } else {
044: this .shortTitle = (title.substring(0, 12) + "...");
045: }
046: this .bookId = bookId;
047: authors = new ArrayList();
048: narrators = new ArrayList();
049: }
050:
051: /**
052: * @return Returns the authors.
053: */
054: public Collection getAuthors() {
055: return authors;
056: }
057:
058: /**
059: * @param authors The authors to set.
060: */
061: public void setAuthors(Collection authors) {
062: this .authors = authors;
063: }
064:
065: /**
066: * @return Returns the bookId.
067: */
068: public long getBookId() {
069: return bookId;
070: }
071:
072: /**
073: * @param bookId The bookId to set.
074: */
075: public void setBookId(long bookId) {
076: this .bookId = bookId;
077: }
078:
079: /**
080: * @return Returns the imageFilePath.
081: */
082: public String getImageFilePath() {
083: return imageFilePath;
084: }
085:
086: /**
087: * @param imageFilePath The imageFilePath to set.
088: */
089: public void setImageFilePath(String imageFilePath) {
090: this .imageFilePath = imageFilePath;
091: }
092:
093: /**
094: * @return Returns the longTitle.
095: */
096: public String getLongTitle() {
097: return longTitle;
098: }
099:
100: /**
101: * @param longTitle The longTitle to set.
102: */
103: public void setLongTitle(String longTitle) {
104: this .longTitle = longTitle;
105: }
106:
107: /**
108: * @return Returns the narrators.
109: */
110: public Collection getNarrators() {
111: return narrators;
112: }
113:
114: /**
115: * @param narrators The narrators to set.
116: */
117: public void setNarrators(Collection narrators) {
118: this .narrators = narrators;
119: }
120:
121: /**
122: * @return Returns the releaseDate.
123: */
124: public String getReleaseDate() {
125: return releaseDate;
126: }
127:
128: /**
129: * @param releaseDate The releaseDate to set.
130: */
131: public void setReleaseDate(String releaseDate) {
132: this .releaseDate = releaseDate;
133: }
134:
135: /**
136: * @return Returns the shortTitle.
137: */
138: public String getShortTitle() {
139: return shortTitle;
140: }
141:
142: /**
143: * @param shortTitle The shortTitle to set.
144: */
145: public void setShortTitle(String shortTitle) {
146: this .shortTitle = shortTitle;
147: }
148:
149: /**
150: * @return Returns the totalDuration.
151: */
152: public double getTotalDuration() {
153: return totalDuration;
154: }
155:
156: /**
157: * @param totalDuration The totalDuration to set.
158: */
159: public void setTotalDuration(double totalDuration) {
160: this .totalDuration = totalDuration;
161: }
162:
163: /**
164: * @return Returns the bookType.
165: */
166: public String getBookType() {
167: return bookType;
168: }
169:
170: /**
171: * @param bookType The bookType to set.
172: */
173: public void setBookType(String bookType) {
174: this .bookType = bookType;
175: }
176:
177: /**
178: * @return Returns the urlBook.
179: */
180: public String getUrlBook() {
181: return urlBook;
182: }
183:
184: /**
185: * @param urlBook The urlBook to set.
186: */
187: public void setUrlBook(String urlBook) {
188: this .urlBook = urlBook;
189: }
190:
191: /**
192: * @return Returns the urlSummary.
193: */
194: public String getUrlSummary() {
195: return urlSummary;
196: }
197:
198: /**
199: * @param urlSummary The urlSummary to set.
200: */
201: public void setUrlSummary(String urlSummary) {
202: this .urlSummary = urlSummary;
203: }
204:
205: /**
206: * @return Returns the bookKind.
207: */
208: public String getBookKind() {
209: return bookKind;
210: }
211:
212: /**
213: * @param bookKind The bookKind to set.
214: */
215: public void setBookKind(String bookKind) {
216: this .bookKind = bookKind;
217: }
218:
219: /**
220: * @return Returns the popularity.
221: */
222: public int getPopularity() {
223: return popularity;
224: }
225:
226: /**
227: * @param popularity The popularity to set.
228: */
229: public void setPopularity(int popularity) {
230: this .popularity = popularity;
231: }
232:
233: /**
234: * @return Returns the publisher.
235: */
236: public String getPublisher() {
237: return publisher;
238: }
239:
240: /**
241: * @param publisher The publisher to set.
242: */
243: public void setPublisher(String publisher) {
244: this .publisher = publisher;
245: }
246:
247: /**
248: * @return Returns the mainAuthor.
249: */
250: String getMainAuthor() {
251: return mainAuthor;
252: }
253:
254: /**
255: * @param mainAuthor The mainAuthor to set.
256: */
257: void setMainAuthor(String mainAuthor) {
258: this .mainAuthor = mainAuthor;
259: }
260:
261: /**
262: * @return Returns the mainNarrator.
263: */
264: String getMainNarrator() {
265: return mainNarrator;
266: }
267:
268: /**
269: * @param mainNarrator The mainNarrator to set.
270: */
271: void setMainNarrator(String mainNarrator) {
272: this .mainNarrator = mainNarrator;
273: }
274:
275: /**
276: * @param author an author to add to the authors collection of the book
277: * @return true if this collection changed as a result of the call
278: */
279: public boolean add(Object author) {
280: return authors.add(author);
281: }
282:
283: /**
284: * @param arg0 a collection of authors
285: * @return if this collection changed as a result of the call
286: */
287: public boolean addAll(Collection arg0) {
288: return authors.addAll(arg0);
289: }
290:
291: /**
292: * @param author The author to add.
293: */
294: public void addAuthor(Author author) {
295: authors.add(author);
296: author.addBook(this );
297: }
298:
299: /**
300: * @param narrator The narrator to add.
301: */
302: public void addNarrator(Narrator narrator) {
303: narrators.add(narrator);
304: narrator.addBook(this );
305: }
306:
307: /**
308: * @return Returns the totalDuration in a String format.
309: */
310: public String getStrTotalDuration() {
311: if (totalDuration == 0) {
312: return "";
313: }
314: long h = (long) totalDuration / 3600;
315: long m = ((long) totalDuration - (h * 3600)) / 60;
316: long s = ((long) totalDuration - (m * 60));
317: String result = String.valueOf(h) + ":" + String.valueOf(m)
318: + ":" + String.valueOf(s);
319: return result;
320: }
321: }
|