Files
ModTweaker/src/main/java/modtweaker2/utils/BaseListRemoval.java
T
Zixxl da33cc6fab ModTweaker2 Rework
- Revised base classes for IUndoableAction
- Reordered lots of code, so stuck actions should be less frequent
- Added wildcard support to many "remove" methods
- Started working on exist & duplicate checks
2015-06-29 16:36:35 +02:00

65 lines
1.9 KiB
Java

package modtweaker2.utils;
import java.util.List;
import modtweaker2.helpers.LogHelper;
public abstract class BaseListRemoval<T> extends BaseListModification<T> {
protected BaseListRemoval(String name, List<T> list) {
super(name, list);
}
protected BaseListRemoval(String name, List<T> list, List<T> recipies) {
this(name, list);
if(recipes != null) {
recipes.addAll(recipies);
}
}
@Override
public void apply() {
if(recipes.isEmpty()) {
return;
}
for(T recipe : this.recipes) {
if(recipe != null) {
if(this.list.remove(recipe)) {
successful.add(recipe);
} else {
LogHelper.logError(String.format("Error removing %s Recipe for %s", name, getRecipeInfo(recipe)));
}
} else {
LogHelper.logError(String.format("Error removing %s Recipe: null object", name));
}
}
}
@Override
public void undo() {
if(successful.isEmpty()) {
return;
}
for(T recipe : successful) {
if(recipe != null) {
if(!list.add(recipe)) {
LogHelper.logError(String.format("Error restoring %s Recipe for %s", name, getRecipeInfo(recipe)));
}
} else {
LogHelper.logError(String.format("Error restoring %s Recipe: null object", name));
}
}
}
@Override
public String describe() {
return String.format("[ModTweaker2] Removing %d %s Recipe(s) for %s", this.recipes.size(), this.name, this.getRecipeInfo());
}
@Override
public String describeUndo() {
return String.format("[ModTweaker2] Restoring %d %s Recipe(s) for %s", this.recipes.size(), this.name, this.getRecipeInfo());
}
}