-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDatabase.java
More file actions
42 lines (34 loc) · 1022 Bytes
/
Database.java
File metadata and controls
42 lines (34 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.yurii.salimov.lesson10.task05;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @author Yuriy Salimov (yuriy.alex.salimov@gmail.com)
* @version 1.0
*/
public final class Database<K, V> implements Serializable {
private static final long serialVersionUID = 1L;
private final HashMap<K, V> map = new HashMap<>();
public void add(final K key, final V value) {
this.map.put(key, value);
}
public void delete(final K key) {
this.map.remove(key);
}
public V get(final K key) {
return this.map.get(key);
}
@Override
public String toString() {
if (this.map.isEmpty()) {
return "Database is empty!";
}
final StringBuilder sb = new StringBuilder();
for (Map.Entry<K, V> entry : this.map.entrySet()) {
sb.append(entry.getKey())
.append(" ")
.append(entry.getValue());
}
return sb.toString();
}
}