001: package org.directwebremoting.convert.mapped;
002:
003: import java.util.HashSet;
004: import java.util.Set;
005:
006: import org.directwebremoting.util.CompareUtil;
007:
008: /**
009: * A hibernate bean to fit the declaration in {@link org.directwebremoting.hibernate.Database}
010: * @author Joe Walker [joe at getahead dot ltd dot uk]
011: */
012: public class Hibernate3Ex {
013: public Hibernate3Ex() {
014: }
015:
016: public Hibernate3Ex(Integer id) {
017: this .id = id;
018: }
019:
020: public Hibernate3Ex(Integer id, String name) {
021: this .id = id;
022: this .name = name;
023: }
024:
025: public Hibernate3Ex(Integer id, String name,
026: Set<Hibernate3NestEx> children) {
027: this .id = id;
028: this .name = name;
029: this .children = children;
030: }
031:
032: public Integer getId() {
033: return id;
034: }
035:
036: public void setId(Integer id) {
037: this .id = id;
038: }
039:
040: public String getName() {
041: return name;
042: }
043:
044: public void setName(String name) {
045: this .name = name;
046: }
047:
048: public Set<Hibernate3NestEx> getChildren() {
049: return children;
050: }
051:
052: public void setChildren(Set<Hibernate3NestEx> child) {
053: this .children = child;
054: }
055:
056: @Override
057: public String toString() {
058: return "Hibernate3Ex[id=" + getId() + ",name=" + getName()
059: + ",children=" + getChildren().size() + "]";
060: }
061:
062: @Override
063: public boolean equals(Object obj) {
064: if (obj == null) {
065: return false;
066: }
067:
068: if (obj == this ) {
069: return true;
070: }
071:
072: Class<? extends Hibernate3Ex> this Class = this .getClass();
073: Class<? extends Object> thatClass = obj.getClass();
074: if (!this Class.isAssignableFrom(thatClass)
075: && !thatClass.isAssignableFrom(this Class)) {
076: return false;
077: }
078:
079: Hibernate3Ex that = (Hibernate3Ex) obj;
080:
081: if (!CompareUtil.equals(this .getId(), that.getId())) {
082: return false;
083: }
084:
085: // Normally .equals should only have to test PK for equality with a DB
086: // but we want our tests to be tighter ...
087:
088: if (!CompareUtil.equals(this .getName(), that.getName())) {
089: return false;
090: }
091:
092: if (!CompareUtil.equals(this .getChildren(), that.getChildren())) {
093: return false;
094: }
095:
096: return true;
097: }
098:
099: private Integer id;
100:
101: private String name;
102:
103: private Set<Hibernate3NestEx> children = new HashSet<Hibernate3NestEx>();
104: }
|