1 24 package org.objectweb.jalisto.se.test.data; 25 26 import org.objectweb.jalisto.se.api.ClassDescription; 27 import org.objectweb.jalisto.se.JalistoFactory; 28 import org.objectweb.jalisto.se.impl.meta.type.MetaTypeFactory; 29 30 import java.io.Serializable ; 31 32 public class BookWithAuthor implements Serializable { 33 private BookWithAuthor() { 34 } 35 36 private BookWithAuthor(String title, int pages, int price, String author) { 37 this.pages = pages; 38 this.title = title; 39 this.price = price; 40 this.author = author; 41 } 42 43 public String getAuthor() { 44 return author; 45 } 46 47 public void setAuthor(String author) { 48 this.author = author; 49 } 50 51 public int getPrice() { 52 return price; 53 } 54 55 public void setPrice(int price) { 56 this.price = price; 57 } 58 59 public int getPages() { 60 return pages; 61 } 62 63 public void setPages(int pages) { 64 this.pages = pages; 65 } 66 67 public String getTitle() { 68 return title; 69 } 70 71 public void setTitle(String title) { 72 this.title = title; 73 } 74 75 public static BookWithAuthor newBook() { 76 counter++; 77 return new BookWithAuthor(getNewTitle(counter), 78 getNewPages(counter), 79 getNewPrice(counter), 80 getNewAuthor(counter)); 81 } 82 83 public Object [] toArray() { 84 Object [] result = new Object [4]; 85 result[0] = title; 86 result[1] = new Integer (pages); 87 result[2] = new Integer (price); 88 result[3] = author; 89 return result; 90 } 91 92 public String toString() { 93 StringBuffer sb = new StringBuffer (); 94 sb.append("'").append(title); 95 sb.append("from ").append(author).append(", "); 96 sb.append(pages).append(" pages, "); 97 sb.append(price).append(" E"); 98 sb.append("'"); 99 return sb.toString(); 100 } 101 102 public static BookWithAuthor toBook(Object [] array) { 103 BookWithAuthor book = new BookWithAuthor(); 104 book.setTitle((String ) array[0]); 105 book.setPages(((Integer ) array[1]).intValue()); 106 book.setPrice(((Integer ) array[2]).intValue()); 107 book.setAuthor((String ) array[3]); 108 return book; 109 } 110 111 public static ClassDescription getMetaDescription() { 112 ClassDescription meta = JalistoFactory.createClassDescription(BookWithAuthor.class.getName()); 113 meta.addField(JalistoFactory.createFieldDescription("title", MetaTypeFactory.StringType)); 114 meta.addField(JalistoFactory.createFieldDescription("pages", MetaTypeFactory.IntegerType)); 115 meta.addField(JalistoFactory.createFieldDescription("price", MetaTypeFactory.IntegerType)); 116 meta.addField(JalistoFactory.createFieldDescription("author", MetaTypeFactory.StringType)); 117 return meta; 118 } 119 120 private static String getNewTitle(int c) { 121 return titles[c % titles.length]; 122 } 123 124 private static String getNewAuthor(int c) { 125 return authors[c % authors.length]; 126 } 127 128 private static int getNewPrice(int c) { 129 return prices[c % prices.length]; 130 } 131 132 public static int getNewPages(int c) { 133 return (c % maxPage); 134 } 135 136 private String title; 137 private int pages; 138 private int price; 139 private String author; 140 141 public static int counter = -1; 142 public static final String [] titles = {"Death Off Stage", 143 "At the Edge", 144 "Fingersmith", 145 "Metes and Bounds", 146 "A Fountain Filled with Blood", 147 "A Cold Case of Murder", 148 "Innocent Hearts", 149 "Tipping the Velvet", 150 "Bittersweet", 151 "The Jester"}; 152 public static final int[] prices = {5, 153 10, 154 15, 155 20, 156 25, 157 30}; 158 public static final String [] authors = {"James McManus", 159 "John Sandford", 160 "Robert Dallek", 161 "Andy Andrews"}; 162 public static final int maxPage = 1000; 163 164 165 static final long serialVersionUID = -7589377096154761459L; 166 } 167 | Popular Tags |