n-gram predictor in Java