org.jbpt.petri.unfolding.AbstractCoSet Maven / Gradle / Ivy
Show all versions of jbpt-petri Show documentation
package org.jbpt.petri.unfolding;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
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 class AbstractCoSet, C extends ICondition, E extends IEvent, F extends IFlow, N extends INode, P extends IPlace, T extends ITransition, M extends IMarking>
extends HashSet
implements ICoSet
{
private static final long serialVersionUID = 1L;
public AbstractCoSet() {}
private Map> p2cs = new HashMap
>();
@Override
public int hashCode() {
int code = 0;
for (C c : this) {
code += c.hashCode();
}
return code;
}
@Override
public boolean add(C c) {
if (this.p2cs.get(c.getPlace())==null) {
Set cs = new HashSet();
cs.add(c);
this.p2cs.put(c.getPlace(),cs);
}
else
this.p2cs.get(c.getPlace()).add(c);
return super.add(c);
}
@Override
public boolean addAll(Collection extends C> cs) {
boolean result=false;
for (C c : cs) result |= this.add(c);
return result;
}
@Override
public boolean remove(Object c) {
return super.remove(c);
}
@Override
public boolean removeAll(Collection> cs) {
return super.removeAll(cs);
}
@Override
public Set getConditions(P place) {
return this.p2cs.get(place);
}
@Override
public Collection getPlaces() {
Collection
result = new ArrayList
();
for (C c : this)
result.add(c.getPlace());
return result;
}
}