@Test void testSpecifyTheMinimumLevel() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("HeaderLength").addProperty("min_level", "2")).build(); HeaderLengthValidator validator = (HeaderLengthValidator) ValidatorFactory.getInstance(config.getValidatorConfigs().get(0), config); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(new Section(5, "This is a long long long long" + " long long long long long long long long header")); assertEquals(0, errors.size()); }
@Override public void validate(Section section) { if (section.getLevel() >= getInt("min_level")) { return; } List<Sentence> headerContents = section.getHeaderContents(); int headerLength = headerContents.stream().map(s -> s.getContent().length()).reduce(0, (s, r) -> s + r); if (headerLength > getInt("max_len")) { addLocalizedError(section.getJoinedHeaderContents(), getInt("max_len")); } }
HeaderLengthValidator extends Validator { @Override public void validate(Section section) { if (section.getLevel() >= getInt("min_level")) { return; } List<Sentence> headerContents = section.getHeaderContents(); int headerLength = headerContents.stream().map(s -> s.getContent().length()).reduce(0, (s, r) -> s + r); if (headerLength > getInt("max_len")) { addLocalizedError(section.getJoinedHeaderContents(), getInt("max_len")); } } }
HeaderLengthValidator extends Validator { @Override public void validate(Section section) { if (section.getLevel() >= getInt("min_level")) { return; } List<Sentence> headerContents = section.getHeaderContents(); int headerLength = headerContents.stream().map(s -> s.getContent().length()).reduce(0, (s, r) -> s + r); if (headerLength > getInt("max_len")) { addLocalizedError(section.getJoinedHeaderContents(), getInt("max_len")); } } HeaderLengthValidator(); }
HeaderLengthValidator extends Validator { @Override public void validate(Section section) { if (section.getLevel() >= getInt("min_level")) { return; } List<Sentence> headerContents = section.getHeaderContents(); int headerLength = headerContents.stream().map(s -> s.getContent().length()).reduce(0, (s, r) -> s + r); if (headerLength > getInt("max_len")) { addLocalizedError(section.getJoinedHeaderContents(), getInt("max_len")); } } HeaderLengthValidator(); @Override void validate(Section section); }
HeaderLengthValidator extends Validator { @Override public void validate(Section section) { if (section.getLevel() >= getInt("min_level")) { return; } List<Sentence> headerContents = section.getHeaderContents(); int headerLength = headerContents.stream().map(s -> s.getContent().length()).reduce(0, (s, r) -> s + r); if (headerLength > getInt("max_len")) { addLocalizedError(section.getJoinedHeaderContents(), getInt("max_len")); } } HeaderLengthValidator(); @Override void validate(Section section);  }