An example of a functor implementation in java