AggregateMember.java

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

  2. /**
  3.  * A member of an aggregate. Has a key as unique identifier.
  4.  */
  5. public abstract class AggregateMember {

  6.     /** Separator between parts of a key */
  7.     public static final String KEY_SEPARATOR = ":";

  8.     /**
  9.      * Get the key of the {@link AggregateMember}.
  10.      *
  11.      * @return the key, composed with the KEY_SEPARATOR.
  12.      */
  13.     public abstract String key();

  14.     /**
  15.      * {@inheritDoc} <br>
  16.      * <strong>This implementation</strong> uses the {@link AggregateMember#key()}.
  17.      */
  18.     @Override
  19.     public int hashCode() {
  20.         return key().hashCode();
  21.     }

  22.     /**
  23.      * {@inheritDoc} <br>
  24.      * <strong>This implementation</strong> uses the {@link AggregateMember#key()}.
  25.      */
  26.     @Override
  27.     public boolean equals(final Object obj) {
  28.         if (this == obj) {
  29.             return true;
  30.         }
  31.         if (!(obj instanceof AggregateMember)) {
  32.             return false;
  33.         }
  34.         final AggregateMember other = (AggregateMember) obj;
  35.         if (key().equals(other.key())) {
  36.             return true;
  37.         }
  38.         return false;
  39.     }

  40. }