CheckDigitWeightedMod11Verifier implements CheckDigitVerifier { public boolean isValid(String id) { int totalWeight = 0; int wIndex = 0; byte[] digits = id.getBytes(); for (int i = 0; i < digits.length; i++) { byte digit = digits[i]; if (!Character.isDigit(digit)) { return false; } digit -= 48; int weightToUse = i == digits.length - 1 ? 1 : weights[wIndex]; totalWeight += digit * weightToUse; if (++wIndex >= weights.length) wIndex = 0; } return totalWeight % 11 == 0; } private  CheckDigitWeightedMod11Verifier(int[] weights); static CheckDigitVerifier from(int[] weights); boolean isValid(String id);  }
@Test public void testIsValid() { int[] weights = {7, 6, 5, 4, 3, 2}; CheckDigitVerifier verifier = CheckDigitVerifiers.getVerifier(WeightedMod11, weights); Assert.assertTrue(verifier.isValid("0365327")); Assert.assertFalse(verifier.isValid("0365328")); }