org.jbpt.petri.unfolding.AbstractEvent 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.unfolding;
import org.jbpt.petri.IFlow;
import org.jbpt.petri.IMarking;
import org.jbpt.petri.INode;
import org.jbpt.petri.IPlace;
import org.jbpt.petri.ITransition;
public abstract class AbstractEvent, C extends ICondition, E extends IEvent, F extends IFlow, N extends INode, P extends IPlace, T extends ITransition, M extends IMarking>
extends AbstractBPNode
implements IEvent {
static private int count = 0;
// required to capture unfolding
private T t = null; // transition that corresponds to event
private ICoSet pre = null; // preconditions of event - *e
// for convenience reasons
private ICoSet post = null; // postconditions of event - e*
private ILocalConfiguration lc = null;
private ICompletePrefixUnfolding CPU = null;
protected AbstractEvent() {
this.ID = ++AbstractEvent.count;
}
/**
* Constructor.
*
* @param unf Reference to the unfolding.
* @param transition Transition whose occurrence is represented by this event.
* @param preset Preset of conditions which caused this event to occur.
*/
public AbstractEvent(ICompletePrefixUnfolding cpu, T transition, ICoSet preset) {
this.ID = ++AbstractEvent.count;
this.CPU = cpu;
this.t = transition;
this.pre = preset;
}
@Override
public ICoSet getPostConditions() {
return this.post;
}
@Override
public T getTransition() {
return this.t;
}
@Override
public ICoSet getPreConditions() {
return this.pre;
}
@Override
public String toString() {
return this.getName();
}
@Override
public String getName() {
return String.format("%s-%s-%s",this.ID,this.t.getName(),t.getLabel());
}
@Override
public boolean equals(Object that) {
if (that == null || !(that instanceof IEvent)) return false;
if (this == that) return true;
@SuppressWarnings("unchecked")
E thatE = (E) that;
if (this.getTransition().equals(thatE.getTransition())
&& this.getPreConditions().equals(thatE.getPreConditions()))
return true;
return false;
}
@Override
public int hashCode() {
int hashCode = 7 * this.getTransition().hashCode();
for (C c : this.getPreConditions())
hashCode += 11 * c.getPlace().hashCode();
return hashCode;
}
@SuppressWarnings("unchecked")
@Override
public N getPetriNetNode() {
return (N)this.t;
}
@Override
public boolean isEvent() {
return true;
}
@Override
public boolean isCondition() {
return false;
}
@Override
public void setTransition(T transition) {
this.t = transition;
}
@Override
public void setPreConditions(ICoSet preConditions) {
this.pre = preConditions;
}
@Override
public void setPostConditions(ICoSet postConditions) {
this.post = postConditions;
}
@SuppressWarnings("unchecked")
@Override
public ILocalConfiguration getLocalConfiguration() {
if (this.lc!=null) return this.lc;
ILocalConfiguration lc = null;
try {
lc = (ILocalConfiguration)AbstractLocalConfiguration.class.newInstance();
} catch (InstantiationException e) {
return null;
} catch (IllegalAccessException e) {
return null;
}
lc.setEvent((E)this);
lc.setCompletePrefixUnfolding(this.CPU);
lc.construct();
this.lc = lc;
return this.lc;
}
@Override
public void setCompletePrefixUnfolding(ICompletePrefixUnfolding cpu) {
this.CPU = cpu;
}
}