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 DVD implements Serializable { 33 private DVD() { 34 } 35 36 private DVD(String title, int price, String author) { 37 this.title = title; 38 this.price = price; 39 this.director = author; 40 } 41 42 public String getDirector() { 43 return director; 44 } 45 46 public void setDirector(String director) { 47 this.director = director; 48 } 49 50 public int getPrice() { 51 return price; 52 } 53 54 public void setPrice(int price) { 55 this.price = price; 56 } 57 58 public String getTitle() { 59 return title; 60 } 61 62 public void setTitle(String title) { 63 this.title = title; 64 } 65 66 public static DVD newDVD() { 67 counter++; 68 return new DVD(getNewTitle(counter), 69 getNewPrice(counter), 70 getNewDirector(counter)); 71 } 72 73 public Object [] toArray() { 74 Object [] result = new Object [3]; 75 result[0] = title; 76 result[1] = new Integer (price); 77 result[2] = director; 78 return result; 79 } 80 81 public String toString() { 82 StringBuffer sb = new StringBuffer (); 83 sb.append("'").append(title); 84 sb.append("from ").append(director).append(", "); 85 sb.append(price).append(" E"); 86 sb.append("'"); 87 return sb.toString(); 88 } 89 90 public static DVD toDVD(Object [] array) { 91 DVD dvd = new DVD(); 92 dvd.setTitle((String ) array[0]); 93 dvd.setPrice(((Integer ) array[1]).intValue()); 94 dvd.setDirector((String ) array[2]); 95 return dvd; 96 } 97 98 public static ClassDescription getMetaDescription() { 99 ClassDescription meta = JalistoFactory.createClassDescription(DVD.class.getName()); 100 meta.addField(JalistoFactory.createFieldDescription("title", MetaTypeFactory.StringType)); 101 meta.addField(JalistoFactory.createFieldDescription("price", MetaTypeFactory.IntegerType)); 102 meta.addField(JalistoFactory.createFieldDescription("director", MetaTypeFactory.StringType)); 103 meta.setLeafPageSize(0, (short) 3); 104 meta.setNodePageSize(0, (short) 2); 105 meta.setNodeSize(0, (short) 4); 106 return meta; 107 } 108 109 private static String getNewTitle(int c) { 110 return titles[c % titles.length]; 111 } 112 113 private static String getNewDirector(int c) { 114 return directors[c % directors.length]; 115 } 116 117 private static int getNewPrice(int c) { 118 return prices[c % prices.length]; 119 } 120 121 private String title; 122 private int price; 123 private String director; 124 125 public static int counter = -1; 126 public static final String [] titles = {"The Pianist", 127 "The Right Stuff", 128 "Dr. Quinn Medicine Woman", 129 "Throne of Blood", 130 "About Schmidt", 131 "A Guy Thing", 132 "Sex and the City", 133 "Miller's Crossing", 134 "The Animatrix", 135 "Dark Blue"}; 136 public static final int[] prices = {5, 137 10, 138 15, 139 20, 140 25, 141 30}; 142 public static final String [] directors = {"Roman Polanski", 143 "Toshiro Mifune", 144 "Luc Besson", 145 "Kevin Costner"}; 146 147 static final long serialVersionUID = -7589377099514765159L; 148 } 149 | Popular Tags |