@Override public Person personAendern(Person person) throws Exception { // check params if (person == null) { throw new PersonException("person == null"); } // check oid String oid = person.getOid(); if (oid == null || oid.isEmpty()) { String message = String.format("oid(%) invalid", oid); throw new PersonException(message); } // check existence if (!personStore.containsKey(oid)) { String message = String.format("oid(%) unknown", oid); throw new PersonException(message); } // replace personStore.put(oid, person); // notify listeners listenerApi.personGeaendert(person); // return result return person; }
@Override public List<Person> list4Jahr(int jahr) { // declare result List<Person> personList = new ArrayList<>(personStore.size()); // copy store for (Person person : personStore.values()) { // check geburtsDatum as calendar Date geburtsDatum = person.getGeburtsDatum(); if (geburtsDatum == null) { continue; } Calendar cal = Calendar.getInstance(); cal.setTime(geburtsDatum); // check jahrgang if (cal.get(Calendar.YEAR) == jahr) { personList.add(new Person(person)); } } // return result return personList; }
@Override public Person personAnlegen(Person person) throws Exception { // check params if (person == null) { throw new PersonException("person == null"); } // generate oid String newOid = generateOid(); person.setOid(newOid); // put clone in map personStore.put(newOid, new Person(person)); // notify listeners listenerApi.personAngelegt(person); // return person return person; }
@Override public void personLoeschen(Person person) throws Exception { // check params if (person == null) { throw new PersonException("person == null"); } // check oid String oid = person.getOid(); if (oid == null || oid.isEmpty()) { String message = String.format("oid(%) invalid", oid); throw new PersonException(message); } // remove from map if (personStore.remove(oid) == null) { String message = String.format("oid(%) unknown", oid); throw new PersonException(message); } // notify listeners listenerApi.personGeloescht(person); }