(C) 2011 — Software Languages Team, University of Koblenz-Landau
Navigation
Check-in deadline
June 24, 2011 (End Of Day, Koblenz timezone)
Variation 1
Title
Scrap your boilerplate for the depth feature
Instructions
The starting point for this assignment is 101implementation:javaSyb. The goal is to implement 101feature:Depth. The implementation should be robust in a way that it determines the nesting depth of Department objects without though making any assumptions other than that there are objects of type Department. Hence, the implementation should leverage a generic traversal akin to the implementation of 101feature:Total.
Here is a sketch of the preferred implementation; complete it:
package org.softlang.features;
import org.softlang.company.*;
import javaf.prelude.*;
import static javaf.syb.Query.*;
public class Depth {
public static int depth(Company c) {
return traverse().apply(c);
}
public static Function<Object,Integer> traverse() {
return new Function<Object,Integer>() {
public Integer apply(Object x) {
final int result =
... // traverse ALL immediate sub-objects recursively
...; // and combine intermediate results with max operator.
return orDefault(
..., // return result+1 if x is a department
... // return result as is if x is not a department
).apply(x);
}
};
}
public static BinaryOperator<Integer> max = ... // functor to compute the max of two integers
}
Please note: while Total used the convenient traversal scheme everything, the problem at hand requires a custom scheme traverse.
Variation 2
Scrap your boilerplate for a variation on the cut feature
Instructions
The starting point for this assignment is 101implementation:javaSyb. The goal is to implement a variation on 101feature:Cut such that manager salaries are cut only. To this end, the implementation should maintain the parent object at any level of traversal so that a manager can be distinguished from a regular employee by the type of its parent object: Department (whereas the parent object of a regular object is a collection).
Here is a sketch of the preferred implementation; complete it:
package org.softlang.features;
import org.softlang.company.*;
import javaf.prelude.*;
import static javaf.syb.Transformation.*;
public class CutManagers {
public static void cutManagers(Company c) {
traverse(null).apply(c);
}
public static Action<Object> traverse(final Object parent) {
return new Action<Object>() {
public void apply(Object o) {
...; // update salary if this a manager
...; // traverse ALL immediate sub-objects recursively
}
};
}
public static Action<Employee> updateSalary(final Object parent) {
return new Action<Employee>() {
public void apply(Employee x) {
...; // cut salary in half if this is a manager
}
};
}
}
Please note: while Cut used the convenient traversal scheme everywhere, the problem at hand requires a custom scheme traverse.