hi guys,
i just got job interview. now the employer wanted me to write a
java even listener. I admit my java skill is very weak. but i do want see how event and listener work. can someone help? thank you so much.
here is what they ask me to do:
· Create a new class ObservableList that extends java.util.ArrayList
· ObservableList must allow any class that implements a new interface (that you define) called ListListener to "register" and "unregister" with it.
· All ListListeners that are registered with an ObservableList must be "notified" every time one or more items are added or removed from that list, no matter what method was called to modify the list. Be sure to check the API docs for ArrayList to make sure you cover all of the various add and remove methods.
· The notification must allow the listeners to access the items that were added/removed and the List they belong to.
· It is up to you to decide how to best implement the notification mechanism, however for this exercise notifications only need to be sent to objects that live in the same JVM process. In other words, don't use JMS or anything distributed.
· There are no specific requirements on how this class should deal with multiple concurrent threads. Implement the best, most reasonable multi-threading features you can think of given the scope of this exercise. At a minimum, please document in your code comments all of the important multi-threaded issues you can think of.
· Create a class TestListListener that implements ListListener and prints every notification it receives from ObservableList. It should print at least what kind of change occurred and the item(s) that were added/removed.
· Include at least one
unit test that uses ObservableList with TestListListener and demonstrates its features. (You're more than welcome to include more.) It should use at least two instances of ObservableList and at least three instances of TestListListener (you can use more). Use whatever combinations of lists and listeners and method calls you think best demonstrates the most functionality.