private static Pair calcBestAndWorstCase ( int pswLength , TreeMap < Integer , Integer > passwordLengths , int k ) {
  Pair pair = new Pair ( ) ;
  int tries = 0 ;
  for ( Map . Entry < Integer , Integer > entry : passwordLengths . entrySet ( ) ) {
    if ( entry . getKey ( ) < pswLength ) {
      tries += entry . getValue ( ) ;
    }
  }
  int multiplier = ( tries < k ) ? 0 : ( tries / k ) ;
  pair . bestCase = ( tries + multiplier * 5 ) + 1 ;
  tries = tries + passwordLengths . get ( pswLength ) - 1 ;
  multiplier = tries / k ;
  pair . worstCase = ( tries + multiplier * 5 ) + 1 ;
  return pair ;
}

private static Pair calcBestAndWorstCase ( int pswLength , TreeMap < Integer , Integer > passwordLengths , int k ) { Pair pair = new Pair ( ) ; int tries = 0 ; for ( Map . Entry < Integer , Integer > entry : passwordLengths . entrySet ( ) ) { if ( entry . getKey ( ) < pswLength ) { tries += entry . getValue ( ) ; } } int multiplier = ( tries < k ) ? 0 : ( tries / k ) ; pair . bestCase = ( tries + multiplier * 5 ) + 1 ; tries = tries + passwordLengths . get ( pswLength ) - 1 ; multiplier = tries / k ; pair . worstCase = ( tries + multiplier * 5 ) + 1 ; return pair ; }
(method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (enhanced_for_statement type: (generic_type (scoped_type_identifier (type_identifier) (type_identifier)) (type_arguments (type_identifier) (type_identifier))) name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (ternary_expression condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (decimal_integer_literal) alternative: (parenthesized_expression (binary_expression left: (identifier) right: (identifier)))))) (expression_statement (assignment_expression left: (field_access object: (identifier) field: (identifier)) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) (expression_statement (assignment_expression left: (field_access object: (identifier) field: (identifier)) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (decimal_integer_literal)))) (return_statement (identifier))))