Converted more code from Scala to Java.