KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > xml > book > Book


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.xml.book;
8
9 import java.util.List JavaDoc;
10 import java.util.ArrayList JavaDoc;
11
12 /**
13  * Book class that represents book element in XML content.
14  *
15  * @version <tt>$Revision: 1.2 $</tt>
16  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
17  */

18 public class Book
19 {
20    private String JavaDoc isbn;
21    private String JavaDoc title;
22    private String JavaDoc author;
23    private List JavaDoc characters = new ArrayList JavaDoc();
24
25    public String JavaDoc getIsbn()
26    {
27       return isbn;
28    }
29
30    public void setIsbn(String JavaDoc isbn)
31    {
32       this.isbn = isbn;
33    }
34
35    public String JavaDoc getAuthor()
36    {
37       return author;
38    }
39
40    public void setAuthor(String JavaDoc author)
41    {
42       this.author = author;
43    }
44
45    public String JavaDoc getTitle()
46    {
47       return title;
48    }
49
50    public void setTitle(String JavaDoc title)
51    {
52       this.title = title;
53    }
54
55    public List JavaDoc getCharacters()
56    {
57       return characters;
58    }
59
60    public void setCharacters(List JavaDoc characters)
61    {
62       this.characters = characters;
63    }
64
65    public void addCharacter(BookCharacter character)
66    {
67       characters.add(character);
68    }
69
70    public int getCharactersTotal()
71    {
72       return characters.size();
73    }
74
75    public String JavaDoc toString()
76    {
77       StringBuffer JavaDoc sb = new StringBuffer JavaDoc(100);
78       sb.append('[')
79          .append("isbn=").append(isbn)
80          .append(", title=").append(title)
81          .append(", author=").append(author)
82          .append(", characters=").append(characters)
83          .append(']');
84       return sb.toString();
85    }
86
87    public boolean equals(Object JavaDoc o)
88    {
89       if(this == o) return true;
90       if(!(o instanceof Book)) return false;
91
92       final Book book = (Book)o;
93
94       if(author != null ? !author.equals(book.author) : book.author != null) return false;
95       if(characters != null ? !characters.equals(book.characters) : book.characters != null) return false;
96       if(isbn != null ? !isbn.equals(book.isbn) : book.isbn != null) return false;
97       if(title != null ? !title.equals(book.title) : book.title != null) return false;
98
99       return true;
100    }
101
102    public int hashCode()
103    {
104       int result;
105       result = (isbn != null ? isbn.hashCode() : 0);
106       result = 29 * result + (title != null ? title.hashCode() : 0);
107       result = 29 * result + (author != null ? author.hashCode() : 0);
108       result = 29 * result + (characters != null ? characters.hashCode() : 0);
109       return result;
110    }
111 }
112
Popular Tags