summaryrefslogtreecommitdiffstats
path: root/šola/p1/dn/9/Shramba.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--šola/p1/dn/9/Shramba.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/šola/p1/dn/9/Shramba.java b/šola/p1/dn/9/Shramba.java
new file mode 100644
index 0000000..c212b9c
--- /dev/null
+++ b/šola/p1/dn/9/Shramba.java
@@ -0,0 +1,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);
+ }
+}