Compare commits
No commits in common. "f/aggregate-change" and "develop" have entirely different histories.
f/aggregat
...
develop
@ -1,47 +0,0 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* Base interface for changes to be registered in a change manager.
|
||||
* Base interface for changes to be registered in an undo manager.
|
||||
*
|
||||
* @author Maximilian Käfer
|
||||
* @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 REDO_AVAILABLE = "redoAvailable";
|
||||
|
||||
protected final ReadOnlyObjectWrapper<C> lastChange =
|
||||
protected ReadOnlyObjectWrapper<C> lastChange =
|
||||
new ReadOnlyObjectWrapper<>(this, LAST_CHANGE);
|
||||
protected final ReadOnlyBooleanWrapper atMarkedChange =
|
||||
protected ReadOnlyBooleanWrapper atMarkedChange =
|
||||
new ReadOnlyBooleanWrapper(this, AT_MARKED_CHANGE);
|
||||
protected final ReadOnlyBooleanWrapper undoAvailable =
|
||||
protected ReadOnlyBooleanWrapper undoAvailable =
|
||||
new ReadOnlyBooleanWrapper(this, UNDO_AVAILABLE);
|
||||
protected final ReadOnlyBooleanWrapper redoAvailable =
|
||||
protected ReadOnlyBooleanWrapper redoAvailable =
|
||||
new ReadOnlyBooleanWrapper(this, REDO_AVAILABLE);
|
||||
|
||||
protected final M manager;
|
||||
|
Reference in New Issue
Block a user