port of https://github.com/kennytm/pndopt to java