fix linters
This commit is contained in:
parent
caccc490fe
commit
bd2d0766ae
@ -1,15 +1,12 @@
|
||||
/**
|
||||
* The Action interface that can be called
|
||||
* on an object of type T to act.
|
||||
*
|
||||
* Contains a single abstract method call.
|
||||
*
|
||||
* CS2030S Lab 4
|
||||
* AY22/23 Semester 1
|
||||
*
|
||||
* @author Yadunand Prem (10B)
|
||||
*/
|
||||
|
||||
interface Action<T> {
|
||||
void call(T item);
|
||||
void call(T item);
|
||||
}
|
||||
|
@ -1,12 +1,9 @@
|
||||
/**
|
||||
* The Actionable interface that can
|
||||
* act when given an action.
|
||||
*
|
||||
* Contains a single abstract method act.
|
||||
*
|
||||
* CS2030S Lab 4
|
||||
* AY22/23 Semester 1
|
||||
*
|
||||
* @author Yadunand Prem (10B)
|
||||
*/
|
||||
|
||||
|
@ -2,15 +2,12 @@
|
||||
* The Applicable interface that can probably
|
||||
* transform if given something that is
|
||||
* probably an Immutator.
|
||||
*
|
||||
* Contains a single abstract method apply.
|
||||
*
|
||||
* CS2030S Lab 4
|
||||
* AY22/23 Semester 1
|
||||
*
|
||||
* @author Yadunand Prem (10B)
|
||||
*/
|
||||
|
||||
interface Applicable<T> {
|
||||
<R> Applicable<R> apply(Probably<Immutator<R, T>> probablyImmutator);
|
||||
<R> Applicable<R> apply(Probably<Immutator<R, T>> probablyImmutator);
|
||||
}
|
||||
|
@ -1,12 +1,9 @@
|
||||
/**
|
||||
* The Immutator interface that can transform
|
||||
* to type T2, an object of type T1.
|
||||
*
|
||||
* Contains a single abstract method invoke.
|
||||
*
|
||||
* CS2030S Lab 4
|
||||
* AY22/23 Semester 1
|
||||
*
|
||||
* @author Yadunand Prem (10B)
|
||||
*/
|
||||
|
||||
|
@ -2,12 +2,9 @@
|
||||
* The Immutatorable interface that can
|
||||
* transform when given something that is
|
||||
* Immutator.
|
||||
*
|
||||
* Contains a single abstract method transform.
|
||||
*
|
||||
* CS2030S Lab 4
|
||||
* AY22/23 Semester 1
|
||||
*
|
||||
* @author Yadunand Prem (10B)
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
/**
|
||||
* A generic Immutator that takes in an object
|
||||
* that is T and returns an object that is probably T.
|
||||
*
|
||||
* CS2030S Lab 4
|
||||
* AY22/23 Semester 1
|
||||
*
|
||||
|
@ -4,7 +4,6 @@
|
||||
* and return the boolean value by checking
|
||||
* if the given value is equal to mod when
|
||||
* divided by div.
|
||||
*
|
||||
* CS2030S Lab 4
|
||||
* AY22/23 Semester 1
|
||||
*
|
||||
@ -13,16 +12,16 @@
|
||||
|
||||
class IsModEq implements Immutator<Boolean, Integer> {
|
||||
|
||||
private int div;
|
||||
private int check;
|
||||
private int div;
|
||||
private int check;
|
||||
|
||||
public IsModEq(int div, int check) {
|
||||
this.div = div;
|
||||
this.check = check;
|
||||
}
|
||||
public IsModEq(int div, int check) {
|
||||
this.div = div;
|
||||
this.check = check;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean invoke(Integer val) {
|
||||
return val % div == check;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Boolean invoke(Integer val) {
|
||||
return val % div == check;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
/**
|
||||
* A non-generic Action to print the String
|
||||
* representation of the object.
|
||||
*
|
||||
* CS2030S Lab 4
|
||||
* AY22/23 Semester 1
|
||||
*
|
||||
|
@ -18,7 +18,7 @@ class Probably<T> implements Actionable<T>, Immutatorable<T>, Applicable<T> {
|
||||
* This is called a factory method. We can only
|
||||
* create this using the two public static method.
|
||||
*
|
||||
* @return The shared NOTHING.
|
||||
* @param value T
|
||||
*/
|
||||
private Probably(T 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.
|
||||
*
|
||||
* @param <T> type T
|
||||
* @return The shared NOTHING.
|
||||
*/
|
||||
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
|
||||
* given again.
|
||||
*
|
||||
* @param <T> type T
|
||||
*
|
||||
* @param value Probably this is the value
|
||||
* unless it is null then we say
|
||||
* that there is no
|
||||
|
@ -2,12 +2,13 @@ class Test3 {
|
||||
public static void main(String[] args) {
|
||||
CS2030STest we = new CS2030STest();
|
||||
|
||||
class Incr implements Immutator<Integer,Integer> {
|
||||
class Incr implements Immutator<Integer, Integer> {
|
||||
public Integer invoke(Integer t1) {
|
||||
return t1 + 1;
|
||||
}
|
||||
}
|
||||
class Length implements Immutator<Integer,String> {
|
||||
|
||||
class Length implements Immutator<Integer, String> {
|
||||
public Integer invoke(String t1) {
|
||||
return t1.length();
|
||||
}
|
||||
@ -39,4 +40,4 @@ class Test3 {
|
||||
new Improbable<>().invoke(new Improbable<Integer>().invoke(1)).toString(),
|
||||
"<<1>>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,13 @@ class Test4 {
|
||||
public static void main(String[] args) {
|
||||
CS2030STest we = new CS2030STest();
|
||||
|
||||
class Incr implements Immutator<Integer,Integer> {
|
||||
class Incr implements Immutator<Integer, Integer> {
|
||||
public Integer invoke(Integer t1) {
|
||||
return t1 + 1;
|
||||
}
|
||||
}
|
||||
class Length implements Immutator<Integer,String> {
|
||||
|
||||
class Length implements Immutator<Integer, String> {
|
||||
public Integer invoke(String t1) {
|
||||
return t1.length();
|
||||
}
|
||||
@ -36,4 +37,4 @@ class Test4 {
|
||||
Probably.<String>just(null).transform(new Length()).transform(new Incr()).toString(),
|
||||
"<>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,20 @@ class Test5 {
|
||||
public static void main(String[] args) {
|
||||
CS2030STest we = new CS2030STest();
|
||||
|
||||
class Incr implements Immutator<Integer,Integer> {
|
||||
class Incr implements Immutator<Integer, Integer> {
|
||||
public Integer invoke(Integer t1) {
|
||||
return t1 + 1;
|
||||
}
|
||||
}
|
||||
class Length implements Immutator<Integer,String> {
|
||||
|
||||
class Length implements Immutator<Integer, String> {
|
||||
public Integer invoke(String t1) {
|
||||
return t1.length();
|
||||
}
|
||||
}
|
||||
|
||||
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>");
|
||||
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(),
|
||||
@ -30,4 +31,4 @@ class Test5 {
|
||||
Probably.<Integer>just(null).check(new IsModEq(0,2)).toString(),
|
||||
"<>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,21 +2,22 @@ class Test6 {
|
||||
public static void main(String[] args) {
|
||||
CS2030STest we = new CS2030STest();
|
||||
|
||||
class Incr implements Immutator<Integer,Integer> {
|
||||
class Incr implements Immutator<Integer, Integer> {
|
||||
public Integer invoke(Integer t1) {
|
||||
return t1 + 1;
|
||||
}
|
||||
}
|
||||
class Length implements Immutator<Integer,String> {
|
||||
|
||||
class Length implements Immutator<Integer, String> {
|
||||
public Integer invoke(String t1) {
|
||||
return t1.length();
|
||||
}
|
||||
}
|
||||
|
||||
Probably<Immutator<Integer,Integer>> justIncr = Probably.just(new Incr());
|
||||
Probably<Immutator<Integer,String>> justLength = Probably.just(new Length());
|
||||
Probably<Immutator<Integer,Integer>> noIncr = Probably.none();
|
||||
Probably<Immutator<Integer,String>> noLength = Probably.none();
|
||||
Probably<Immutator<Integer, Integer>> justIncr = Probably.just(new Incr());
|
||||
Probably<Immutator<Integer, String>> justLength = Probably.just(new Length());
|
||||
Probably<Immutator<Integer, Integer>> noIncr = Probably.none();
|
||||
Probably<Immutator<Integer, String>> noLength = Probably.none();
|
||||
|
||||
we.expect("Probably.just(17).<Integer>apply(justIncr)",
|
||||
Probably.just(17).apply(justIncr).toString(),
|
||||
@ -44,4 +45,4 @@ class Test6 {
|
||||
Probably.<String>none().apply(noLength).toString(),
|
||||
"<>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user