Compare commits

...

2 Commits

Author SHA1 Message Date
d117052ca4
Aggregate Change
All checks were successful
zdm/undo-redo/pipeline/head This commit looks good
The aggregate change combines multiple changes into one while
implementing the Change interface.
2022-02-11 09:48:41 +01:00
b30f806894
Improve Javadoc, make wrapper properties final 2022-02-11 09:48:34 +01:00
3 changed files with 52 additions and 5 deletions

View File

@ -0,0 +1,47 @@
package dev.kske.undoredo.core;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Kai S. K. Engelbart
* @since 0.2.0
*/
public final class AggregateChange<C extends Change> implements Change {
private final List<C> changes = new ArrayList<>();
@SafeVarargs
public AggregateChange(C... changes) {
this(Arrays.asList(changes));
}
public AggregateChange(Collection<C> changes) {
changes.addAll(changes);
}
@Override
public void apply() {
changes.forEach(Change::apply);
}
@Override
public Change invert() {
List<Change> invertedChanges =
changes
.parallelStream()
.map(Change::invert)
.collect(Collectors.toList());
Collections.reverse(invertedChanges);
return new AggregateChange<>(invertedChanges);
}
@Override
public boolean isIdentity() {
return changes.stream().allMatch(Change::isIdentity);
}
public List<C> changes() {
return Collections.unmodifiableList(changes);
}
}

View File

@ -1,7 +1,7 @@
package dev.kske.undoredo.core;
/**
* Base interface for changes to be registered in an undo manager.
* Base interface for changes to be registered in a change manager.
*
* @author Maximilian K&auml;fer
* @since 0.0.1

View File

@ -28,13 +28,13 @@ public class ChangeManagerWrapper<C extends Change, M extends ChangeManager<C>>
public static final String UNDO_AVAILABLE = "undoAvailable";
public static final String REDO_AVAILABLE = "redoAvailable";
protected ReadOnlyObjectWrapper<C> lastChange =
protected final ReadOnlyObjectWrapper<C> lastChange =
new ReadOnlyObjectWrapper<>(this, LAST_CHANGE);
protected ReadOnlyBooleanWrapper atMarkedChange =
protected final ReadOnlyBooleanWrapper atMarkedChange =
new ReadOnlyBooleanWrapper(this, AT_MARKED_CHANGE);
protected ReadOnlyBooleanWrapper undoAvailable =
protected final ReadOnlyBooleanWrapper undoAvailable =
new ReadOnlyBooleanWrapper(this, UNDO_AVAILABLE);
protected ReadOnlyBooleanWrapper redoAvailable =
protected final ReadOnlyBooleanWrapper redoAvailable =
new ReadOnlyBooleanWrapper(this, REDO_AVAILABLE);
protected final M manager;