You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue relates to #35 (actually this should be a subtask of the previous).
Streams 2 is "stringly typed" this is not how we should teach students to code.
The easiest and cleanest way to solve all questions si to define the following method:
privatefinalstaticPredicate<Student> pred(finalMap<String, Predicate<?>> conditions) {
return (s) -> {
for (Map.Entry<String, Predicate<?>> e : conditions.entrySet()) {
switch (e.getKey()) {
case"firstName":
if (!((Predicate<String>) e.getValue()).test(s.getFirstName()))
returnfalse;
elsebreak;
case"lastName":
if (!((Predicate<String>) e.getValue()).test(s.getLastName()))
returnfalse;
elsebreak;
case"section":
if (!((Predicate<Integer>) e.getValue()).test(s.getSection()))
returnfalse;
elsebreak;
case"courses_results":
if (!((Predicate<Map<String, Double>>) e.getValue()).test(s.getCourses_results()))
returnfalse;
elsebreak;
default:
thrownewRuntimeException("Unexpected key");
}
}
returntrue;
};
}
One should rely on the type system to help student get a grasp on what should be done. Also, it would be great if we could show students how to combine predicates (and, or, not, ...)
The text was updated successfully, but these errors were encountered:
This issue relates to #35 (actually this should be a subtask of the previous).
Streams 2 is "stringly typed" this is not how we should teach students to code.
The easiest and cleanest way to solve all questions si to define the following method:
One should rely on the type system to help student get a grasp on what should be done. Also, it would be great if we could show students how to combine predicates (and, or, not, ...)
The text was updated successfully, but these errors were encountered: