Rewrite computation of metrics in proper java