org.jbpt.petri.untangling.pss.AbstractProcessSetSystem Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbpt-petri Show documentation
Show all versions of jbpt-petri Show documentation
The jBPT code library is a compendium of technologies that support research on design, execution, and evaluation of business processes.
The newest version!
package org.jbpt.petri.untangling.pss;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.jbpt.petri.IFlow;
import org.jbpt.petri.IMarking;
import org.jbpt.petri.INetSystem;
import org.jbpt.petri.INode;
import org.jbpt.petri.IPlace;
import org.jbpt.petri.ITransition;
import org.jbpt.petri.unfolding.IBPNode;
import org.jbpt.petri.unfolding.ICondition;
import org.jbpt.petri.unfolding.IEvent;
import org.jbpt.petri.untangling.IProcess;
/**
* An abstract implementation of the {@link IProcessSetSystem} interface.
*
* @author Artem Polyvyanyy
*/
public abstract class AbstractProcessSetSystem, C extends ICondition, E extends IEvent,
F extends IFlow, N extends INode, P extends IPlace, T extends ITransition, M extends IMarking>
implements IProcessSetSystem
{
private INetSystem system = null;
private Collection> systems = null;
@SuppressWarnings("unchecked")
public AbstractProcessSetSystem(INetSystem sys, Collection> pis) {
if (sys==null) return;
if (pis==null) return;
this.system = sys;
this.systems = new ArrayList>();
for (IProcess pi : pis) {
IProcessSystem pSystem = null;
try {
pSystem = (IProcessSystem) ProcessSystem.class.newInstance();
} catch (InstantiationException e) {
continue;
} catch (IllegalAccessException e) {
continue;
}
pSystem.setSystem(sys);
pSystem.setProcess(pi);
this.systems.add(pSystem);
}
}
@Override
public Collection> getProcessSystems() {
return this.systems;
}
@Override
public Set getEnabledTransitions() {
Set result = new HashSet();
for (IProcessSystem pSystem : this.systems)
result.addAll(pSystem.getEnabledTransitions());
return result;
}
@Override
public M getMarking() {
return this.system.getMarking();
}
@Override
public boolean fire(T transition) {
Collection> toRemove = new ArrayList>();
boolean flag = false;
for (IProcessSystem sys : this.systems) {
if (sys.getEnabledTransitions().contains(transition)) {
flag = true;
}
else
toRemove.add(sys);
}
if (!flag) return false;
this.systems.removeAll(toRemove);
return this.system.fire(transition);
}
@Override
public INetSystem getNetSystem() {
return this.system;
}
}