From 4ee04937dac4aff95c70e03d74da8b63e439256c Mon Sep 17 00:00:00 2001 From: Yadunand Prem Date: Sun, 16 Oct 2022 03:46:01 +0800 Subject: [PATCH] feat: add some javadoc --- .gitignore | 2 ++ Lab6/And.java | 11 +++++++++++ Lab6/Cond.java | 19 ++++++++++++++++++- Lab6/Not.java | 10 +++++++--- Lab6/Or.java | 11 +++++++++++ Lab6/cs2030s/fp/Actually.java | 6 ++++-- Lab6/cs2030s/fp/Immutatorable.java | 6 ++++-- Lab6/cs2030s/fp/Lazy.java | 8 ++------ Lab6/cs2030s/fp/Memo.java | 4 +++- 9 files changed, 62 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 9b824ce..8415580 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ Lab1.pdf checkstyle.jar cs2030_checks.xml *.swp + +Lab6/docs \ No newline at end of file diff --git a/Lab6/And.java b/Lab6/And.java index 9be08eb..a909db0 100644 --- a/Lab6/And.java +++ b/Lab6/And.java @@ -1,7 +1,18 @@ +/** + * Represents the And type, a conditional which returns true if both left and + * right values are true. This operator short circuits, which means if the first + * value is false, the right value is not evaluated + */ class And implements Cond { private Cond lVal; private Cond rVal; + /** + * Constructor for the And conditional. + * + * @param lVal the left value in the And Operation. + * @param rVal This is only evaluated if lVal is true + */ public And(Cond lVal, Cond rVal) { this.lVal = lVal; this.rVal = rVal; diff --git a/Lab6/Cond.java b/Lab6/Cond.java index 0077e38..f29fd4e 100644 --- a/Lab6/Cond.java +++ b/Lab6/Cond.java @@ -1,4 +1,21 @@ +/** + * Represents a conditional type. + * CS2030S Lab 5 + * AY20/21 Semester 2 + * + */ interface Cond { + /** + * Evaluates the given conditional. + * + * @return the boolean result of the evaluation + */ boolean eval(); + + /** + * negates the value of the conditional, without evaluating it. + * + * @return a new conditional, with the negated value + */ Cond neg(); -} \ No newline at end of file +} diff --git a/Lab6/Not.java b/Lab6/Not.java index 49cc83a..e685f01 100644 --- a/Lab6/Not.java +++ b/Lab6/Not.java @@ -1,19 +1,23 @@ +/** + * Represents the Not type, a conditional which inverts the given input. + */ class Not implements Cond { private Cond val; - + public Not(Cond val) { this.val = val; } - + @Override public boolean eval() { return !this.val.eval(); } + @Override public String toString() { return "!(" + this.val + ")"; } - + @Override public Cond neg() { return this.val; diff --git a/Lab6/Or.java b/Lab6/Or.java index 45648fe..8e2fc13 100644 --- a/Lab6/Or.java +++ b/Lab6/Or.java @@ -1,7 +1,18 @@ +/** + * Represents the Or type, a conditional which returns true if either value is + * true. This operator short circuits, which means that if the left value is + * true, the right value is not evaluated + */ class Or implements Cond { private Cond lVal; private Cond rVal; + /** + * Constructor for the Or conditional. + * + * @param lVal the left value in the Or Operation. + * @param rVal This is only evaluated if lVal is false + */ public Or(Cond lVal, Cond rVal) { this.lVal = lVal; this.rVal = rVal; diff --git a/Lab6/cs2030s/fp/Actually.java b/Lab6/cs2030s/fp/Actually.java index 3dcce65..da8513b 100644 --- a/Lab6/cs2030s/fp/Actually.java +++ b/Lab6/cs2030s/fp/Actually.java @@ -22,7 +22,8 @@ public abstract class Actually implements Immutatorable, Actionable { public abstract T unless(U other); - public abstract Actually next(Immutator, ? super T> immutator); + public abstract Actually next( + Immutator, ? super T> immutator); private static class Success extends Actually { private final T value; @@ -134,7 +135,8 @@ public abstract class Actually implements Immutatorable, Actionable { } @Override - public Actually next(Immutator, ? super Object> immutator) { + public Actually next( + Immutator, ? super Object> immutator) { return Actually.err(this.e); } diff --git a/Lab6/cs2030s/fp/Immutatorable.java b/Lab6/cs2030s/fp/Immutatorable.java index 1ce2b3b..e522703 100644 --- a/Lab6/cs2030s/fp/Immutatorable.java +++ b/Lab6/cs2030s/fp/Immutatorable.java @@ -1,7 +1,8 @@ package cs2030s.fp; /** - * Represent a container that can transforms its content to produce another container containing the immutated element, possible of different types. + * Represent a container that can transforms its content to produce another + * container containing the immutated element, possible of different types. * CS2030S Lab 5 * AY22/23 Semester 1 * @@ -11,7 +12,8 @@ public interface Immutatorable { /** * The method to produce another container with immutated element. * - * @param f The immutator. + * @param the return type + * @param f The immutator. * @return A new container containing the immutated element. */ Immutatorable transform(Immutator f); diff --git a/Lab6/cs2030s/fp/Lazy.java b/Lab6/cs2030s/fp/Lazy.java index 13743ab..86838da 100644 --- a/Lab6/cs2030s/fp/Lazy.java +++ b/Lab6/cs2030s/fp/Lazy.java @@ -21,15 +21,11 @@ public class Lazy implements Immutatorable { @Override public Lazy transform(Immutator f) { - return Lazy.from(() -> f.invoke(this.init.init())); + return Lazy.from(() -> f.invoke(this.get())); } public Lazy next(Immutator, ? super T> f) { - - @SuppressWarnings("unchecked") - Lazy result = (Lazy) Lazy.from(() -> f.invoke(this.init.init())); - - return result; + return Lazy.from(() -> f.invoke(this.get()).get()); } diff --git a/Lab6/cs2030s/fp/Memo.java b/Lab6/cs2030s/fp/Memo.java index 69036a6..941bad5 100644 --- a/Lab6/cs2030s/fp/Memo.java +++ b/Lab6/cs2030s/fp/Memo.java @@ -28,7 +28,9 @@ public class Memo extends Lazy { return result; } - public Memo combine(Memo other, Combiner combiner) { + public Memo combine( + Memo other, + Combiner combiner) { return Memo.from(() -> combiner.combine(this.get(), other.get())); }