feat: add some javadoc

This commit is contained in:
Yadunand Prem 2022-10-16 03:46:01 +08:00
parent 6a4ef4ea70
commit 4ee04937da
9 changed files with 62 additions and 15 deletions

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ Lab1.pdf
checkstyle.jar
cs2030_checks.xml
*.swp
Lab6/docs

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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;

View File

@ -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;

View File

@ -22,7 +22,8 @@ public abstract class Actually<T> implements Immutatorable<T>, Actionable<T> {
public abstract <U extends T> T unless(U other);
public abstract <R> Actually<R> next(Immutator<? extends Actually<? extends R>, ? super T> immutator);
public abstract <R> Actually<R> next(
Immutator<? extends Actually<? extends R>, ? super T> immutator);
private static class Success<T> extends Actually<T> {
private final T value;
@ -134,7 +135,8 @@ public abstract class Actually<T> implements Immutatorable<T>, Actionable<T> {
}
@Override
public <R> Actually<R> next(Immutator<? extends Actually<? extends R>, ? super Object> immutator) {
public <R> Actually<R> next(
Immutator<? extends Actually<? extends R>, ? super Object> immutator) {
return Actually.err(this.e);
}

View File

@ -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<T> {
/**
* The method to produce another container with immutated element.
*
* @param f The immutator.
* @param <R> the return type
* @param f The immutator.
* @return A new container containing the immutated element.
*/
<R> Immutatorable<R> transform(Immutator<? extends R, ? super T> f);

View File

@ -21,15 +21,11 @@ public class Lazy<T> implements Immutatorable<T> {
@Override
public <R> Lazy<R> transform(Immutator<? extends R, ? super T> f) {
return Lazy.from(() -> f.invoke(this.init.init()));
return Lazy.from(() -> f.invoke(this.get()));
}
public <R> Lazy<R> next(Immutator<? extends Lazy<? extends R>, ? super T> f) {
@SuppressWarnings("unchecked")
Lazy<R> result = (Lazy<R>) Lazy.from(() -> f.invoke(this.init.init()));
return result;
return Lazy.<R>from(() -> f.invoke(this.get()).get());
}

View File

@ -28,7 +28,9 @@ public class Memo<T> extends Lazy<T> {
return result;
}
public <R, S> Memo<R> combine(Memo<? extends S> other, Combiner<? extends R, ? super T, ? super S> combiner) {
public <R, S> Memo<R> combine(
Memo<? extends S> other,
Combiner<? extends R, ? super T, ? super S> combiner) {
return Memo.<R>from(() -> combiner.combine(this.get(), other.get()));
}