From d188a1126a4d4d5cd332cdc40b7a61f13290c55f Mon Sep 17 00:00:00 2001 From: Thomas Smits Date: Thu, 18 Jan 2024 15:19:30 +0100 Subject: [PATCH] Corrected link --- Assignment_076/solution/readme.md | 2 +- .../java/pr2/lambda/observer/Beobachter.java | 5 ++++ .../java/pr2/lambda/observer/Datenhalter.java | 24 +++++++++++++++++++ .../lambda/observer/DatenhalterAnonym.java | 20 ++++++++++++++++ .../lambda/observer/test/BeobachterTest.java | 18 ++++++++++++++ 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 solutions/src/main/java/pr2/lambda/observer/Beobachter.java create mode 100644 solutions/src/main/java/pr2/lambda/observer/Datenhalter.java create mode 100644 solutions/src/main/java/pr2/lambda/observer/DatenhalterAnonym.java create mode 100644 solutions/src/main/java/pr2/lambda/observer/test/BeobachterTest.java diff --git a/Assignment_076/solution/readme.md b/Assignment_076/solution/readme.md index 657e078..fe048c7 100644 --- a/Assignment_076/solution/readme.md +++ b/Assignment_076/solution/readme.md @@ -2,4 +2,4 @@ Musterlösung: -pr2.lambda.observer](../../solutions/src/main/java/pr2/lambda/observer/). +[pr2.lambda.observer](../../solutions/src/main/java/pr2/lambda/observer/). diff --git a/solutions/src/main/java/pr2/lambda/observer/Beobachter.java b/solutions/src/main/java/pr2/lambda/observer/Beobachter.java new file mode 100644 index 0000000..98eb441 --- /dev/null +++ b/solutions/src/main/java/pr2/lambda/observer/Beobachter.java @@ -0,0 +1,5 @@ +package pr2.lambda.observer; + +public interface Beobachter { + int getValue(); +} diff --git a/solutions/src/main/java/pr2/lambda/observer/Datenhalter.java b/solutions/src/main/java/pr2/lambda/observer/Datenhalter.java new file mode 100644 index 0000000..d3e2218 --- /dev/null +++ b/solutions/src/main/java/pr2/lambda/observer/Datenhalter.java @@ -0,0 +1,24 @@ + +package pr2.lambda.observer; + +public class Datenhalter { + + private final int geheimerWert; + + public Datenhalter(int geheimerWert) { + this.geheimerWert = geheimerWert; + } + + public Beobachter getBeobachter() { + return new BeobachterImpl(); + } + + private class BeobachterImpl implements Beobachter { + + @Override + public int getValue() { + return geheimerWert; + } + + } +} diff --git a/solutions/src/main/java/pr2/lambda/observer/DatenhalterAnonym.java b/solutions/src/main/java/pr2/lambda/observer/DatenhalterAnonym.java new file mode 100644 index 0000000..fe4b99f --- /dev/null +++ b/solutions/src/main/java/pr2/lambda/observer/DatenhalterAnonym.java @@ -0,0 +1,20 @@ + +package pr2.lambda.observer; + +public class DatenhalterAnonym { + + private final int geheimerWert; + + public DatenhalterAnonym(int geheimerWert) { + this.geheimerWert = geheimerWert; + } + + public Beobachter getBeobachter() { + return new Beobachter() { + @Override + public int getValue() { + return geheimerWert; + } + }; + } +} diff --git a/solutions/src/main/java/pr2/lambda/observer/test/BeobachterTest.java b/solutions/src/main/java/pr2/lambda/observer/test/BeobachterTest.java new file mode 100644 index 0000000..c3d9e72 --- /dev/null +++ b/solutions/src/main/java/pr2/lambda/observer/test/BeobachterTest.java @@ -0,0 +1,18 @@ + +package pr2.lambda.observer.test; + +import org.junit.jupiter.api.Test; +import pr2.lambda.observer.Beobachter; +import pr2.lambda.observer.Datenhalter; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class BeobachterTest { + + @Test + void testBeobachter() { + Datenhalter dh = new Datenhalter(42); + Beobachter b = dh.getBeobachter(); + assertEquals(42, b.getValue()); + } +}