mardi 8 septembre 2020

Java8 splitting long interface method into separate methods

I have the below default method in an interface and it seems to be pretty complex because of the many if-else conditions.

       default void validate() {
         Application application = application().get();
            if (StringUtils.isEmpty(application.name()) || application.data() == null) {
               throw new IllegalArgumentException());
            } else {
               for (Form form : application.data().forms) {
                   if (StringUtils.isEmpty(form.getId())) {
                        throw new IllegalArgumentException();
                   }
                     for (Question question : form.getQuestions()) {
                         if (StringUtils.isEmpty(question.getQuestion())
                            || StringUtils.isEmpty(question.getValue())) {
                               throw new IllegalArgumentException();
                         }
                      }
                }
            }
        }

I want to split this into different methods to reduce the complexity. However since the project is configured to use Java8, private methods cannot be used in the interface. How else can I break this down and reduce the complexity? Any advice would be much appreciated.

Aucun commentaire:

Enregistrer un commentaire