1 24 package org.objectweb.jalisto.samples.basic2.data; 25 26 import java.util.Random ; 27 28 public class Book { 29 private Book() { 30 } 31 32 private Book(String title, int pages) { 33 this.pages = pages; 34 this.title = title; 35 } 36 37 public String getComments() { 38 return comments; 39 } 40 41 public void setComments(String 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 getTitle() { 54 return title; 55 } 56 57 public void setTitle(String title) { 58 this.title = title; 59 } 60 61 public String toString() { 62 StringBuffer result = new StringBuffer (); 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 title; 73 private int pages; 74 private String comments; 75 76 77 80 81 public static Book newBook() { 82 return new Book(getNewTitle(), getNewPages()); 83 } 84 85 private static String getNewTitle() { 86 return titles[random.nextInt(titles.length)]; 87 } 88 89 public static int getNewPages() { 90 return random.nextInt(1000); 91 } 92 93 96 97 public static Book toBook(Object [] array) { 98 Book book = new Book(); 99 book.setTitle((String ) array[0]); 100 book.setPages(((Integer ) array[1]).intValue()); 101 book.setComments((String ) array[2]); 102 return book; 103 } 104 105 public Object [] toArray() { 106 Object [] result = new Object [3]; 107 result[0] = title; 108 result[1] = new Integer (pages); 109 result[2] = comments; 110 return result; 111 } 112 113 private static Random random = new Random (); 114 private static String [] fieldNames = {"title", "pages", "comments"}; 115 private static String 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 |