Make sure rolling stock has at least one coupling

This commit is contained in:
Arne Keller 2020-02-29 11:11:00 +01:00
parent 8f8baf6701
commit 324231ef07

View File

@ -27,13 +27,16 @@ public abstract class RollingStock {
* @param length length of this rolling stock
* @param couplingFront whether this rolling stock should have a front coupling
* @param couplingBack whether this rolling stock should have a back coupling
* @throws InvalidInputException on invalid user input (zero-sized coach)
* @throws InvalidInputException on invalid user input (e.g. zero-sized coach)
*/
protected RollingStock(final int length, final boolean couplingFront, final boolean couplingBack)
throws InvalidInputException {
if (length < 1) {
throw new InvalidInputException("rolling stock length has to be positive");
}
if (!couplingFront && !couplingBack) {
throw new InvalidInputException("rolling stocks needs at least one coupling");
}
this.length = length;
this.couplingFront = couplingFront;
this.couplingBack = couplingBack;