@Override public ImmutableAggregate<TState, TEvent> toImmutable() { return new DefaultImmutableAggregate<>( projection, id, sourceVersion, state, appliedEvents); }
@Override public ImmutableAggregate<TState, TEvent> toImmutable() { return new DefaultImmutableAggregate<>( projection, id, sourceVersion, state, appliedEvents); }
@NotNull @Override public ImmutableAggregate<TState, TEvent> rebase(final int version) { return new DefaultImmutableAggregate<>( projection, id, version, state, ImmutableList.of()); }
@NotNull @Override public ImmutableAggregate<TState, TEvent> rebase(final int version) { return new DefaultImmutableAggregate<>( projection, id, version, state, ImmutableList.of()); }
/** * Creates a new immutable aggregate state from the given projection, current state and version. * * @param projection The projection used to apply events to the state of the aggregate. * @param id The id of the aggregate. * @param sourceVersion The current version of the aggregate, in the state provided. * @param state The current state of the aggregate. * @return A new immutable aggregate with the provided current state. */ public static <TState, TEvent> DefaultImmutableAggregate<TState, TEvent> fromExisting( final AggregateProjection<TState, TEvent> projection, final String id, final int sourceVersion, final TState state) { return new DefaultImmutableAggregate<>( projection, id, sourceVersion, state, ImmutableList.of()); }
/** * Creates a new immutable aggregate state from the given projection, current state and version. * * @param projection The projection used to apply events to the state of the aggregate. * @param id The id of the aggregate. * @param sourceVersion The current version of the aggregate, in the state provided. * @param state The current state of the aggregate. * @return A new immutable aggregate with the provided current state. */ public static <TState, TEvent> DefaultImmutableAggregate<TState, TEvent> fromExisting( final AggregateProjection<TState, TEvent> projection, final String id, final int sourceVersion, final TState state) { return new DefaultImmutableAggregate<>( projection, id, sourceVersion, state, ImmutableList.of()); }
@NotNull @Override public ImmutableAggregate<TState, TEvent> apply(@NotNull final TEvent event) { Preconditions.checkNotNull(event); @NotNull TState newState = projection.apply(id, state, event); return new DefaultImmutableAggregate<>( projection, id, sourceVersion, newState, ImmutableList.<TEvent>builder().addAll(appliedEvents).add(event).build()); }
@NotNull @Override public ImmutableAggregate<TState, TEvent> apply(@NotNull final TEvent event) { Preconditions.checkNotNull(event); @NotNull TState newState = projection.apply(id, state, event); return new DefaultImmutableAggregate<>( projection, id, sourceVersion, newState, ImmutableList.<TEvent>builder().addAll(appliedEvents).add(event).build()); }
@NotNull @Override public ImmutableAggregate<TState, TEvent> apply( @NotNull final Iterable<? extends TEvent> events) { Preconditions.checkNotNull(events); @NotNull TState newState = projection.apply(id, state, events); return new DefaultImmutableAggregate<>( projection, id, sourceVersion, newState, ImmutableList.<TEvent>builder().addAll(appliedEvents).addAll(events).build()); }
@NotNull @Override public ImmutableAggregate<TState, TEvent> apply( @NotNull final Iterable<? extends TEvent> events) { Preconditions.checkNotNull(events); @NotNull TState newState = projection.apply(id, state, events); return new DefaultImmutableAggregate<>( projection, id, sourceVersion, newState, ImmutableList.<TEvent>builder().addAll(appliedEvents).addAll(events).build()); }
/** * Creates a new immutable aggregate from the given projection, initialized with the empty * value as defined by the projection, no events, and a "not created" version. * * @param projection The projection used to apply events to the state of the aggregate. * @param id The id of the aggregate. * @return A new immutable aggregate with empty state and "not created" version. */ public static <TState, TEvent> DefaultImmutableAggregate<TState, TEvent> createNew( final AggregateProjection<TState, TEvent> projection, final String id) { return new DefaultImmutableAggregate<>( projection, id, Aggregate.VERSION_NOT_CREATED, projection.empty(), ImmutableList.of()); }
/** * Creates a new immutable aggregate from the given projection, initialized with the empty * value as defined by the projection, no events, and a "not created" version. * * @param projection The projection used to apply events to the state of the aggregate. * @param id The id of the aggregate. * @return A new immutable aggregate with empty state and "not created" version. */ public static <TState, TEvent> DefaultImmutableAggregate<TState, TEvent> createNew( final AggregateProjection<TState, TEvent> projection, final String id) { return new DefaultImmutableAggregate<>( projection, id, Aggregate.VERSION_NOT_CREATED, projection.empty(), ImmutableList.of()); }