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 public class Author { 31 32 private Author() { 33 } 34 35 private Author(String firstName, String lastName) { 36 this.firstName = firstName; 37 this.lastName = lastName; 38 } 39 40 public String getFirstName() { 41 return firstName; 42 } 43 44 public void setFirstName(String firstName) { 45 this.firstName = firstName; 46 } 47 48 public String getLastName() { 49 return lastName; 50 } 51 52 public void setLastName(String lastName) { 53 this.lastName = lastName; 54 } 55 56 public boolean equals(Object o) { 57 try { 58 Author candidate = (Author) o; 59 return (candidate.firstName.equals(firstName) && 60 candidate.lastName.equals(lastName)); 61 } catch (Exception e) { 62 } 63 return false; 64 } 65 66 public String toString() { 67 return "Author : " + firstName + " " + lastName; 68 } 69 70 public Object [] toArray() { 71 Object [] result = new Object [2]; 72 result[0] = firstName; 73 result[1] = lastName; 74 return result; 75 } 76 77 public static Author toAuthor(Object [] array) { 78 Author author = new Author(); 79 author.setFirstName((String ) array[0]); 80 author.setLastName((String ) array[1]); 81 return author; 82 } 83 84 public static ClassDescription getMetaDescription() { 85 ClassDescription meta = JalistoFactory.createClassDescription(Author.class.getName()); 86 meta.addField(JalistoFactory.createFieldDescription("firstName", MetaTypeFactory.StringType)); 87 meta.addField(JalistoFactory.createFieldDescription("lastName", MetaTypeFactory.StringType)); 88 return meta; 89 } 90 91 public static Author newAuthor() { 92 counter++; 93 return new Author(getNewFirstName(counter), getNewLastName(counter)); 94 } 95 96 private static String getNewFirstName(int c) { 97 return firstNames[c % firstNames.length]; 98 } 99 100 private static String getNewLastName(int c) { 101 return lastNames[c % lastNames.length]; 102 } 103 104 private String firstName; 105 private String lastName; 106 107 public static int counter = -1; 108 109 public static final String [] firstNames = {"James", 110 "John", 111 "Robert", 112 "Andy"}; 113 114 public static final String [] lastNames = {"McManus", 115 "Sandford", 116 "Dallek", 117 "Andrews"}; 118 } 119 | Popular Tags |