replaced Scala code by pure Java