Functional Java port with Test class.