Skip to content
Snippets Groups Projects
Commit a37d1e2c authored by dgelessus's avatar dgelessus
Browse files

Remove out of place copy of de.prob.model.representation sources

parent 30701f09
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 418 deletions
package de.prob.model.representation;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
/**
* This class is the subclass of all model elements (Models, Machines, Contexts,
* Variables, etc.)
*
* @author joy
*
*/
public abstract class AbstractElement {
protected Map<Class<? extends AbstractElement>, java.util.Set<? extends AbstractElement>> children = new HashMap<Class<? extends AbstractElement>, Set<? extends AbstractElement>>();
/**
* Each {@link AbstractElement} can have children of a subclass that extends
* {@link AbstractElement}. These are specified by the class of the child.
* To get a Set of all of the children of a particular class, use this
* method.
*
* @param c
* {@link Class} T of the desired type of children
* @return {@link Set} containing all the children of type T
*/
@SuppressWarnings("unchecked")
public <T extends AbstractElement> Set<T> getChildrenOfType(final Class<T> c) {
Set<? extends AbstractElement> set = children.get(c);
if (set == null) {
return Collections.emptySet();
}
return (Set<T>) set;
}
/**
* Maps a {@link Collection} of elements to the specified {@link Class}
*
* @param c
* {@link Class} to specify children elements
* @param elements
* {@link Collection} of elements with which c will be mapped
*/
public <T extends AbstractElement> void put(final Class<T> c,
final Collection<? extends T> elements) {
children.put(c, new LinkedHashSet<T>(elements));
}
/**
* @return the {@link Map} of {@link Class} to {@link Set} of children
*/
public Map<Class<? extends AbstractElement>, java.util.Set<? extends AbstractElement>> getChildren() {
return children;
}
}
package de.prob.model.representation;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import de.prob.model.representation.RefType.ERefType;
import de.prob.statespace.History;
import de.prob.statespace.StateSpace;
import edu.uci.ics.jung.graph.DirectedSparseMultigraph;
public abstract class AbstractModel extends AbstractElement {
protected StateSpace statespace;
protected File modelFile;
protected DirectedSparseMultigraph<String, RefType> graph = new DirectedSparseMultigraph<String, RefType>();
public StateSpace getStatespace() {
return statespace;
}
public abstract AbstractElement getComponent(String name);
// This is needed for the graph representation
public abstract Map<String, AbstractElement> getComponents();
public DirectedSparseMultigraph<String, RefType> getGraph() {
return graph;
}
public ERefType getRelationship(final String comp1, final String comp2) {
return getEdge(comp1, comp2);
}
public ERefType getEdge(final String comp1, final String comp2) {
final RefType edge = graph.findEdge(comp1, comp2);
if (edge == null) {
return null;
}
return edge.getRelationship();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("(");
sb.append(graph.getVertices().toString());
sb.append(", ");
Collection<RefType> edges = graph.getEdges();
List<String> s = new ArrayList<String>();
for (RefType refType : edges) {
String src = graph.getSource(refType);
String dest = graph.getDest(refType);
s.add(refType.toString()+"=("+src+","+dest+")");
}
sb.append(s.toString());
sb.append(")");
return sb.toString();
}
public Object asType(final Class<?> className) {
if (className.getSimpleName().equals("StateSpace")) {
return statespace;
}
if (className.getSimpleName().equals("History")) {
return new History(statespace);
}
throw new ClassCastException("No element of type " + className
+ " found.");
}
public abstract StateSchema getStateSchema();
public abstract AbstractElement getMainComponent();
public File getModelFile() {
return modelFile;
}
}
package de.prob.model.representation;
public abstract class Action extends AbstractElement {
private final String code;
public Action(final String code) {
this.code = code;
}
public String getCode() {
return code;
}
@Override
public String toString() {
return code;
}
}
package de.prob.model.representation;
import de.prob.animator.domainobjects.IEvalElement;
import de.prob.unicode.UnicodeTranslator;
public abstract class Axiom extends AbstractElement implements IEval {
private final IEvalElement predicate;
public Axiom(final IEvalElement predicate) {
this.predicate = predicate;
}
public IEvalElement getPredicate() {
return predicate;
}
@Override
public IEvalElement getEvaluate() {
return predicate;
}
@Override
public String toString() {
return UnicodeTranslator.toUnicode(predicate.getCode());
}
}
package de.prob.model.representation;
public abstract class BEvent extends AbstractElement {
private final String name;
public BEvent(final String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
}
package de.prob.model.representation;
public class BSet extends AbstractElement {
private final String name;
public BSet(final String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
}
package de.prob.model.representation;
import de.prob.animator.domainobjects.EvaluationResult;
import de.prob.animator.domainobjects.IEvalElement;
import de.prob.statespace.History;
import de.prob.unicode.UnicodeTranslator;
public abstract class Constant extends AbstractElement implements IEval {
protected final IEvalElement expression;
protected EvaluationResult result;
public Constant(final IEvalElement expression) {
this.expression = expression;
}
public IEvalElement getExpression() {
return expression;
}
@Override
public IEvalElement getEvaluate() {
return expression;
}
@Override
public String toString() {
return UnicodeTranslator.toUnicode(expression.getCode());
}
// Experimental. Would allow the user to calculate the value once and cache
// it.
public EvaluationResult getValue(final History h) {
if (result == null) {
result = h.evalCurrent(getEvaluate());
}
return result;
}
}
package de.prob.model.representation;
public class FormulaUUID {
static int count = 0;
public final String uuid = "Formula_" + (++count);
}
package de.prob.model.representation;
import de.prob.animator.domainobjects.IEvalElement;
public abstract class Guard extends AbstractElement implements IEval {
private final IEvalElement predicate;
public Guard(final IEvalElement predicate) {
this.predicate = predicate;
}
public IEvalElement getPredicate() {
return predicate;
}
@Override
public IEvalElement getEvaluate() {
return predicate;
}
@Override
public String toString() {
return predicate.toString();
}
}
package de.prob.model.representation;
import de.prob.animator.domainobjects.IEvalElement;
public interface IEval {
public IEvalElement getEvaluate();
}
package de.prob.model.representation;
import de.prob.animator.domainobjects.IEvalElement;
import de.prob.unicode.UnicodeTranslator;
public abstract class Invariant extends AbstractElement implements IEval {
private final IEvalElement predicate;
public Invariant(final IEvalElement predicate) {
this.predicate = predicate;
}
public IEvalElement getPredicate() {
return predicate;
}
@Override
public IEvalElement getEvaluate() {
return predicate;
}
@Override
public String toString() {
return UnicodeTranslator.toUnicode(predicate.getCode());
}
}
package de.prob.model.representation;
public abstract class Machine extends AbstractElement {
private final String name;
public Machine(final String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
}
package de.prob.model.representation;
public class RefType {
private final ERefType relationship;
/*
* RefType is used for both ClassicalBModels and EventBModels
*
* ClassicalB: SEES, USES, REFINES, INCLUDES, IMPORTS EventB: SEES, REFINES,
* EXTENDS
*/
public enum ERefType {
SEES, USES, REFINES, INCLUDES, IMPORTS, EXTENDS
}
public RefType(final ERefType relationship) {
this.relationship = relationship;
}
@Override
public String toString() {
return relationship.toString();
}
public ERefType getRelationship() {
return relationship;
}
}
package de.prob.model.representation;
public interface StateSchema {
public Object[] getElements(Object o);
public boolean hasChildren(Object o);
}
package de.prob.model.representation;
import de.prob.animator.domainobjects.IEvalElement;
import de.prob.unicode.UnicodeTranslator;
public abstract class Variable extends AbstractElement implements IEval {
protected final IEvalElement expression;
public Variable(final IEvalElement expression) {
this.expression = expression;
}
public IEvalElement getExpression() {
return expression;
}
@Override
public IEvalElement getEvaluate() {
return expression;
}
public String getName() {
return expression.getCode();
}
@Override
public String toString() {
return UnicodeTranslator.toUnicode(expression.getCode());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment