001: package org.drools.jsr94.rules;
002:
003: /*
004: * $Id: Person.java,v 1.4 2004/11/17 03:09:50 dbarnett Exp $
005: *
006: * Copyright 2002-2004 (C) The Werken Company. All Rights Reserved.
007: *
008: * Redistribution and use of this software and associated documentation
009: * ("Software"), with or without modification, are permitted provided that the
010: * following conditions are met:
011: *
012: * 1. Redistributions of source code must retain copyright statements and
013: * notices. Redistributions must also contain a copy of this document.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright notice,
016: * this list of conditions and the following disclaimer in the documentation
017: * and/or other materials provided with the distribution.
018: *
019: * 3. The name "drools" must not be used to endorse or promote products derived
020: * from this Software without prior written permission of The Werken Company.
021: * For written permission, please contact bob@werken.com.
022: *
023: * 4. Products derived from this Software may not be called "drools" nor may
024: * "drools" appear in their names without prior written permission of The Werken
025: * Company. "drools" is a registered trademark of The Werken Company.
026: *
027: * 5. Due credit should be given to The Werken Company.
028: * (http://drools.werken.com/).
029: *
030: * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS''
031: * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
032: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
033: * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE
034: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
035: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
036: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
037: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
038: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
039: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
040: * POSSIBILITY OF SUCH DAMAGE.
041: *
042: */
043:
044: import java.util.HashSet;
045: import java.util.Set;
046:
047: public class Person {
048: private String name;
049:
050: private Set sisters;
051:
052: public Person() {
053:
054: }
055:
056: public Person(final String name) {
057: this .name = name;
058: this .sisters = new HashSet();
059: }
060:
061: public String getName() {
062: return this .name;
063: }
064:
065: public void addSister(final String sistersName) {
066: this .sisters.add(sistersName);
067: }
068:
069: public boolean hasSister(final Person person) {
070: return this .sisters.contains(person.getName());
071: }
072:
073: public String toString() {
074: return this .name;
075: }
076:
077: public int hashCode() {
078: final int PRIME = 31;
079: int result = 1;
080: result = PRIME * result
081: + ((name == null) ? 0 : name.hashCode());
082: result = PRIME * result
083: + ((sisters == null) ? 0 : sisters.hashCode());
084: return result;
085: }
086:
087: public boolean equals(Object obj) {
088: if (this == obj)
089: return true;
090: if (obj == null)
091: return false;
092:
093: if (!(obj instanceof Person))
094: return false;
095: final Person other = (Person) obj;
096:
097: if (name == null) {
098: if (other.name != null)
099: return false;
100: } else if (!name.equals(other.name))
101: return false;
102: if (sisters == null) {
103: if (other.sisters != null)
104: return false;
105: } else if (!sisters.equals(other.sisters))
106: return false;
107: return true;
108: }
109:
110: }
|