Entry.java

  1. package de.japrost.jabudget.domain.account;

  2. import static java.util.Objects.requireNonNull;

  3. import java.io.Serializable;

  4. /**
  5.  * An entry in an {@link Account}.<br>
  6.  */
  7. public class Entry extends AggregateMember implements Serializable {

  8.     private static final long serialVersionUID = 1L;
  9.     /** The identity of the Account the Entry resides in. */
  10.     private final String accountId;
  11.     /** The code of the entry. */
  12.     private final String code;
  13.     /** The subject of the entry */
  14.     private final String subject;

  15.     // TODO use jabudegt-utils with requireNonNull
  16.     // TODO write tests that fields could not be null
  17.     /**
  18.      * Create an Entry.
  19.      *
  20.      * @param accountId the account id
  21.      * @param code the code
  22.      * @param subject the subject
  23.      */
  24.     public Entry(final String accountId, final String code, final String subject) {
  25.         requireNonNull(accountId, "'accountId' MUST NOT be null.");
  26.         requireNonNull(code, "'code' MUST NOT be null.");
  27.         requireNonNull(subject, "'subject' MUST NOT be null.");
  28.         this.accountId = accountId;
  29.         this.code = code;
  30.         this.subject = subject;
  31.     }

  32.     /**
  33.      * Gets the identity of the Account the Entry resides in.
  34.      *
  35.      * @return the identity of the Account the Entry resides in
  36.      */

  37.     public String getAccountId() {
  38.         return accountId;
  39.     }

  40.     /**
  41.      * Gets the code of the entry.
  42.      *
  43.      * @return the code of the entry
  44.      */
  45.     public String getCode() {
  46.         return code;
  47.     }

  48.     /**
  49.      * Gets the subject of the entry.
  50.      *
  51.      * @return the subject of the entry
  52.      */
  53.     public String getSubject() {
  54.         return subject;
  55.     }

  56.     /**
  57.      * {@inheritDoc}
  58.      * <p>
  59.      * <strong>This implementation</strong> concats accountId and code.
  60.      */

  61.     @Override
  62.     public String key() {
  63.         return accountId + KEY_SEPARATOR + code;
  64.     }

  65.     /**
  66.      * {@inheritDoc}
  67.      * <p>
  68.      * <strong>This implementation</strong> show all fields.
  69.      */

  70.     @Override
  71.     public String toString() {
  72.         StringBuilder builder = new StringBuilder();
  73.         builder.append("Entry [accountId=").append(accountId).append(", code=").append(code).append(", subject=")
  74.                 .append(subject).append("]");
  75.         return builder.toString();
  76.     }

  77. }