FinalStateMachine/src/main/java/me/bvn13/fsm/exceptions/AmbiguousTransitionExceptio...

26 lines
767 B
Java
Raw Normal View History

2022-07-07 02:15:12 +03:00
package me.bvn13.fsm.exceptions;
2017-12-28 15:30:26 +03:00
import java.util.List;
import static java.lang.String.format;
2017-12-28 15:30:26 +03:00
/**
2022-07-07 02:15:12 +03:00
* is thrown if there are more than 1 appropriate transition from current state
2017-12-28 15:30:26 +03:00
*/
2022-07-07 02:15:12 +03:00
public class AmbiguousTransitionException extends FsmException {
2017-12-28 15:30:26 +03:00
public AmbiguousTransitionException(String message) {
super(message);
}
public AmbiguousTransitionException(String from, List<String> next) {
super(format("Ambiguous transition from state %s. Candidates are: %s", from, join(next)));
}
private static String join(List<String> list) {
StringBuilder msg = new StringBuilder();
for (String to : list) {
msg.append(msg.length() > 0 ? ", " : "").append(to);
2017-12-28 15:30:26 +03:00
}
return msg.toString();
2017-12-28 15:30:26 +03:00
}
}