/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package graphjx.algorithm;
import graphjx.structure.Model;
import graphjx.structure.ValidationException;
/**
*
* @author Davide De Pasquale
*/
public abstract class Algorithm<T extends Model> {
private T model;
/**
* Creates a new algorithm given a model.
*
* @param model
*/
public Algorithm(T model) {
this.model = model;
}
/**
*
* @return
*/
public final T getDomain() {
return this.model;
}
public abstract void init();
public final Model process(Model model) throws ValidationException {
if (!model.isValidated()) {
model.validate();
}
if (!model.isValidated()) {
throw new ValidationException("Cannot validate model");
}
Model m = doProcess(model);
return m;
}
protected abstract Model doProcess(Model model);
}