@Test public void isValidLuhnNumber_whenValidMasterCard_returnsTrue() { assertTrue(CardUtils.isValidLuhnNumber("5555555555554444")); }
static boolean isValidLuhnNumber(@Nullable String cardNumber) { if (cardNumber == null) { return false; } boolean isOdd = true; int sum = 0; for (int index = cardNumber.length() - 1; index >= 0; index--) { char c = cardNumber.charAt(index); if (!Character.isDigit(c)) { return false; } int digitInteger = Character.getNumericValue(c); isOdd = !isOdd; if (isOdd) { digitInteger *= 2; } if (digitInteger > 9) { digitInteger -= 9; } sum += digitInteger; } return sum % 10 == 0; }
CardUtils { static boolean isValidLuhnNumber(@Nullable String cardNumber) { if (cardNumber == null) { return false; } boolean isOdd = true; int sum = 0; for (int index = cardNumber.length() - 1; index >= 0; index--) { char c = cardNumber.charAt(index); if (!Character.isDigit(c)) { return false; } int digitInteger = Character.getNumericValue(c); isOdd = !isOdd; if (isOdd) { digitInteger *= 2; } if (digitInteger > 9) { digitInteger -= 9; } sum += digitInteger; } return sum % 10 == 0; } }
CardUtils { static boolean isValidLuhnNumber(@Nullable String cardNumber) { if (cardNumber == null) { return false; } boolean isOdd = true; int sum = 0; for (int index = cardNumber.length() - 1; index >= 0; index--) { char c = cardNumber.charAt(index); if (!Character.isDigit(c)) { return false; } int digitInteger = Character.getNumericValue(c); isOdd = !isOdd; if (isOdd) { digitInteger *= 2; } if (digitInteger > 9) { digitInteger -= 9; } sum += digitInteger; } return sum % 10 == 0; }  }
CardUtils { static boolean isValidLuhnNumber(@Nullable String cardNumber) { if (cardNumber == null) { return false; } boolean isOdd = true; int sum = 0; for (int index = cardNumber.length() - 1; index >= 0; index--) { char c = cardNumber.charAt(index); if (!Character.isDigit(c)) { return false; } int digitInteger = Character.getNumericValue(c); isOdd = !isOdd; if (isOdd) { digitInteger *= 2; } if (digitInteger > 9) { digitInteger -= 9; } sum += digitInteger; } return sum % 10 == 0; }  @NonNull @Card.CardBrand static String getPossibleCardType(@Nullable String cardNumber); static boolean isValidCardNumber(@Nullable String cardNumber); }
CardUtils { static boolean isValidLuhnNumber(@Nullable String cardNumber) { if (cardNumber == null) { return false; } boolean isOdd = true; int sum = 0; for (int index = cardNumber.length() - 1; index >= 0; index--) { char c = cardNumber.charAt(index); if (!Character.isDigit(c)) { return false; } int digitInteger = Character.getNumericValue(c); isOdd = !isOdd; if (isOdd) { digitInteger *= 2; } if (digitInteger > 9) { digitInteger -= 9; } sum += digitInteger; } return sum % 10 == 0; }  @NonNull @Card.CardBrand static String getPossibleCardType(@Nullable String cardNumber); static boolean isValidCardNumber(@Nullable String cardNumber);  }