String realData = parsingResult.toString();
//Splits the file in lines
List<String> lines = Arrays.asList( LINE_DELIMITER_PATTERN.split( realData ) );
if ( lines.isEmpty() ) {
throw new ParsingFailException( "Empty file" );
}
//Find player position first
final Iterator<String> skipFirstLineTrick = lines.iterator();
String firstLine;
try {
do {
firstLine = skipFirstLineTrick.next();
//Remove spaces
firstLine = SPACE_PATTERN.matcher( firstLine ).replaceAll( "" );
} while ( ! VALID_PLAYER_POSITION_PATTERN.matcher( firstLine ).matches() );
} catch ( NoSuchElementException e ) {
//If player position line couldn't be found...
throw new ParsingFailException( "Can't find a valid player position", e );
}
try {
final Point validPosition = parsePlayerPositionLine( firstLine );
this.playerPosition.x = validPosition.x;
this.playerPosition.y = validPosition.y;
} catch ( NumberFormatException e ) {
throw new ParsingFailException( e );
}
/* End of the parsing of the initial player position */
/* Parse the other lines */
while ( skipFirstLineTrick.hasNext() ) {