001    /*
002      * hammurapi-rules-tutorial @mesopotamia.version@
003     * Hammurapi rules tutorial. 
004     * Copyright (C) 2006  Hammurapi Group
005     *
006     * This program is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU Lesser General Public
008     * License as published by the Free Software Foundation; either
009     * version 2 of the License, or (at your option) any later version.
010     *
011     * This program is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014     * Lesser General Public License for more details.
015     *
016     * You should have received a copy of the GNU Lesser General Public
017     * License along with this library; if not, write to the Free Software
018     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019     *
020     * URL: http://http://www.hammurapi.biz
021     * e-Mail: support@hammurapi.biz
022     */
023    package biz.hammurapi.rules.tutorial.facts;
024    
025    import org.w3c.dom.Element;
026    
027    import biz.hammurapi.xml.dom.DomSerializable;
028    
029    public class Person implements DomSerializable {
030    
031            private String name;
032    
033            private boolean isMale;
034            
035            private int age;
036    
037            public Person(String name, int age, boolean isMale) {
038                    super();
039                    this.name = name;
040                    this.age = age;
041                    this.isMale = isMale;
042            }
043    
044            public String toString() {
045                    return name + " ["+(isMale ? "male " : "female ")+age+"]";
046            }
047    
048            public boolean equals(Object obj) {
049                    return obj instanceof Person 
050                    && name.equals(((Person) obj).name) 
051                    && isMale == ((Person) obj).isMale 
052                    && age == ((Person) obj).age;
053            }
054    
055            public int hashCode() {
056                    return name.hashCode() 
057                    ^ (isMale ? 0 : 1) 
058                    ^ age;
059            }
060            
061            public boolean isMale() {
062                    return isMale;
063            }
064            
065            public int getAge() {
066                    return age;
067            }
068            
069            public String getName() {
070                    return name;
071            }
072    
073            public void toDom(Element holder) {
074                    holder.setAttribute("name", name);
075                    holder.setAttribute("type", getClass().getName());
076                    holder.setAttribute("gender", isMale ? "male" : "female");
077                    holder.setAttribute("age", String.valueOf(age));
078            }
079    }