001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.xml.book;
023:
024: import java.util.List;
025: import java.util.ArrayList;
026:
027: /**
028: * Book class that represents book element in XML content.
029: *
030: * @version <tt>$Revision: 57211 $</tt>
031: * @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
032: */
033: public class Book {
034: public static Book getInstance() {
035: Book book = new Book();
036: book.setIsbn("0836217462");
037: book.setTitle("Being a Dog Is a Full-Time Job");
038: book.setAuthor("Charles M. Schulz");
039:
040: BookCharacter character = new BookCharacter();
041: character.setName("Snoopy");
042: character.setFriendOf("Peppermint Patty");
043: character.setSince("1950-10-04");
044: character.setQualification("extroverted beagle");
045: book.addCharacter(character);
046:
047: character = new BookCharacter();
048: character.setName("Peppermint Patty");
049: character.setSince("1966-08-22");
050: character.setQualification("bold, brash and tomboyish");
051: book.addCharacter(character);
052:
053: return book;
054: }
055:
056: private String isbn;
057: private String title;
058: private String author;
059: private List characters = new ArrayList();
060:
061: public String getIsbn() {
062: return isbn;
063: }
064:
065: public void setIsbn(String isbn) {
066: this .isbn = isbn;
067: }
068:
069: public String getAuthor() {
070: return author;
071: }
072:
073: public void setAuthor(String author) {
074: this .author = author;
075: }
076:
077: public String getTitle() {
078: return title;
079: }
080:
081: public void setTitle(String title) {
082: this .title = title;
083: }
084:
085: public List getCharacters() {
086: return characters;
087: }
088:
089: public void setCharacters(List characters) {
090: this .characters = characters;
091: }
092:
093: public void addCharacter(BookCharacter character) {
094: characters.add(character);
095: }
096:
097: public int getCharactersTotal() {
098: return characters.size();
099: }
100:
101: public String toString() {
102: StringBuffer sb = new StringBuffer(100);
103: sb.append('[').append("isbn=").append(isbn).append(", title=")
104: .append(title).append(", author=").append(author)
105: .append(", characters=").append(characters).append(']');
106: return sb.toString();
107: }
108:
109: public boolean equals(Object o) {
110: if (this == o)
111: return true;
112: if (!(o instanceof Book))
113: return false;
114:
115: final Book book = (Book) o;
116:
117: if (author != null ? !author.equals(book.author)
118: : book.author != null)
119: return false;
120: if (characters != null ? !characters.equals(book.characters)
121: : book.characters != null)
122: return false;
123: if (isbn != null ? !isbn.equals(book.isbn) : book.isbn != null)
124: return false;
125: if (title != null ? !title.equals(book.title)
126: : book.title != null)
127: return false;
128:
129: return true;
130: }
131:
132: public int hashCode() {
133: int result;
134: result = (isbn != null ? isbn.hashCode() : 0);
135: result = 29 * result + (title != null ? title.hashCode() : 0);
136: result = 29 * result + (author != null ? author.hashCode() : 0);
137: result = 29 * result
138: + (characters != null ? characters.hashCode() : 0);
139: return result;
140: }
141: }
|