| 1 | package org.sanmibuh.ddd.domain; | |
| 2 | ||
| 3 | import java.util.ArrayList; | |
| 4 | import java.util.Collections; | |
| 5 | import java.util.List; | |
| 6 | ||
| 7 | public abstract class AggregateRoot<I extends AggregateRootId<?>> { | |
| 8 | ||
| 9 | private final I id; | |
| 10 | private final List<DomainEvent> domainEvents = new ArrayList<>(); | |
| 11 | ||
| 12 | protected AggregateRoot(final I id) { | |
| 13 | this.id = id; | |
| 14 | } | |
| 15 | ||
| 16 | public final I id() { | |
| 17 |
1
1. id : replaced return value with null for org/sanmibuh/ddd/domain/AggregateRoot::id → KILLED |
return id; |
| 18 | } | |
| 19 | ||
| 20 | protected final void recordEvent(final DomainEvent event) { | |
| 21 | domainEvents.add(event); | |
| 22 | } | |
| 23 | ||
| 24 | public final List<DomainEvent> domainEvents() { | |
| 25 |
1
1. domainEvents : replaced return value with Collections.emptyList for org/sanmibuh/ddd/domain/AggregateRoot::domainEvents → KILLED |
return Collections.unmodifiableList(domainEvents); |
| 26 | } | |
| 27 | ||
| 28 | // Entity identity: equal iff same concrete type and same id, ignoring state and recorded events. | |
| 29 | // Concrete aggregates are final (enforced by ArchUnit), so a distinct class is always a distinct | |
| 30 | // aggregate; getClass() captures that precisely, whereas instanceof AggregateRoot would make two | |
| 31 | // aggregate types sharing an id compare equal. | |
| 32 | // Hand-written rather than Lombok on purpose: identity is defined once here, in the base, so | |
| 33 | // every aggregate inherits it for free and it cannot be silently forgotten on a new one. | |
| 34 | // Lombok's instanceof/canEqual would only discriminate by concrete type if | |
| 35 | // @EqualsAndHashCode(callSuper = true) were repeated on every leaf. | |
| 36 | @Override | |
| 37 | @SuppressWarnings("EqualsGetClass") | |
| 38 | public final boolean equals(final Object o) { | |
| 39 |
2
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED |
if (o == null || getClass() != o.getClass()) { |
| 40 |
1
1. equals : replaced boolean return with true for org/sanmibuh/ddd/domain/AggregateRoot::equals → KILLED |
return false; |
| 41 | } | |
| 42 |
2
1. equals : replaced boolean return with false for org/sanmibuh/ddd/domain/AggregateRoot::equals → KILLED 2. equals : replaced boolean return with true for org/sanmibuh/ddd/domain/AggregateRoot::equals → KILLED |
return id.equals(((AggregateRoot<?>) o).id); |
| 43 | } | |
| 44 | ||
| 45 | @Override | |
| 46 | public final int hashCode() { | |
| 47 |
1
1. hashCode : replaced int return with 0 for org/sanmibuh/ddd/domain/AggregateRoot::hashCode → KILLED |
return id.hashCode(); |
| 48 | } | |
| 49 | } | |
Mutations | ||
| 17 |
1.1 |
|
| 25 |
1.1 |
|
| 39 |
1.1 2.2 |
|
| 40 |
1.1 |
|
| 42 |
1.1 2.2 |
|
| 47 |
1.1 |