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 BookWithFormat implements Serializable { 33 private BookWithFormat() { 34 } 35 36 private BookWithFormat(String title, int pages, int price, Format format) { 37 this.pages = pages; 38 this.title = title; 39 this.price = price; 40 this.format = format; 41 } 42 43 public Author getAuthor() { 44 return author; 45 } 46 47 public void setAuthor(Author 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 Format getFormat() { 76 return format; 77 } 78 79 public void setFormat(Format format) { 80 this.format = format; 81 } 82 83 public boolean equals(Object o) { 84 try { 85 BookWithFormat candidate = (BookWithFormat) o; 86 boolean titleTest = ((candidate.title != null) && (candidate.title.equals(title))) || 87 ((candidate.title == null) && (title == null)); 88 boolean intTest = (candidate.pages == pages) && (candidate.price == price); 89 boolean authorTest = ((candidate.author != null) && (candidate.author.equals(author))) || 90 ((candidate.author == null) && (author == null)); 91 boolean formatTest = ((candidate.format != null) && (candidate.format.equals(format))) || 92 ((candidate.format == null) && (format == null)); 93 94 return (titleTest && intTest && authorTest && formatTest); 95 } catch (Exception e) { 96 } 97 return false; 98 } 99 100 public Object [] toArray() { 101 Object [] result = new Object [5]; 102 result[0] = title; 103 result[1] = new Integer (pages); 104 result[2] = new Integer (price); 105 result[3] = author; 106 result[4] = format; 107 return result; 108 } 109 110 public String toString() { 111 StringBuffer sb = new StringBuffer (); 112 sb.append("'").append(title); 113 sb.append("from ").append(author).append(", "); 114 sb.append(pages).append(" pages, "); 115 sb.append(price).append(" E"); 116 sb.append("'"); 117 return sb.toString(); 118 } 119 120 public static BookWithFormat toBook(Object [] array) { 121 BookWithFormat book = new BookWithFormat(); 122 book.setTitle((String ) array[0]); 123 book.setPages(((Integer ) array[1]).intValue()); 124 book.setPrice(((Integer ) array[2]).intValue()); 125 book.setAuthor((Author) array[3]); 126 book.setFormat((Format) array[4]); 127 return book; 128 } 129 130 public static ClassDescription getMetaDescription() { 131 ClassDescription meta = JalistoFactory.createClassDescription(BookWithFormat.class.getName()); 132 meta.addField(JalistoFactory.createFieldDescription("title", MetaTypeFactory.StringType)); 133 meta.addField(JalistoFactory.createFieldDescription("pages", MetaTypeFactory.IntegerType)); 134 meta.addField(JalistoFactory.createFieldDescription("price", MetaTypeFactory.IntegerType)); 135 meta.addField(JalistoFactory.createFieldDescription("author", MetaTypeFactory.LinkType)); 136 meta.addField(JalistoFactory.createFieldDescription("format", MetaTypeFactory.SerializedType)); 137 return meta; 138 } 139 140 public static BookWithFormat newBook() { 141 counter++; 142 return new BookWithFormat(getNewTitle(counter), 143 getNewPages(counter), 144 getNewPrice(counter), 145 Format.getFormat()); 146 } 147 148 private static String getNewTitle(int c) { 149 return titles[c % titles.length]; 150 } 151 152 private static int getNewPrice(int c) { 153 return prices[c % prices.length]; 154 } 155 156 public static int getNewPages(int c) { 157 return (c % maxPage); 158 } 159 160 private String title; 161 private int pages; 162 private int price; 163 private Author author; 164 private Format format; 165 166 public static int counter = -1; 167 public static final String [] titles = {"Death Off Stage", 168 "At the Edge", 169 "Fingersmith", 170 "Metes and Bounds", 171 "A Fountain Filled with Blood", 172 "A Cold Case of Murder", 173 "Innocent Hearts", 174 "Tipping the Velvet", 175 "Bittersweet", 176 "The Jester"}; 177 public static final int[] prices = {5, 178 10, 179 15, 180 20, 181 25, 182 30}; 183 184 public static final int maxPage = 1000; 185 186 187 static final long serialVersionUID = -7589461099514761459L; 188 } 189 | Popular Tags |