Compare commits
2 Commits
develop
...
f/aggregat
Author | SHA1 | Date | |
---|---|---|---|
d117052ca4 | |||
b30f806894 |
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package dev.kske.undoredo.core;
|
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äfer
|
* @author Maximilian Käfer
|
||||||
* @since 0.0.1
|
* @since 0.0.1
|
||||||
|
@ -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 UNDO_AVAILABLE = "undoAvailable";
|
||||||
public static final String REDO_AVAILABLE = "redoAvailable";
|
public static final String REDO_AVAILABLE = "redoAvailable";
|
||||||
|
|
||||||
protected ReadOnlyObjectWrapper<C> lastChange =
|
protected final ReadOnlyObjectWrapper<C> lastChange =
|
||||||
new ReadOnlyObjectWrapper<>(this, LAST_CHANGE);
|
new ReadOnlyObjectWrapper<>(this, LAST_CHANGE);
|
||||||
protected ReadOnlyBooleanWrapper atMarkedChange =
|
protected final ReadOnlyBooleanWrapper atMarkedChange =
|
||||||
new ReadOnlyBooleanWrapper(this, AT_MARKED_CHANGE);
|
new ReadOnlyBooleanWrapper(this, AT_MARKED_CHANGE);
|
||||||
protected ReadOnlyBooleanWrapper undoAvailable =
|
protected final ReadOnlyBooleanWrapper undoAvailable =
|
||||||
new ReadOnlyBooleanWrapper(this, UNDO_AVAILABLE);
|
new ReadOnlyBooleanWrapper(this, UNDO_AVAILABLE);
|
||||||
protected ReadOnlyBooleanWrapper redoAvailable =
|
protected final ReadOnlyBooleanWrapper redoAvailable =
|
||||||
new ReadOnlyBooleanWrapper(this, REDO_AVAILABLE);
|
new ReadOnlyBooleanWrapper(this, REDO_AVAILABLE);
|
||||||
|
|
||||||
protected final M manager;
|
protected final M manager;
|
||||||
|
Reference in New Issue
Block a user