| 1 | |
package org.kuali.rice.core.api.mo; |
| 2 | |
|
| 3 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
| 4 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
| 5 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
| 6 | |
import org.kuali.rice.core.api.CoreConstants; |
| 7 | |
import org.kuali.rice.core.api.util.collect.CollectionUtils; |
| 8 | |
|
| 9 | |
import javax.xml.bind.Unmarshaller; |
| 10 | |
import javax.xml.bind.annotation.XmlTransient; |
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
@XmlTransient |
| 27 | |
public abstract class AbstractDataTransferObject implements ModelObjectComplete { |
| 28 | |
|
| 29 | |
private transient volatile Integer _hashCode; |
| 30 | |
private transient volatile String _toString; |
| 31 | |
|
| 32 | |
protected AbstractDataTransferObject() { |
| 33 | 485 | super(); |
| 34 | 485 | } |
| 35 | |
|
| 36 | |
@Override |
| 37 | |
public int hashCode() { |
| 38 | |
|
| 39 | |
|
| 40 | 333 | Integer h = _hashCode; |
| 41 | 333 | if (h == null) { |
| 42 | 134 | synchronized (this) { |
| 43 | 134 | h = _hashCode; |
| 44 | 134 | if (h == null) { |
| 45 | 134 | _hashCode = h = Integer.valueOf(HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE)); |
| 46 | |
} |
| 47 | 134 | } |
| 48 | |
} |
| 49 | |
|
| 50 | 333 | return h.intValue(); |
| 51 | |
} |
| 52 | |
|
| 53 | |
@Override |
| 54 | |
public boolean equals(Object obj) { |
| 55 | 150 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 56 | |
} |
| 57 | |
|
| 58 | |
@Override |
| 59 | |
public String toString() { |
| 60 | |
|
| 61 | |
|
| 62 | 1 | String t = _toString; |
| 63 | 1 | if (t == null) { |
| 64 | 1 | synchronized (this) { |
| 65 | 1 | t = _toString; |
| 66 | 1 | if (t == null) { |
| 67 | 1 | _toString = t = ToStringBuilder.reflectionToString(this); |
| 68 | |
} |
| 69 | 1 | } |
| 70 | |
} |
| 71 | |
|
| 72 | 1 | return t; |
| 73 | |
} |
| 74 | |
|
| 75 | |
@SuppressWarnings("unused") |
| 76 | |
protected void beforeUnmarshal(Unmarshaller u, Object parent) throws Exception { |
| 77 | 173 | } |
| 78 | |
|
| 79 | |
@SuppressWarnings("unused") |
| 80 | |
protected void afterUnmarshal(Unmarshaller u, Object parent) throws Exception { |
| 81 | 173 | CollectionUtils.makeUnmodifiableAndNullSafe(this); |
| 82 | 173 | } |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | 0 | protected static class Constants { |
| 88 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS, "_hashCode", "_toString"}; |
| 89 | |
} |
| 90 | |
} |