change from Java code to Scala