KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > samples > basic2 > data > Book


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.samples.basic2.data;
25
26 import java.util.Random JavaDoc;
27
28 public class Book {
29     private Book() {
30     }
31
32     private Book(String JavaDoc title, int pages) {
33         this.pages = pages;
34         this.title = title;
35     }
36
37     public String JavaDoc getComments() {
38         return comments;
39     }
40
41     public void setComments(String JavaDoc comments) {
42         this.comments = comments;
43     }
44
45     public int getPages() {
46         return pages;
47     }
48
49     public void setPages(int pages) {
50         this.pages = pages;
51     }
52
53     public String JavaDoc getTitle() {
54         return title;
55     }
56
57     public void setTitle(String JavaDoc title) {
58         this.title = title;
59     }
60
61     public String JavaDoc toString() {
62         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
63         result.append("'").append(title).append(", ").append(pages).append(" pages");
64         if (comments != null) {
65             result.append(", ").append(comments);
66         }
67         result.append("'");
68         return result.toString();
69     }
70
71
72     private String JavaDoc title;
73     private int pages;
74     private String JavaDoc comments;
75
76
77     /**
78      * ***************** CONSTRUCTION STATIC METHODS *********************
79      */

80
81     public static Book newBook() {
82         return new Book(getNewTitle(), getNewPages());
83     }
84
85     private static String JavaDoc getNewTitle() {
86         return titles[random.nextInt(titles.length)];
87     }
88
89     public static int getNewPages() {
90         return random.nextInt(1000);
91     }
92
93     /**
94      * ****************** UTILITY METHODS *********************
95      */

96
97     public static Book toBook(Object JavaDoc[] array) {
98         Book book = new Book();
99         book.setTitle((String JavaDoc) array[0]);
100         book.setPages(((Integer JavaDoc) array[1]).intValue());
101         book.setComments((String JavaDoc) array[2]);
102         return book;
103     }
104
105     public Object JavaDoc[] toArray() {
106         Object JavaDoc[] result = new Object JavaDoc[3];
107         result[0] = title;
108         result[1] = new Integer JavaDoc(pages);
109         result[2] = comments;
110         return result;
111     }
112
113     private static Random JavaDoc random = new Random JavaDoc();
114     private static String JavaDoc[] fieldNames = {"title", "pages", "comments"};
115     private static String JavaDoc titles[] = {"Death Off Stage",
116                                       "At the Edge",
117                                       "Fingersmith",
118                                       "Metes and Bounds",
119                                       "A Fountain Filled with Blood",
120                                       "A Cold Case of Murder",
121                                       "Innocent Hearts",
122                                       "Tipping the Velvet",
123                                       "Bittersweet",
124                                       "The Jester",
125                                       "2nd Chance",
126                                       "Beyond All Reason"};
127 }
128
Popular Tags