View Javadoc
1   package de.japrost.jabudget.domain.account;
2   
3   /**
4    * A member of an aggregate. Has a key as unique identifier.
5    */
6   public abstract class AggregateMember {
7   
8   	/** Separator between parts of a key */
9   	public static final String KEY_SEPARATOR = ":";
10  
11  	/**
12  	 * Get the key of the {@link AggregateMember}.
13  	 *
14  	 * @return the key, composed with the KEY_SEPARATOR.
15  	 */
16  	public abstract String key();
17  
18  	/**
19  	 * {@inheritDoc} <br>
20  	 * <strong>This implementation</strong> uses the {@link AggregateMember#key()}.
21  	 */
22  	@Override
23  	public int hashCode() {
24  		return key().hashCode();
25  	}
26  
27  	/**
28  	 * {@inheritDoc} <br>
29  	 * <strong>This implementation</strong> uses the {@link AggregateMember#key()}.
30  	 */
31  	@Override
32  	public boolean equals(final Object obj) {
33  		if (this == obj) {
34  			return true;
35  		}
36  		if (!(obj instanceof AggregateMember)) {
37  			return false;
38  		}
39  		final AggregateMember/../../de/japrost/jabudget/domain/account/AggregateMember.html#AggregateMember">AggregateMember other = (AggregateMember) obj;
40  		if (key().equals(other.key())) {
41  			return true;
42  		}
43  		return false;
44  	}
45  
46  }