@Test public void shouldGeneratedLuhnNumberForOneDigitNumber() { LuhnCheckDigitFunction luhnCheckDigitFunction = new LuhnCheckDigitFunction(); assertThat(luhnCheckDigitFunction.apply(5L), is(59L)); }
@Override @Nullable public Long apply(@Nonnull Long partialAccountNumber) { checkNotNull(partialAccountNumber, "partialAccountNumber can't be null"); boolean isEven = true; int total = 0; Long temp = partialAccountNumber; while (temp > 0) { long digit = temp % 10; if (isEven) { long multipliedDigit = digit * 2; total += isTwoDigit(multipliedDigit) ? sumUpDigits(multipliedDigit) : multipliedDigit; } else { total += digit; } temp /= 10; isEven = !isEven; } int check = total * 9 % 10; return partialAccountNumber * 10 + check; }
LuhnCheckDigitFunction implements Function<Long, Long> { @Override @Nullable public Long apply(@Nonnull Long partialAccountNumber) { checkNotNull(partialAccountNumber, "partialAccountNumber can't be null"); boolean isEven = true; int total = 0; Long temp = partialAccountNumber; while (temp > 0) { long digit = temp % 10; if (isEven) { long multipliedDigit = digit * 2; total += isTwoDigit(multipliedDigit) ? sumUpDigits(multipliedDigit) : multipliedDigit; } else { total += digit; } temp /= 10; isEven = !isEven; } int check = total * 9 % 10; return partialAccountNumber * 10 + check; } }
LuhnCheckDigitFunction implements Function<Long, Long> { @Override @Nullable public Long apply(@Nonnull Long partialAccountNumber) { checkNotNull(partialAccountNumber, "partialAccountNumber can't be null"); boolean isEven = true; int total = 0; Long temp = partialAccountNumber; while (temp > 0) { long digit = temp % 10; if (isEven) { long multipliedDigit = digit * 2; total += isTwoDigit(multipliedDigit) ? sumUpDigits(multipliedDigit) : multipliedDigit; } else { total += digit; } temp /= 10; isEven = !isEven; } int check = total * 9 % 10; return partialAccountNumber * 10 + check; }  }
LuhnCheckDigitFunction implements Function<Long, Long> { @Override @Nullable public Long apply(@Nonnull Long partialAccountNumber) { checkNotNull(partialAccountNumber, "partialAccountNumber can't be null"); boolean isEven = true; int total = 0; Long temp = partialAccountNumber; while (temp > 0) { long digit = temp % 10; if (isEven) { long multipliedDigit = digit * 2; total += isTwoDigit(multipliedDigit) ? sumUpDigits(multipliedDigit) : multipliedDigit; } else { total += digit; } temp /= 10; isEven = !isEven; } int check = total * 9 % 10; return partialAccountNumber * 10 + check; }  @Override @Nullable Long apply(@Nonnull Long partialAccountNumber); }
LuhnCheckDigitFunction implements Function<Long, Long> { @Override @Nullable public Long apply(@Nonnull Long partialAccountNumber) { checkNotNull(partialAccountNumber, "partialAccountNumber can't be null"); boolean isEven = true; int total = 0; Long temp = partialAccountNumber; while (temp > 0) { long digit = temp % 10; if (isEven) { long multipliedDigit = digit * 2; total += isTwoDigit(multipliedDigit) ? sumUpDigits(multipliedDigit) : multipliedDigit; } else { total += digit; } temp /= 10; isEven = !isEven; } int check = total * 9 % 10; return partialAccountNumber * 10 + check; }  @Override @Nullable Long apply(@Nonnull Long partialAccountNumber);  }