Подскажите, пожалуйста, что не так. В качестве подсказки говорит, чтоб я убедился, что все person сохраняются. Заранее спасибо! P.S. synchronized(allPeople) ставил перед циклом - не играет роли (это я на всяк случай)
package com.javarush.task.task17.task1711;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/*
CRUD 2
*/
public class Solution {
public static volatile List<Person> allPeople = new ArrayList<Person>();
static {
allPeople.add(Person.createMale("Иванов Иван", new Date())); //сегодня родился id=0
allPeople.add(Person.createMale("Петров Петр", new Date())); //сегодня родился id=1
}
public static void main(String[] args) {
SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH);
SimpleDateFormat sdf2 = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
switch(args[0]){
case "-с": {
for(int i = 1; i < args.length; i += 3){
String name = args[i];
String sex = args[i+1];
Date d = null;
try{
d = sdf1.parse(args[i + 2]);
} catch(ParseException e){
System.out.println(e.getMessage());
}
Person person;
if (sex.equals("м"))
person = Person.createMale(name, d);
else
person = Person.createFemale(name, d);
synchronized(allPeople){
allPeople.add(person);}
System.out.println(allPeople.indexOf(person));
}break;
}
case "-u":{
for(int i = 1; i < args.length; i += 4){
int id = Integer.parseInt(args[i]);
String name = args[i + 1];
String sex = args[i + 2];
Date d = null;
try{
d = sdf1.parse(args[i + 3]);
}catch(ParseException e){
System.out.println(e.getMessage());
}
synchronized(allPeople){
Person person = allPeople.get(id);
person.setName(name);
person.setBirthDay(d);
if(sex.equals("м"))
person.setSex(Sex.MALE);
else
person.setSex(Sex.FEMALE);
}
}break;
}
case "-d":{
synchronized(allPeople){
for(int i = 1; i < args.length; i++){
Person person = allPeople.get(Integer.parseInt(args[i]));
person.setBirthDay(null);
person.setName(null);
person.setSex(null);
}
}break;
}
case "-i":{
synchronized(allPeople){
for(int i = 1; i < args.length; i++){
Person person = allPeople.get(Integer.parseInt(args[i]));
System.out.println(String.format("%s %s %s", person.getName(),
(person.getSex() == Sex.MALE ? "м" : "ж"),
sdf2.format(person.getBirthDay())));
}
}
}break;
}
}
}