summaryrefslogtreecommitdiffstats
path: root/šola/p1/dn
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2024-01-06 23:41:23 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2024-01-06 23:41:23 +0100
commita818828950b7afde8d7a334b088026bc2b1a562f (patch)
tree1e3bd05954d80c4432b905657142abc0378a6499 /šola/p1/dn
parentb šola (diff)
downloadr-a818828950b7afde8d7a334b088026bc2b1a562f.tar
r-a818828950b7afde8d7a334b088026bc2b1a562f.tar.gz
r-a818828950b7afde8d7a334b088026bc2b1a562f.tar.bz2
r-a818828950b7afde8d7a334b088026bc2b1a562f.tar.lz
r-a818828950b7afde8d7a334b088026bc2b1a562f.tar.xz
r-a818828950b7afde8d7a334b088026bc2b1a562f.tar.zst
r-a818828950b7afde8d7a334b088026bc2b1a562f.zip
Diffstat (limited to 'šola/p1/dn')
-rw-r--r--šola/p1/dn/9/Kaca.java1
-rw-r--r--šola/p1/dn/9/Lev.java1
-rw-r--r--šola/p1/dn/9/Macka.java1
-rw-r--r--šola/p1/dn/9/Medved.java1
-rw-r--r--šola/p1/dn/9/Plazilec.java1
-rw-r--r--šola/p1/dn/9/Preganjanje.java25
-rw-r--r--šola/p1/dn/9/Sesalec.java1
-rw-r--r--šola/p1/dn/9/Shramba.java22
-rw-r--r--šola/p1/dn/9/Test.java19
-rw-r--r--šola/p1/dn/9/Tiger.java1
-rw-r--r--šola/p1/dn/9/Zelva.java1
-rw-r--r--šola/p1/dn/9/Zival.java1
-rw-r--r--šola/p1/dn/9/ZivalImplementacija.java21
13 files changed, 96 insertions, 0 deletions
diff --git a/šola/p1/dn/9/Kaca.java b/šola/p1/dn/9/Kaca.java
new file mode 100644
index 0000000..114f3b4
--- /dev/null
+++ b/šola/p1/dn/9/Kaca.java
@@ -0,0 +1 @@
+public class Kaca extends Plazilec {}
diff --git a/šola/p1/dn/9/Lev.java b/šola/p1/dn/9/Lev.java
new file mode 100644
index 0000000..f593344
--- /dev/null
+++ b/šola/p1/dn/9/Lev.java
@@ -0,0 +1 @@
+public class Lev extends Macka {}
diff --git a/šola/p1/dn/9/Macka.java b/šola/p1/dn/9/Macka.java
new file mode 100644
index 0000000..ae23486
--- /dev/null
+++ b/šola/p1/dn/9/Macka.java
@@ -0,0 +1 @@
+public class Macka extends Sesalec {}
diff --git a/šola/p1/dn/9/Medved.java b/šola/p1/dn/9/Medved.java
new file mode 100644
index 0000000..20515ba
--- /dev/null
+++ b/šola/p1/dn/9/Medved.java
@@ -0,0 +1 @@
+public class Medved extends Sesalec {}
diff --git a/šola/p1/dn/9/Plazilec.java b/šola/p1/dn/9/Plazilec.java
new file mode 100644
index 0000000..1e46073
--- /dev/null
+++ b/šola/p1/dn/9/Plazilec.java
@@ -0,0 +1 @@
+public class Plazilec extends Zival {}
diff --git a/šola/p1/dn/9/Preganjanje.java b/šola/p1/dn/9/Preganjanje.java
new file mode 100644
index 0000000..74485d1
--- /dev/null
+++ b/šola/p1/dn/9/Preganjanje.java
@@ -0,0 +1,25 @@
+import java.util.*;
+public class Preganjanje {
+ private Class<?> preganjalec;
+ private Class<?> preganjan;
+ public Preganjanje (Class<?> preganjalec, Class<?> preganjan) {
+ this.preganjalec = preganjalec;
+ this.preganjan = preganjan;
+ }
+ public int hashCode () {
+ return 1;
+ //return Objects.hash(preganjalec, preganjan);
+ }
+ @Override
+ public boolean equals (Object drugi) {
+ if (this == drugi)
+ return true;
+ if (drugi == null || getClass() != drugi.getClass())
+ return false;
+ Preganjanje drugo = (Preganjanje) drugi;
+ return preganjalec.equals(drugo.preganjalec) && preganjan.equals(drugo.preganjan);
+ }
+ public String toString () {
+ return String.format("%s->%s", preganjalec.getName(), preganjan.getName());
+ }
+}
diff --git a/šola/p1/dn/9/Sesalec.java b/šola/p1/dn/9/Sesalec.java
new file mode 100644
index 0000000..611513c
--- /dev/null
+++ b/šola/p1/dn/9/Sesalec.java
@@ -0,0 +1 @@
+public class Sesalec extends Zival {}
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);
+ }
+}
diff --git a/šola/p1/dn/9/Test.java b/šola/p1/dn/9/Test.java
new file mode 100644
index 0000000..d0a83d4
--- /dev/null
+++ b/šola/p1/dn/9/Test.java
@@ -0,0 +1,19 @@
+import java.util.*;
+public class Test {
+ public static void main (String[] args) {
+ Zival z = new Zival();
+ Zival z2 = new Zival();
+ Sesalec s = new Sesalec();
+ Medved m = new Medved();
+ Tiger t = new Tiger();
+ z.seHrani();
+ s.seHrani();
+ t.preganja(m);
+ t.preganja(m);
+ System.out.println(Arrays.toString(t.preganjanja.entrySet().toArray()));
+ System.out.println("z: " + z.steviloHranjenj() + " z2: " + z2.steviloHranjenj());
+ System.out.println("---");
+ System.out.println("t->m: " + t.steviloPreganjanj(m));
+ System.out.println("t->m: " + z.steviloPreganjanj(z));
+ }
+}
diff --git a/šola/p1/dn/9/Tiger.java b/šola/p1/dn/9/Tiger.java
new file mode 100644
index 0000000..14a70da
--- /dev/null
+++ b/šola/p1/dn/9/Tiger.java
@@ -0,0 +1 @@
+public class Tiger extends Macka {}
diff --git a/šola/p1/dn/9/Zelva.java b/šola/p1/dn/9/Zelva.java
new file mode 100644
index 0000000..cfb4cde
--- /dev/null
+++ b/šola/p1/dn/9/Zelva.java
@@ -0,0 +1 @@
+public class Zelva extends Plazilec {}
diff --git a/šola/p1/dn/9/Zival.java b/šola/p1/dn/9/Zival.java
new file mode 100644
index 0000000..5ccfed4
--- /dev/null
+++ b/šola/p1/dn/9/Zival.java
@@ -0,0 +1 @@
+public class Zival extends Shramba {}
diff --git a/šola/p1/dn/9/ZivalImplementacija.java b/šola/p1/dn/9/ZivalImplementacija.java
new file mode 100644
index 0000000..c5ba81e
--- /dev/null
+++ b/šola/p1/dn/9/ZivalImplementacija.java
@@ -0,0 +1,21 @@
+// unused
+import java.util.*;
+public class ZivalImplementacija {
+ int hranjenj;
+ List<ZivalImplementacija> implementacije;
+ public void dodajImplementacijo (ZivalImplementacija z) {
+ if (implementacije == null)
+ implementacije = new ArrayList<ZivalImplementacija>();
+ implementacije.add(z);
+ }
+ public void seHrani () {
+ this.hranjenj++;
+ }
+ public int steviloHranjenj () {
+ int r = hranjenj;
+ if (implementacije != null)
+ for (ZivalImplementacija i : implementacije)
+ r += i.steviloHranjenj();
+ return r;
+ }
+}