diff --git a/Lab4/Applicable.java b/Lab4/Applicable.java index c764ebb..31b8efb 100644 --- a/Lab4/Applicable.java +++ b/Lab4/Applicable.java @@ -5,9 +5,10 @@ * Contains a single abstract method apply. * CS2030S Lab 4 * AY22/23 Semester 1 + * * @author Yadunand Prem (10B) */ interface Applicable { - Applicable apply(Probably> probablyImmutator); + Applicable apply(Probably> probablyImmutator); } diff --git a/Lab4/Immutatorable.java b/Lab4/Immutatorable.java index b9d277c..396890d 100644 --- a/Lab4/Immutatorable.java +++ b/Lab4/Immutatorable.java @@ -9,5 +9,5 @@ */ interface Immutatorable { - public Immutatorable transform(Immutator immutator); + public Immutatorable transform(Immutator immutator); } diff --git a/Lab4/Probably.java b/Lab4/Probably.java index 628c9d4..0d402eb 100644 --- a/Lab4/Probably.java +++ b/Lab4/Probably.java @@ -41,7 +41,7 @@ class Probably implements Actionable, Immutatorable, Applicable { * Unless the value is null, then nothing is * given again. * - * @param type T + * @param type T * * @param value Probably this is the value * unless it is null then we say @@ -105,21 +105,18 @@ class Probably implements Actionable, Immutatorable, Applicable { action.call(this.value); } - public Probably check(IsModEq eq) { + public Probably check(Immutator eq) { if (this.value == null) { return none(); } - if (this.value instanceof Integer) { - Integer val = (Integer) this.value; - if (eq.invoke(val)) { - return this; - } + if (eq.invoke(this.value)) { + return this; } return none(); } @Override - public Probably transform(Immutator immutator) { + public Probably transform(Immutator immutator) { if (this.value == null) { return none(); } @@ -127,9 +124,9 @@ class Probably implements Actionable, Immutatorable, Applicable { } @Override - public Probably apply(Probably> probablyImmutator) { - if (this.value != null && probablyImmutator.value != null) { - return just(probablyImmutator.value.invoke(this.value)); + public Probably apply(Probably> probablyImmutator) { + if (probablyImmutator.value != null) { + return this.transform(probablyImmutator.value); } return none(); }