Translated Python prototype to Java