private Person findById(int id) { for (Person person : storage) { if (person.getId() == id) { return person; } } return null; }
public Set<Person> findByName(String name) { Set<Person> personByNameSet = new HashSet<Person>(); for (Person person : storage) { if (person.getName().indexOf(name) != -1) { personByNameSet.add(person); } } return personByNameSet; }
public Set<Person> findByAge(int age) { Set<Person> personByAgeSet = new HashSet<Person>(); for (Person person : storage) { if (person.getAge() == age) { personByAgeSet.add(person); } } return personByAgeSet; }
public boolean exists(int id) { Person p = new Person(); p.setId(id); return storage.contains(p); }
public boolean exists(String name, int age) { Person p = new Person(); p.setAge(age); p.setName(name); return storage.contains(p); }
public void add(Person person) { Person copy = new Person(person); copy.setId(nextId()); System.out.println(">>adding person: " + copy); this.storage.add(copy); }