Skip to content

Instantly share code, notes, and snippets.

@ganine
Created July 13, 2011 20:40
Show Gist options
  • Save ganine/1081268 to your computer and use it in GitHub Desktop.
Save ganine/1081268 to your computer and use it in GitHub Desktop.
public List<ValidacaoException> validar() throws Exception {
List<ValidacaoException> problemas = new ArrayList<ValidacaoException>();
for (Method method : this.getClass().getDeclaredMethods()) {
if (method.getName().startsWith("validar") && !method.getName().equals("validar")) {
try {
method.invoke(this);
} catch (InvocationTargetException e) {
problemas.add((ValidacaoException) e.getCause());
} catch (Exception e) {
throw e;
}
}
}
return problemas;
}
public void validarFaixaDeValores() throws ValidacaoException {
if (valorInicial != null && valorFinal != null && valorInicial.compareTo(valorFinal) > 0) throw new ValidacaoException("valor.inicial.maior.que.final");
}
public void validarPeriodo() throws ValidacaoException {
if (dataInicial != null && dataFinal != null && dataInicial.after(dataFinal)) throw new ValidacaoException("data.inicial.maior.que.final");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment