Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package repository;
- import java.util.LinkedHashMap;
- public class Repository {
- private int id;
- private LinkedHashMap<Integer, Person> data;
- public Repository() {
- this.data = new LinkedHashMap<>();
- this.id = 0;
- }
- public void add(Person person) {
- data.put(id, person);
- id++;
- }
- public Person get(int id) {
- return this.data.get(id);
- }
- public boolean update(int id, Person newPerson) {
- if (data.containsKey(id)) {
- data.put(id, newPerson);
- return true;
- }
- return false;
- }
- public boolean delete(int id) {
- if (data.containsKey(id)) {
- data.remove(id);
- return true;
- }
- return false;
- }
- public int getCount() {
- return data.size();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement