fix linters

This commit is contained in:
Yadunand Prem
2022-09-25 14:59:51 +08:00
parent caccc490fe
commit bd2d0766ae
13 changed files with 38 additions and 49 deletions

View File

@@ -1,15 +1,12 @@
/** /**
* The Action interface that can be called * The Action interface that can be called
* on an object of type T to act. * on an object of type T to act.
*
* Contains a single abstract method call. * Contains a single abstract method call.
*
* CS2030S Lab 4 * CS2030S Lab 4
* AY22/23 Semester 1 * AY22/23 Semester 1
*
* @author Yadunand Prem (10B) * @author Yadunand Prem (10B)
*/ */
interface Action<T> { interface Action<T> {
void call(T item); void call(T item);
} }

View File

@@ -1,12 +1,9 @@
/** /**
* The Actionable interface that can * The Actionable interface that can
* act when given an action. * act when given an action.
*
* Contains a single abstract method act. * Contains a single abstract method act.
*
* CS2030S Lab 4 * CS2030S Lab 4
* AY22/23 Semester 1 * AY22/23 Semester 1
*
* @author Yadunand Prem (10B) * @author Yadunand Prem (10B)
*/ */

View File

@@ -2,15 +2,12 @@
* The Applicable interface that can probably * The Applicable interface that can probably
* transform if given something that is * transform if given something that is
* probably an Immutator. * probably an Immutator.
*
* Contains a single abstract method apply. * Contains a single abstract method apply.
*
* CS2030S Lab 4 * CS2030S Lab 4
* AY22/23 Semester 1 * AY22/23 Semester 1
*
* @author Yadunand Prem (10B) * @author Yadunand Prem (10B)
*/ */
interface Applicable<T> { interface Applicable<T> {
<R> Applicable<R> apply(Probably<Immutator<R, T>> probablyImmutator); <R> Applicable<R> apply(Probably<Immutator<R, T>> probablyImmutator);
} }

View File

@@ -1,12 +1,9 @@
/** /**
* The Immutator interface that can transform * The Immutator interface that can transform
* to type T2, an object of type T1. * to type T2, an object of type T1.
*
* Contains a single abstract method invoke. * Contains a single abstract method invoke.
*
* CS2030S Lab 4 * CS2030S Lab 4
* AY22/23 Semester 1 * AY22/23 Semester 1
*
* @author Yadunand Prem (10B) * @author Yadunand Prem (10B)
*/ */

View File

@@ -2,12 +2,9 @@
* The Immutatorable interface that can * The Immutatorable interface that can
* transform when given something that is * transform when given something that is
* Immutator. * Immutator.
*
* Contains a single abstract method transform. * Contains a single abstract method transform.
*
* CS2030S Lab 4 * CS2030S Lab 4
* AY22/23 Semester 1 * AY22/23 Semester 1
*
* @author Yadunand Prem (10B) * @author Yadunand Prem (10B)
*/ */

View File

@@ -1,7 +1,6 @@
/** /**
* A generic Immutator that takes in an object * A generic Immutator that takes in an object
* that is T and returns an object that is probably T. * that is T and returns an object that is probably T.
*
* CS2030S Lab 4 * CS2030S Lab 4
* AY22/23 Semester 1 * AY22/23 Semester 1
* *

View File

@@ -4,7 +4,6 @@
* and return the boolean value by checking * and return the boolean value by checking
* if the given value is equal to mod when * if the given value is equal to mod when
* divided by div. * divided by div.
*
* CS2030S Lab 4 * CS2030S Lab 4
* AY22/23 Semester 1 * AY22/23 Semester 1
* *
@@ -13,16 +12,16 @@
class IsModEq implements Immutator<Boolean, Integer> { class IsModEq implements Immutator<Boolean, Integer> {
private int div; private int div;
private int check; private int check;
public IsModEq(int div, int check) { public IsModEq(int div, int check) {
this.div = div; this.div = div;
this.check = check; this.check = check;
} }
@Override @Override
public Boolean invoke(Integer val) { public Boolean invoke(Integer val) {
return val % div == check; return val % div == check;
} }
} }

View File

@@ -1,7 +1,6 @@
/** /**
* A non-generic Action to print the String * A non-generic Action to print the String
* representation of the object. * representation of the object.
*
* CS2030S Lab 4 * CS2030S Lab 4
* AY22/23 Semester 1 * AY22/23 Semester 1
* *

View File

@@ -18,7 +18,7 @@ class Probably<T> implements Actionable<T>, Immutatorable<T>, Applicable<T> {
* This is called a factory method. We can only * This is called a factory method. We can only
* create this using the two public static method. * create this using the two public static method.
* *
* @return The shared NOTHING. * @param value T
*/ */
private Probably(T value) { private Probably(T value) {
this.value = value; this.value = value;
@@ -27,6 +27,7 @@ class Probably<T> implements Actionable<T>, Immutatorable<T>, Applicable<T> {
/** /**
* It is probably nothing, no value inside. * It is probably nothing, no value inside.
* *
* @param <T> type T
* @return The shared NOTHING. * @return The shared NOTHING.
*/ */
public static <T> Probably<T> none() { public static <T> Probably<T> none() {
@@ -40,6 +41,8 @@ class Probably<T> implements Actionable<T>, Immutatorable<T>, Applicable<T> {
* Unless the value is null, then nothing is * Unless the value is null, then nothing is
* given again. * given again.
* *
* @param <T> type T
*
* @param value Probably this is the value * @param value Probably this is the value
* unless it is null then we say * unless it is null then we say
* that there is no * that there is no

View File

@@ -2,12 +2,13 @@ class Test3 {
public static void main(String[] args) { public static void main(String[] args) {
CS2030STest we = new CS2030STest(); CS2030STest we = new CS2030STest();
class Incr implements Immutator<Integer,Integer> { class Incr implements Immutator<Integer, Integer> {
public Integer invoke(Integer t1) { public Integer invoke(Integer t1) {
return t1 + 1; return t1 + 1;
} }
} }
class Length implements Immutator<Integer,String> {
class Length implements Immutator<Integer, String> {
public Integer invoke(String t1) { public Integer invoke(String t1) {
return t1.length(); return t1.length();
} }
@@ -39,4 +40,4 @@ class Test3 {
new Improbable<>().invoke(new Improbable<Integer>().invoke(1)).toString(), new Improbable<>().invoke(new Improbable<Integer>().invoke(1)).toString(),
"<<1>>"); "<<1>>");
} }
} }

View File

@@ -2,12 +2,13 @@ class Test4 {
public static void main(String[] args) { public static void main(String[] args) {
CS2030STest we = new CS2030STest(); CS2030STest we = new CS2030STest();
class Incr implements Immutator<Integer,Integer> { class Incr implements Immutator<Integer, Integer> {
public Integer invoke(Integer t1) { public Integer invoke(Integer t1) {
return t1 + 1; return t1 + 1;
} }
} }
class Length implements Immutator<Integer,String> {
class Length implements Immutator<Integer, String> {
public Integer invoke(String t1) { public Integer invoke(String t1) {
return t1.length(); return t1.length();
} }
@@ -36,4 +37,4 @@ class Test4 {
Probably.<String>just(null).transform(new Length()).transform(new Incr()).toString(), Probably.<String>just(null).transform(new Length()).transform(new Incr()).toString(),
"<>"); "<>");
} }
} }

View File

@@ -2,19 +2,20 @@ class Test5 {
public static void main(String[] args) { public static void main(String[] args) {
CS2030STest we = new CS2030STest(); CS2030STest we = new CS2030STest();
class Incr implements Immutator<Integer,Integer> { class Incr implements Immutator<Integer, Integer> {
public Integer invoke(Integer t1) { public Integer invoke(Integer t1) {
return t1 + 1; return t1 + 1;
} }
} }
class Length implements Immutator<Integer,String> {
class Length implements Immutator<Integer, String> {
public Integer invoke(String t1) { public Integer invoke(String t1) {
return t1.length(); return t1.length();
} }
} }
we.expect("Probably.just(17).check(new IsModEq(3,2)) // 17 % 3 is equal to 2", we.expect("Probably.just(17).check(new IsModEq(3,2)) // 17 % 3 is equal to 2",
Probably.just(17).check(new IsModEq(3,2)).toString(), Probably.just(17).check(new IsModEq(3, 2)).toString(),
"<17>"); "<17>");
we.expect("Probably.just(18).check(new IsModEq(3,2)) // 18 % 3 is not equal to 2", we.expect("Probably.just(18).check(new IsModEq(3,2)) // 18 % 3 is not equal to 2",
Probably.just(18).check(new IsModEq(3,2)).toString(), Probably.just(18).check(new IsModEq(3,2)).toString(),
@@ -30,4 +31,4 @@ class Test5 {
Probably.<Integer>just(null).check(new IsModEq(0,2)).toString(), Probably.<Integer>just(null).check(new IsModEq(0,2)).toString(),
"<>"); "<>");
} }
} }

View File

@@ -2,21 +2,22 @@ class Test6 {
public static void main(String[] args) { public static void main(String[] args) {
CS2030STest we = new CS2030STest(); CS2030STest we = new CS2030STest();
class Incr implements Immutator<Integer,Integer> { class Incr implements Immutator<Integer, Integer> {
public Integer invoke(Integer t1) { public Integer invoke(Integer t1) {
return t1 + 1; return t1 + 1;
} }
} }
class Length implements Immutator<Integer,String> {
class Length implements Immutator<Integer, String> {
public Integer invoke(String t1) { public Integer invoke(String t1) {
return t1.length(); return t1.length();
} }
} }
Probably<Immutator<Integer,Integer>> justIncr = Probably.just(new Incr()); Probably<Immutator<Integer, Integer>> justIncr = Probably.just(new Incr());
Probably<Immutator<Integer,String>> justLength = Probably.just(new Length()); Probably<Immutator<Integer, String>> justLength = Probably.just(new Length());
Probably<Immutator<Integer,Integer>> noIncr = Probably.none(); Probably<Immutator<Integer, Integer>> noIncr = Probably.none();
Probably<Immutator<Integer,String>> noLength = Probably.none(); Probably<Immutator<Integer, String>> noLength = Probably.none();
we.expect("Probably.just(17).<Integer>apply(justIncr)", we.expect("Probably.just(17).<Integer>apply(justIncr)",
Probably.just(17).apply(justIncr).toString(), Probably.just(17).apply(justIncr).toString(),
@@ -44,4 +45,4 @@ class Test6 {
Probably.<String>none().apply(noLength).toString(), Probably.<String>none().apply(noLength).toString(),
"<>"); "<>");
} }
} }