1 19 20 package org.netbeans.api.convertor.book; 21 22 import org.netbeans.spi.convertor.SimplyConvertible; 23 import java.util.Properties ; 24 25 26 30 public class Book implements SimplyConvertible { 31 32 public int ID; 33 public String author; 34 public String title; 35 public String publisher; 36 public int price; 37 38 private boolean initialized = false; 39 40 private static final String KEY_ID = "id"; 41 private static final String KEY_AUTHOR = "author"; 42 private static final String KEY_TITLE = "title"; 43 private static final String KEY_PUBLISHER = "publisher"; 44 private static final String KEY_PRICE = "price"; 45 46 public Book() { 47 } 48 49 public Book(int ID, String title, String author, String publisher, int price) { 50 this.ID = ID; 51 this.title = title; 52 this.author = author; 53 this.publisher = publisher; 54 this.price = price; 55 } 56 57 public void read(Properties prop) { 58 if (initialized) { 59 throw new RuntimeException ("Cannot initialize the object more than once!"); 60 } 61 initialized = true; 62 63 ID = Integer.parseInt(prop.getProperty(KEY_ID)); 64 author = prop.getProperty(KEY_AUTHOR); 65 title = prop.getProperty(KEY_TITLE); 66 publisher = prop.getProperty(KEY_PUBLISHER); 67 price = Integer.parseInt(prop.getProperty(KEY_PRICE)); 68 } 69 70 public void write(java.util.Properties p) { 71 p.setProperty(KEY_ID, Integer.toString(ID)); 72 p.setProperty(KEY_AUTHOR, author); 73 p.setProperty(KEY_TITLE, title); 74 p.setProperty(KEY_PUBLISHER, publisher); 75 p.setProperty(KEY_PRICE, Integer.toString(price)); 76 } 77 78 public boolean equals(Object o) { 79 if (!(o instanceof Book)) { 80 return false; 81 } 82 Book b = (Book)o; 83 return ID == b.ID && 84 title.equals(b.title) && 85 author.equals(b.author) && 86 publisher.equals(b.publisher) && 87 price == b.price; 88 } 89 90 public int hashCode() { 91 return 125; 93 } 94 95 public String toString() { 96 return "Book[id="+ID+", title="+title+", author="+author+", publisher="+publisher+", price="+price+"]"+super.toString(); 97 } 98 99 } 100 | Popular Tags |