I don`t know what is wrong, i tried to crash it with space before name, after name, different dates, but all works fine and not pass the name test.
Can someone help please, with figuer out what i miss?
package com.codegym.task.task19.task1921;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
John Johnson
*/
public class Solution {
public static final List<Person> PEOPLE = new ArrayList<>();
public static void main(String[] args) throws IOException, ParseException {
BufferedReader rd = new BufferedReader(new FileReader(args[0]));
ArrayList<String> arr = new ArrayList<>();
while(rd.ready()){
String str = rd.readLine();
Pattern p = Pattern.compile("[^ \\d][^\\d]+[^ \\d]");
Matcher m = p.matcher(str);
String name = "";
while(m.find()){
name = m.group(0);
break;
}
Pattern pp = Pattern.compile("\\d+[ \\d]+");
Matcher mm = pp.matcher(str);
SimpleDateFormat sdf = new SimpleDateFormat("MM dd yyyy");
Date date = null;
while(mm.find()){
date = sdf.parse(mm.group(0));
break;
}
if(!name.equals("") && date != null) {
PEOPLE.add(new Person(name, date));
}
}
/*
for(Person r : PEOPLE){
System.out.println(r.getName() + " - " + r.getBirthDate());
}
*/
rd.close();
}
}