Сперва попробовал добавлять в мпунктамапу через
while (reader.ready()){
String line = reader.readLine();
Matcher matcher = pattern.matcher(line);
while (matcher.find()){
namesDates.put(line.substring(matcher.start(),matcher.end()-1),
formatter.parse(line.substring(matcher.end(),line.length())));
}
}
Не проходило, теперь через replaceAll и trim(), все равно не проходит, хотя и в том и в том случае вывод из списка PEOPLE как в задании.
package com.javarush.task.task19.task1921;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PipedOutputStream;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
Хуан Хуанович
*/
public class Solution {
public static final List<Person> PEOPLE = new ArrayList<Person>();
public static void main(String[] args) throws IOException, ParseException {
HashMap<String, Date> namesDates = new HashMap<>();
SimpleDateFormat formatter = new SimpleDateFormat("d M y", Locale.ENGLISH);
BufferedReader reader = new BufferedReader(new FileReader(args[0]));//"C:\\test.txt"
while (reader.ready()){
String line = reader.readLine();
String name = line.replaceAll("\\d", "").trim();
String birthdate = line.replace(name,"");
namesDates.put(name,formatter.parse(birthdate));
}
reader.close();
for (HashMap.Entry<String, Date> pair : namesDates.entrySet()) {
PEOPLE.add(new Person(pair.getKey(), pair.getValue()));
}
// for (int i = 0; i < PEOPLE.size(); i++) {
// System.out.println(PEOPLE.get(i).getName() + " " + PEOPLE.get(i).getBirthDate());
// }
}
}