Advertisement
N_Damyanov

repository

Feb 17th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. package repository;
  2.  
  3. import java.util.LinkedHashMap;
  4.  
  5. public class Repository {
  6.     private int id;
  7.     private LinkedHashMap<Integer, Person> data;
  8.  
  9.     public Repository() {
  10.         this.data = new LinkedHashMap<>();
  11.         this.id = 0;
  12.     }
  13.  
  14.  
  15.     public void add(Person person) {
  16.         data.put(id, person);
  17.         id++;
  18.     }
  19.  
  20.     public Person get(int id) {
  21.         return this.data.get(id);
  22.     }
  23.  
  24.     public boolean update(int id, Person newPerson) {
  25.         if (data.containsKey(id)) {
  26.             data.put(id, newPerson);
  27.             return true;
  28.         }
  29.         return false;
  30.     }
  31.  
  32.     public boolean delete(int id) {
  33.         if (data.containsKey(id)) {
  34.             data.remove(id);
  35.             return true;
  36.         }
  37.         return false;
  38.     }
  39.  
  40.     public int getCount() {
  41.         return data.size();
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement