вроде все норм, или я что-то упустил?
package com.javarush.task.task17.task1710;
import java.util.*;
/*
CRUD
*/
public class Solution {
public static List<Person> allPeople = new ArrayList<Person>();
private static HashSet<String> sexArgs;
static {
sexArgs = new HashSet<String>(){{add("м");add("ж");}};
allPeople.add(Person.createMale("Иванов Иван", new Date())); //сегодня родился id=0
allPeople.add(Person.createMale("Петров Петр", new Date())); //сегодня родился id=1
}
public static void main(String[] args) {
//start here - начни тут
showAll();
System.out.println("\n\n\n");
int sexIndex = 0;
for (int i = 0; i<args.length; i++){
if (sexArgs.contains(args[i])){
sexIndex = i;
break;
}
}
switch(args[0]){
case "-c":
{
add(args,sexIndex);
break;
}
case "-u":
{
try{
update(Integer.parseInt(args[1]),args,sexIndex);
}catch(IllegalFormatException lfe){
lfe.printStackTrace();
}
break;
}
case "-d":
{
logicRemove(Integer.parseInt(args[1]));
break;
}
case "-i":
{
show(Integer.parseInt(args[1]));
break;
}
}
}
private static void add (String[] args, int sexIndex)throws IllegalArgumentException{
if(!sexArgs.contains(args[sexIndex]))
throw new IllegalArgumentException("Illegal sex arg");
if (args[sexIndex].equals("м"))
allPeople.add(Person.createMale(getName(args,sexIndex),new Date(args[args.length-1])));
else allPeople.add(Person.createFemale(getName(args,sexIndex),new Date(args[args.length-1])));
}
private static String getName (String[] args, int sexIndex){
String name="";
for (int i = 1; i < sexIndex; i++){
if (!args[0].equals("-c")&&i==1)continue;
name+=args[i]+" ";
}
return name;
}
private static void update (int id, String[]args, int sexIndex){
allPeople.get(id).setName(getName(args, sexIndex));
allPeople.get(id).setBirthDay(new Date(args[args.length-1]));
allPeople.get(id).setSex(args[sexIndex].equals("ж") ? Sex.FEMALE : Sex.MALE);
}
private static Person lookUp (int id)throws IllegalArgumentException{
for (int i=0; i<allPeople.size(); i++){
if (i==id)return allPeople.get(i);
}
throw new IllegalArgumentException("no id");
}
private static void showAll(){
for(Person pers: allPeople){
System.out.println(pers);
}
}
private static void logicRemove(int id) {
allPeople.set(id, null);
}
private static void show (int id) {
System.out.println(allPeople.get(id));
}
}