de.rpgframework.genericrpg.modification.ModifyableImpl Maven / Gradle / Ivy
/**
*
*/
package de.rpgframework.genericrpg.modification;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import de.rpgframework.genericrpg.modification.Modification.Origin;
/**
* @author prelle
*
*/
public abstract class ModifyableImpl implements Modifyable {
protected transient List incomingModifications;
protected transient List outgoingModifications;
//-------------------------------------------------------------------
protected ModifyableImpl() {
incomingModifications = new ArrayList<>();
outgoingModifications = new ArrayList<>();
}
//-------------------------------------------------------------------
/**
* @see de.rpgframework.genericrpg.modification.Modifyable#getIncomingModifications()
*/
@Override
public List getIncomingModifications() {
return new ArrayList(this.incomingModifications);
}
//-------------------------------------------------------------------
public void clearIncomingModifications() {
incomingModifications.clear();
}
//-------------------------------------------------------------------
public void removeIncomingModifications(Origin origin) {
getIncomingModifications().stream()
.filter(mod -> mod.getOrigin()==origin)
.forEach(mod -> removeIncomingModification(mod))
;
}
//-------------------------------------------------------------------
/**
* @see de.rpgframework.genericrpg.modification.Modifyable#setIncomingModifications(java.util.List)
*/
@Override
public void setIncomingModifications(List mods) {
incomingModifications = mods;
}
//-------------------------------------------------------------------
/**
* @see de.rpgframework.genericrpg.modification.Modifyable#addIncomingModification(de.rpgframework.genericrpg.modification.Modification)
*/
@Override
public void addIncomingModification(Modification mod) {
// if (mod.getOrigin()==null)
// throw new RuntimeException("Modifications without origin are not allowed");
incomingModifications.add(mod);
}
public void addModifications(Collection mods) {
incomingModifications.addAll(mods);
}
//-------------------------------------------------------------------
/**
* @see de.rpgframework.genericrpg.modification.Modifyable#setIncomingModifications(java.util.List)
*/
@Override
public void removeIncomingModification(Modification mod) {
incomingModifications.remove(mod);
}
//-------------------------------------------------------------------
public void removeIncomingModificationForSource(Object src) {
for (Modification mod : new ArrayList(incomingModifications)) {
if (mod.getSource().equals(src))
incomingModifications.remove(src);
}
}
//-------------------------------------------------------------------
public void clearOutgoingModifications() { outgoingModifications.clear(); }
public void addOutgoingModification(Modification mod) { outgoingModifications.add(mod); }
public List getOutgoingModifications() {
return new ArrayList(this.outgoingModifications);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy