finished lab5
This commit is contained in:
parent
a99c9cefd2
commit
530ef6b71a
@ -25,14 +25,12 @@ class Lab5 {
|
||||
};
|
||||
|
||||
Immutator<Actually<Map<String, Map<String, String>>>, Map<String, Map<String, Map<String, String>>>> getModule = new Immutator<>() {
|
||||
|
||||
@Override
|
||||
public Actually<Map<String, Map<String, String>>> invoke(Map<String, Map<String, Map<String, String>>> param) {
|
||||
return Actually.ok(param.get(module));
|
||||
}
|
||||
};
|
||||
Immutator<Actually<Map<String, String>>, Map<String, Map<String, String>>> getStudent = new Immutator<>() {
|
||||
|
||||
@Override
|
||||
public Actually<Map<String, String>> invoke(Map<String, Map<String, String>> param) {
|
||||
return Actually.ok(param.get(student));
|
||||
@ -40,46 +38,48 @@ class Lab5 {
|
||||
};
|
||||
|
||||
Immutator<Actually<String>, Map<String, String>> getAssessment = new Immutator<>() {
|
||||
|
||||
@Override
|
||||
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) {
|
||||
// Create a scanner to read from standard input.
|
||||
test6();
|
||||
/*
|
||||
* Scanner sc = new Scanner(System.in);
|
||||
*
|
||||
* // Read a single integer from the test file
|
||||
* // and then run the appropriate test case
|
||||
* switch (sc.nextInt()) {
|
||||
* case 1:
|
||||
* test1();
|
||||
* break;
|
||||
* case 2:
|
||||
* test2();
|
||||
* break;
|
||||
* case 3:
|
||||
* test3();
|
||||
* break;
|
||||
* case 4:
|
||||
* test4();
|
||||
* break;
|
||||
* case 5:
|
||||
* test5();
|
||||
* break;
|
||||
* case 6:
|
||||
* test6();
|
||||
* break;
|
||||
* }
|
||||
*/
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
// Read a single integer from the test file
|
||||
// and then run the appropriate test case
|
||||
switch (sc.nextInt()) {
|
||||
case 1:
|
||||
test1();
|
||||
break;
|
||||
case 2:
|
||||
test2();
|
||||
break;
|
||||
case 3:
|
||||
test3();
|
||||
break;
|
||||
case 4:
|
||||
test4();
|
||||
break;
|
||||
case 5:
|
||||
test5();
|
||||
break;
|
||||
case 6:
|
||||
test6();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void test1() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
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 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 <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) {
|
||||
return new Success<T>(value);
|
||||
@ -48,7 +48,7 @@ public abstract class Actually<T> implements Immutatorable<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> Actually<R> next(Immutator<Actually<R>, T> immutator) {
|
||||
public <R> Actually<R> next(Immutator<Actually<R>, ? super T> immutator) {
|
||||
try {
|
||||
return immutator.invoke(this.value);
|
||||
} 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
|
||||
public String toString() {
|
||||
return "<" + value + ">";
|
||||
@ -112,7 +117,7 @@ public abstract class Actually<T> implements Immutatorable<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish(Action action) {
|
||||
public void finish(Action<? super Object> action) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -122,11 +127,17 @@ public abstract class Actually<T> implements Immutatorable<T> {
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(Action<? super Object> action) {
|
||||
// Do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + e.getClass().getName() + "] " + e.getMessage();
|
||||
|
Loading…
Reference in New Issue
Block a user