/** * Parses a configuration from string * * @param roverConfiguration * @return IllegalArgumentException if string argument is empty null or does not represent a * valide rover configuration */ public static RoverConfiguration parseConfiguration(String roverConfiguration) { if (roverConfiguration == null || roverConfiguration.length() == 0) { throw new IllegalArgumentException("RoverConfiguration can not be null on empty"); } String[] feilds = roverConfiguration.split(" "); if (feilds.length != 3) { throw new IllegalArgumentException( "Not a valide rover configuration[" + roverConfiguration + "] must have format X Y P (p belongs to {N,S,E,W})"); } GridLocation gridLocation = GridLocation.parseGridLocation(feilds[0], feilds[1]); Position position = AbstractPosition.parsePosition(feilds[2]); return new RoverConfiguration(position, gridLocation); }
/** @return */ @Override public String toString() { return currentLocation.toString() + " " + currentPosition.toString(); }