This is a short but tricky assignment that illustrates the basics of how interfaces are used in Java to implement generic algorithms (i.e. C++ templates) and function objects. It's a little hard to describe without giving away the solution, so I apologize if this requires several readings to make sense.
The C++ STL has a pair of functions called find and find_if. find searches a container for an item; find_if searches a container for an item that matches a particular predicate. You'll be writing something similar as three separate static methods.
Write a class that contains three static methods, as follows.
boolean equals( Object lhs, Object rhs );which returns true if lhs and rhs are to be considered equal. Test the predicate by using the array of Employees from the previous function. To be able to call the three-parameter find you will need to create a function object that will return true if two Employees are equal (the implementation will be based on the compareTo function). Note that Employee no longer needs to implement the Comparable interface, but there is no harm in doing so.
public static Object find( Object [] a, Object x ) { // Call the three-parameter find return find( a, x, new StandardEquals( ) ); }where StandardEquals is defined along the lines of
class StandardEquals ... { public boolean equals ... }The easiest implementation of StandardEquals is to call the equals method for the two objects. Make sure you do not generate a NullPointerException!
You should submit your revised Date and Employee classes and the three static methods that you rewrote at the end (i.e. in the "finally paragraph"), and a test program with output that proves your program works and handles degenerate cases.