@Test public void testValidTituloEleitor() { String tituloEleitor = "270343380159"; assertTrue(service.validate(tituloEleitor)); }
@Override public boolean validate(String titulo) { if (isRepeated(titulo.substring(0, titulo.length() - 2))) { return false; } int sum = 0; int digit1; int digit2; for (int index = 0, weight = 2, digit; index <= 7; index++, weight++) { digit = Integer.parseInt(titulo.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit1 = 0; } else { digit1 = sum; } sum = 0; for (int index = 8, weight = 7, digit; index <= 10; index++, weight++) { digit = Integer.parseInt(titulo.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit2 = 0; } else { digit2 = sum; } return titulo.equals(titulo.substring(0, 10) + digit1 + digit2); }
TituloEleitorRegexValidatorService extends BasicAbstractRegexValidatorService { @Override public boolean validate(String titulo) { if (isRepeated(titulo.substring(0, titulo.length() - 2))) { return false; } int sum = 0; int digit1; int digit2; for (int index = 0, weight = 2, digit; index <= 7; index++, weight++) { digit = Integer.parseInt(titulo.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit1 = 0; } else { digit1 = sum; } sum = 0; for (int index = 8, weight = 7, digit; index <= 10; index++, weight++) { digit = Integer.parseInt(titulo.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit2 = 0; } else { digit2 = sum; } return titulo.equals(titulo.substring(0, 10) + digit1 + digit2); } }
TituloEleitorRegexValidatorService extends BasicAbstractRegexValidatorService { @Override public boolean validate(String titulo) { if (isRepeated(titulo.substring(0, titulo.length() - 2))) { return false; } int sum = 0; int digit1; int digit2; for (int index = 0, weight = 2, digit; index <= 7; index++, weight++) { digit = Integer.parseInt(titulo.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit1 = 0; } else { digit1 = sum; } sum = 0; for (int index = 8, weight = 7, digit; index <= 10; index++, weight++) { digit = Integer.parseInt(titulo.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit2 = 0; } else { digit2 = sum; } return titulo.equals(titulo.substring(0, 10) + digit1 + digit2); }  }
TituloEleitorRegexValidatorService extends BasicAbstractRegexValidatorService { @Override public boolean validate(String titulo) { if (isRepeated(titulo.substring(0, titulo.length() - 2))) { return false; } int sum = 0; int digit1; int digit2; for (int index = 0, weight = 2, digit; index <= 7; index++, weight++) { digit = Integer.parseInt(titulo.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit1 = 0; } else { digit1 = sum; } sum = 0; for (int index = 8, weight = 7, digit; index <= 10; index++, weight++) { digit = Integer.parseInt(titulo.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit2 = 0; } else { digit2 = sum; } return titulo.equals(titulo.substring(0, 10) + digit1 + digit2); }  @Override void init(File confDir); @Override boolean validate(String titulo); @Override String format(String hit); @Override List<String> getRegexNames(); }
TituloEleitorRegexValidatorService extends BasicAbstractRegexValidatorService { @Override public boolean validate(String titulo) { if (isRepeated(titulo.substring(0, titulo.length() - 2))) { return false; } int sum = 0; int digit1; int digit2; for (int index = 0, weight = 2, digit; index <= 7; index++, weight++) { digit = Integer.parseInt(titulo.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit1 = 0; } else { digit1 = sum; } sum = 0; for (int index = 8, weight = 7, digit; index <= 10; index++, weight++) { digit = Integer.parseInt(titulo.substring(index, index + 1)); sum += digit * weight; } sum = sum % 11; if (sum > 9) { digit2 = 0; } else { digit2 = sum; } return titulo.equals(titulo.substring(0, 10) + digit1 + digit2); }  @Override void init(File confDir); @Override boolean validate(String titulo); @Override String format(String hit); @Override List<String> getRegexNames();  }