finished lab5
This commit is contained in:
@@ -25,14 +25,12 @@ class Lab5 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Immutator<Actually<Map<String, Map<String, String>>>, Map<String, Map<String, Map<String, String>>>> getModule = new Immutator<>() {
|
Immutator<Actually<Map<String, Map<String, String>>>, Map<String, Map<String, Map<String, String>>>> getModule = new Immutator<>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Actually<Map<String, Map<String, String>>> invoke(Map<String, Map<String, Map<String, String>>> param) {
|
public Actually<Map<String, Map<String, String>>> invoke(Map<String, Map<String, Map<String, String>>> param) {
|
||||||
return Actually.ok(param.get(module));
|
return Actually.ok(param.get(module));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Immutator<Actually<Map<String, String>>, Map<String, Map<String, String>>> getStudent = new Immutator<>() {
|
Immutator<Actually<Map<String, String>>, Map<String, Map<String, String>>> getStudent = new Immutator<>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Actually<Map<String, String>> invoke(Map<String, Map<String, String>> param) {
|
public Actually<Map<String, String>> invoke(Map<String, Map<String, String>> param) {
|
||||||
return Actually.ok(param.get(student));
|
return Actually.ok(param.get(student));
|
||||||
@@ -40,46 +38,48 @@ class Lab5 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Immutator<Actually<String>, Map<String, String>> getAssessment = new Immutator<>() {
|
Immutator<Actually<String>, Map<String, String>> getAssessment = new Immutator<>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Actually<String> invoke(Map<String, String> param) {
|
public Actually<String> invoke(Map<String, String> param) {
|
||||||
return Actually.ok(param.get(assessment));
|
return Actually.ok(param.get(assessment).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return cDb.init().next(getModule).next(getStudent).next(getAssessment).except(cNoEntry);
|
return cDb
|
||||||
|
.init()
|
||||||
|
.next(getModule)
|
||||||
|
.next(getStudent)
|
||||||
|
.next(getAssessment)
|
||||||
|
.except(cNoEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// Create a scanner to read from standard input.
|
// Create a scanner to read from standard input.
|
||||||
test6();
|
Scanner sc = new Scanner(System.in);
|
||||||
/*
|
|
||||||
* Scanner sc = new Scanner(System.in);
|
// Read a single integer from the test file
|
||||||
*
|
// and then run the appropriate test case
|
||||||
* // Read a single integer from the test file
|
switch (sc.nextInt()) {
|
||||||
* // and then run the appropriate test case
|
case 1:
|
||||||
* switch (sc.nextInt()) {
|
test1();
|
||||||
* case 1:
|
break;
|
||||||
* test1();
|
case 2:
|
||||||
* break;
|
test2();
|
||||||
* case 2:
|
break;
|
||||||
* test2();
|
case 3:
|
||||||
* break;
|
test3();
|
||||||
* case 3:
|
break;
|
||||||
* test3();
|
case 4:
|
||||||
* break;
|
test4();
|
||||||
* case 4:
|
break;
|
||||||
* test4();
|
case 5:
|
||||||
* break;
|
test5();
|
||||||
* case 5:
|
break;
|
||||||
* test5();
|
case 6:
|
||||||
* break;
|
test6();
|
||||||
* case 6:
|
break;
|
||||||
* test6();
|
}
|
||||||
* break;
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void test1() {
|
public static void test1() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package cs2030s.fp;
|
package cs2030s.fp;
|
||||||
|
|
||||||
public abstract class Actually<T> implements Immutatorable<T> {
|
public abstract class Actually<T> implements Immutatorable<T>, Actionable<T> {
|
||||||
public abstract T unwrap() throws Exception;
|
public abstract T unwrap() throws Exception;
|
||||||
|
|
||||||
public abstract T except(Constant<? extends T> c);
|
public abstract T except(Constant<? extends T> c);
|
||||||
@@ -9,7 +9,7 @@ public abstract class Actually<T> implements Immutatorable<T> {
|
|||||||
|
|
||||||
public abstract T unless(T other);
|
public abstract T unless(T other);
|
||||||
|
|
||||||
public abstract <R> Actually<R> next(Immutator<Actually<R>, T> immutator);
|
public abstract <R> Actually<R> next(Immutator<Actually<R>, ? super T> immutator);
|
||||||
|
|
||||||
public static <T> Actually<T> ok(T value) {
|
public static <T> Actually<T> ok(T value) {
|
||||||
return new Success<T>(value);
|
return new Success<T>(value);
|
||||||
@@ -48,7 +48,7 @@ public abstract class Actually<T> implements Immutatorable<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R> Actually<R> next(Immutator<Actually<R>, T> immutator) {
|
public <R> Actually<R> next(Immutator<Actually<R>, ? super T> immutator) {
|
||||||
try {
|
try {
|
||||||
return immutator.invoke(this.value);
|
return immutator.invoke(this.value);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -65,6 +65,11 @@ public abstract class Actually<T> implements Immutatorable<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void act(Action<? super T> action) {
|
||||||
|
action.call(this.value);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "<" + value + ">";
|
return "<" + value + ">";
|
||||||
@@ -112,7 +117,7 @@ public abstract class Actually<T> implements Immutatorable<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void finish(Action action) {
|
public void finish(Action<? super Object> action) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,11 +127,17 @@ public abstract class Actually<T> implements Immutatorable<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R> Actually<R> next(Immutator<Actually<R>, Object> immutator) {
|
public <R> Actually<R> next(Immutator<Actually<R>, ? super Object> immutator) {
|
||||||
return Actually.err(this.e);
|
return Actually.err(this.e);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void act(Action<? super Object> action) {
|
||||||
|
// Do nothing
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[" + e.getClass().getName() + "] " + e.getMessage();
|
return "[" + e.getClass().getName() + "] " + e.getMessage();
|
||||||
|
|||||||
Reference in New Issue
Block a user