Друзі, треба допомога з моїм огородом. валідатор не пропускає. але начебто перевірив с дебагом усі режими (CIUD). мабуть це якось зв'язано що я використовую while замість for ?
package ua.javarush.task.task17.task1711;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
/*
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) {
// start here - почни тут
try {
switch (args[0]){
case "-c" :
// [0] -c [1]Миронов [2]ч [3]15/04/1990 [4]Миронова [5]ж [6]25/04/1997
try {
int i = 0;
int numberArgForName = 1;
int numberArgForSex = 2;
int numberArgForDate = 3;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy",Locale.ENGLISH);
while (i < args.length-1){
synchronized (allPeople){
int lastIndex = allPeople.size();
if (args[numberArgForSex].equals("ч")){
allPeople.add(lastIndex, Person.createMale(args[numberArgForName],simpleDateFormat.parse(args[numberArgForDate])));
} else if (args[numberArgForSex].equals("ж")) {
allPeople.add(lastIndex, Person.createFemale(args[numberArgForName],simpleDateFormat.parse(args[numberArgForDate])));
}
numberArgForName+=3;
numberArgForSex+=3;
numberArgForDate+=3;
System.out.print(lastIndex);
System.out.print(" ");
i+=3;
}
}
}catch (Exception e){
System.out.println("Something wrong in the part with param -c " +e);
}
break;
case "-u" :
//[0]-u [1]0 [2]Миронов [3]ч [4]15/04/1990 [5]1 [6]Миронова [7]ж [8]25/04/1997
try {
int i = 1;
int numberArgForId = 1;
int numberArgForName = 2;
int numberArgForSex = 3;
int numberArgForDate = 4;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy",Locale.ENGLISH);
while (i < args.length-1) {
synchronized (allPeople) {
Person person = allPeople.get(Integer.parseInt(args[numberArgForId]));
person.setName(args[numberArgForName]);
if (args[numberArgForSex].equals("ч")) person.setSex(Sex.MALE);
if (args[numberArgForSex].equals("ж")) person.setSex(Sex.FEMALE);
person.setBirthDate(simpleDateFormat.parse(args[numberArgForDate]));
numberArgForId += 4;
numberArgForName += 4;
numberArgForSex += 4;
numberArgForDate += 4;
i += 4;
}
}
}catch (Exception e){
System.out.println("Something wrong in the part with param -u! " +e);
}
break;
case "-d" :
try{
int i = 0;
int numberArgForId = 1;
while (i < args.length-1) {
synchronized (allPeople) {
Person person = allPeople.get(Integer.parseInt(args[numberArgForId]));
person.setName(null);
person.setSex(null);
person.setBirthDate(null);
numberArgForId += 1;
i++;
}
}
}catch (Exception e){
System.out.println("Something wrong in the part with param -d " +e);
}
break;
case "-i" :
// -i id1 id2 id3 id4
try {
int i = 0;
int numberArgForId = 1;
StringBuilder stringBuilder = new StringBuilder();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yyyy",Locale.ENGLISH);
while (i < args.length-1) {
synchronized (allPeople) {
Person person = allPeople.get(Integer.parseInt(args[numberArgForId]));
stringBuilder.append(person.getName());
stringBuilder.append(" ");
if (person.getSex().equals(Sex.MALE)) stringBuilder.append("ч");
if (person.getSex().equals(Sex.FEMALE)) stringBuilder.append("ж");
stringBuilder.append(" ");
stringBuilder.append(simpleDateFormat.format(person.getBirthDate()));
numberArgForId += 1;
i++;
}
System.out.println(stringBuilder.toString());
stringBuilder.setLength(0);
}
}catch (Exception e){
System.out.println("Something wrong in the part with param -i " +e);
}
break;
default:
break;
}
}catch (Exception e){
System.out.println("Something wrong in the main part! " +e);
}
}
}