Housni-Trehel Algorithm - Java implementation