package nl.ru.ai.projects.parrot.biomav.editor;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.security.InvalidParameterException;
import java.util.HashMap;
import java.util.Map;
import nl.ru.ai.projects.parrot.biomav.editor.states.BehaviorArray;
import nl.ru.ai.projects.parrot.biomav.editor.transitions.Delay;
import nl.ru.ai.projects.parrot.biomav.editor.transitions.OutOfSight;
import nl.ru.ai.projects.parrot.biomav.editor.transitions.PoleFound;
import nl.ru.ai.projects.parrot.fsm.State;
import nl.ru.ai.projects.parrot.fsm.Transition;
@SuppressWarnings("rawtypes")
public static final Map<String, Class> FSM_TRANSITIONS = new HashMap<String, Class>();
static {
FSM_TRANSITIONS.put("Pole found", PoleFound.class);
FSM_TRANSITIONS.put("Out of sight", OutOfSight.class);
FSM_TRANSITIONS.put("Close to pole", OutOfSight.class);
FSM_TRANSITIONS.put("Delay", Delay.class);
}
private String selectedTransition = FSM_TRANSITIONS.keySet().toArray()[0].toString();
return selectedTransition;
}
if (!FSM_TRANSITIONS.containsKey(t)) {
throw new InvalidParameterException("setTransition: " + t);
}
selectedTransition = t;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public Transition
initTransition(BehaviorArray ba, State from, State to) {
Class transitionClass = FSM_TRANSITIONS.get(selectedTransition);
try {
Constructor c = transitionClass.getConstructor(BehaviorArray.class, State.class);
Transition result = (Transition) c.newInstance(ba, to);
from.addTransition(result);
return result;
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
@Override
String[] result = {"Transition"};
return result;
}
@Override
ParameterTypes[] result = {ParameterTypes.OPTIONS};
return result;
}
@Override
return FSM_TRANSITIONS.keySet().toArray();
}
@Override
return getTransition();
}
@Override
setTransition(value.toString());
}
}