feat: add some javadoc
This commit is contained in:
parent
6a4ef4ea70
commit
4ee04937da
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,3 +5,5 @@ Lab1.pdf
|
|||||||
checkstyle.jar
|
checkstyle.jar
|
||||||
cs2030_checks.xml
|
cs2030_checks.xml
|
||||||
*.swp
|
*.swp
|
||||||
|
|
||||||
|
Lab6/docs
|
@ -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 {
|
class And implements Cond {
|
||||||
private Cond lVal;
|
private Cond lVal;
|
||||||
private Cond rVal;
|
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) {
|
public And(Cond lVal, Cond rVal) {
|
||||||
this.lVal = lVal;
|
this.lVal = lVal;
|
||||||
this.rVal = rVal;
|
this.rVal = rVal;
|
||||||
|
@ -1,4 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* Represents a conditional type.
|
||||||
|
* CS2030S Lab 5
|
||||||
|
* AY20/21 Semester 2
|
||||||
|
*
|
||||||
|
*/
|
||||||
interface Cond {
|
interface Cond {
|
||||||
|
/**
|
||||||
|
* Evaluates the given conditional.
|
||||||
|
*
|
||||||
|
* @return the boolean result of the evaluation
|
||||||
|
*/
|
||||||
boolean eval();
|
boolean eval();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* negates the value of the conditional, without evaluating it.
|
||||||
|
*
|
||||||
|
* @return a new conditional, with the negated value
|
||||||
|
*/
|
||||||
Cond neg();
|
Cond neg();
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* Represents the Not type, a conditional which inverts the given input.
|
||||||
|
*/
|
||||||
class Not implements Cond {
|
class Not implements Cond {
|
||||||
private Cond val;
|
private Cond val;
|
||||||
|
|
||||||
public Not(Cond val) {
|
public Not(Cond val) {
|
||||||
this.val = val;
|
this.val = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean eval() {
|
public boolean eval() {
|
||||||
return !this.val.eval();
|
return !this.val.eval();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "!(" + this.val + ")";
|
return "!(" + this.val + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Cond neg() {
|
public Cond neg() {
|
||||||
return this.val;
|
return this.val;
|
||||||
|
11
Lab6/Or.java
11
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 {
|
class Or implements Cond {
|
||||||
private Cond lVal;
|
private Cond lVal;
|
||||||
private Cond rVal;
|
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) {
|
public Or(Cond lVal, Cond rVal) {
|
||||||
this.lVal = lVal;
|
this.lVal = lVal;
|
||||||
this.rVal = rVal;
|
this.rVal = rVal;
|
||||||
|
@ -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 <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 static class Success<T> extends Actually<T> {
|
||||||
private final T value;
|
private final T value;
|
||||||
@ -134,7 +135,8 @@ public abstract class Actually<T> implements Immutatorable<T>, Actionable<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return Actually.err(this.e);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package cs2030s.fp;
|
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
|
* CS2030S Lab 5
|
||||||
* AY22/23 Semester 1
|
* AY22/23 Semester 1
|
||||||
*
|
*
|
||||||
@ -11,7 +12,8 @@ public interface Immutatorable<T> {
|
|||||||
/**
|
/**
|
||||||
* The method to produce another container with immutated element.
|
* 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.
|
* @return A new container containing the immutated element.
|
||||||
*/
|
*/
|
||||||
<R> Immutatorable<R> transform(Immutator<? extends R, ? super T> f);
|
<R> Immutatorable<R> transform(Immutator<? extends R, ? super T> f);
|
||||||
|
@ -21,15 +21,11 @@ public class Lazy<T> implements Immutatorable<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R> Lazy<R> transform(Immutator<? extends R, ? super T> f) {
|
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) {
|
public <R> Lazy<R> next(Immutator<? extends Lazy<? extends R>, ? super T> f) {
|
||||||
|
return Lazy.<R>from(() -> f.invoke(this.get()).get());
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Lazy<R> result = (Lazy<R>) Lazy.from(() -> f.invoke(this.init.init()));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,9 @@ public class Memo<T> extends Lazy<T> {
|
|||||||
return result;
|
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()));
|
return Memo.<R>from(() -> combiner.combine(this.get(), other.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user