001 /*
002 @license.text@
003 */
004 package com.hammurapi.eventbus.tests.familyties.model;
005
006
007 public class Relative implements Comparable<Relative> {
008
009 private Person subject;
010 private Person object;
011
012 public Relative(Person subject, Person object) {
013 this.subject = subject;
014 this.object = object;
015 }
016
017 public String toString() {
018 StringBuffer ret = new StringBuffer(getSubject().toString());
019 ret.append(" is a ");
020
021 int idx = getClass().getName().lastIndexOf('.');
022 ret.append(idx == -1 ? getClass().getName() : getClass().getName().substring(idx + 1));
023 ret.append(" of ");
024 ret.append(getObject().toString());
025 ret.append(" (");
026 // ret.append(Integer.toString(System.identityHashCode(this), Character.MAX_RADIX));
027 ret.append(")");
028 // ret.append(" (");
029 // ret.append(getDepth());
030 // ret.append("/");
031 // ret.append(getCardinality());
032 // ret.append(")");
033 return ret.toString();
034 }
035
036 public Person getSubject() {
037 return subject;
038 }
039
040 public Person getObject() {
041 return object;
042 }
043
044 public int compareTo(Relative o) {
045 if (this==o || this.equals(o)) {
046 return 0;
047 }
048
049 int subjectCompare = getSubject().compareTo(o.getSubject());
050 if (subjectCompare!=0) {
051 return subjectCompare;
052 }
053
054 int objectCompare = getObject().compareTo(o.getObject());
055 if (objectCompare!=0) {
056 return objectCompare;
057 }
058
059 int typeCompare = getClass().getName().compareTo(o.getClass().getName());
060 if (typeCompare!=0) {
061 return typeCompare;
062 }
063
064 return hashCode() - o.hashCode();
065 }
066
067 @Override
068 public int hashCode() {
069 final int prime = 31;
070 int result = getClass().hashCode();
071 result = prime * result + ((object == null) ? 0 : object.hashCode());
072 result = prime * result + ((subject == null) ? 0 : subject.hashCode());
073 return result;
074 }
075
076 @Override
077 public boolean equals(Object obj) {
078 if (this == obj) {
079 return true;
080 }
081 if (obj == null) {
082 return false;
083 }
084 if (getClass() != obj.getClass()) {
085 return false;
086 }
087 Relative other = (Relative) obj;
088 if (object == null) {
089 if (other.object != null) {
090 return false;
091 }
092 } else if (!object.equals(other.object)) {
093 return false;
094 }
095 if (subject == null) {
096 if (other.subject != null) {
097 return false;
098 }
099 } else if (!subject.equals(other.subject)) {
100 return false;
101 }
102 return true;
103 }
104
105 }