View Javadoc
1   package de.japrost.jabudget.domain.account;
2   
3   import static java.util.Objects.requireNonNull;
4   
5   import java.io.Serializable;
6   
7   /**
8    * An entry in an {@link Account}.<br>
9    */
10  public class Entry extends AggregateMember implements Serializable {
11  
12  	private static final long serialVersionUID = 1L;
13  	/** The identity of the Account the Entry resides in. */
14  	private final String accountId;
15  	/** The code of the entry. */
16  	private final String code;
17  	/** The subject of the entry */
18  	private final String subject;
19  
20  	// TODO use jabudegt-utils with requireNonNull
21  	// TODO write tests that fields could not be null
22  	/**
23  	 * Create an Entry.
24  	 *
25  	 * @param accountId the account id
26  	 * @param code the code
27  	 * @param subject the subject
28  	 */
29  	public Entry(final String accountId, final String code, final String subject) {
30  		requireNonNull(accountId, "'accountId' MUST NOT be null.");
31  		requireNonNull(code, "'code' MUST NOT be null.");
32  		requireNonNull(subject, "'subject' MUST NOT be null.");
33  		this.accountId = accountId;
34  		this.code = code;
35  		this.subject = subject;
36  	}
37  
38  	/**
39  	 * Gets the identity of the Account the Entry resides in.
40  	 *
41  	 * @return the identity of the Account the Entry resides in
42  	 */
43  
44  	public String getAccountId() {
45  		return accountId;
46  	}
47  
48  	/**
49  	 * Gets the code of the entry.
50  	 *
51  	 * @return the code of the entry
52  	 */
53  	public String getCode() {
54  		return code;
55  	}
56  
57  	/**
58  	 * Gets the subject of the entry.
59  	 *
60  	 * @return the subject of the entry
61  	 */
62  	public String getSubject() {
63  		return subject;
64  	}
65  
66  	/**
67  	 * {@inheritDoc}
68  	 * <p>
69  	 * <strong>This implementation</strong> concats accountId and code.
70  	 */
71  
72  	@Override
73  	public String key() {
74  		return accountId + KEY_SEPARATOR + code;
75  	}
76  
77  	/**
78  	 * {@inheritDoc}
79  	 * <p>
80  	 * <strong>This implementation</strong> show all fields.
81  	 */
82  
83  	@Override
84  	public String toString() {
85  		StringBuilder builder = new StringBuilder();
86  		builder.append("Entry [accountId=").append(accountId).append(", code=").append(code).append(", subject=")
87  				.append(subject).append("]");
88  		return builder.toString();
89  	}
90  
91  }