blob: c212b9c6343c4c025f7eaeca5120712a23de4673 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import java.util.*;
public class Shramba {
static Map<Class<?>, Integer> hranjenja = new HashMap<Class<?>, Integer>();
public static Map<Preganjanje, Integer> preganjanja = new HashMap<Preganjanje, Integer>();
public void seHrani () {
for (Class<?> r = this.getClass(); r.getSuperclass() != null; r = r.getSuperclass())
hranjenja.put(r, hranjenja.getOrDefault(r, 0)+1);
}
public int steviloHranjenj () {
return hranjenja.getOrDefault(this.getClass(), 0);
}
public void preganja (Zival z) {
for (Class<?> s = this.getClass(); s.getSuperclass() != null; s = s.getSuperclass())
for (Class<?> t = z.getClass(); t.getSuperclass() != null; t = t.getSuperclass()) {
Preganjanje p = new Preganjanje(s, t);
preganjanja.put(p, preganjanja.getOrDefault(p, 0)+1);
}
}
public int steviloPreganjanj (Zival z) {
return preganjanja.getOrDefault(new Preganjanje(this.getClass(), z.getClass()), 0);
}
}
|