package org.apache.logging.log4j.core.appender.rolling.action;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class CompositeAction extends AbstractAction {
   private final Action[] actions;
   private final boolean stopOnError;

   public CompositeAction(List<Action> actions, boolean stopOnError) {
      this.actions = new Action[actions.size()];
      actions.toArray(this.actions);
      this.stopOnError = stopOnError;
   }

   public void run() {
      try {
         this.execute();
      } catch (IOException var2) {
         LOGGER.warn((String)"Exception during file rollover.", (Throwable)var2);
      }

   }

   public boolean execute() throws IOException {
      if (this.stopOnError) {
         Action[] arr$ = this.actions;
         int len$ = arr$.length;

         for(int i$ = 0; i$ < len$; ++i$) {
            Action action = arr$[i$];
            if (!action.execute()) {
               return false;
            }
         }

         return true;
      } else {
         boolean status = true;
         IOException exception = null;
         Action[] arr$ = this.actions;
         int len$ = arr$.length;

         for(int i$ = 0; i$ < len$; ++i$) {
            Action action = arr$[i$];

            try {
               status &= action.execute();
            } catch (IOException var8) {
               status = false;
               if (exception == null) {
                  exception = var8;
               }
            }
         }

         if (exception != null) {
            throw exception;
         } else {
            return status;
         }
      }
   }

   public String toString() {
      return CompositeAction.class.getSimpleName() + Arrays.toString(this.actions);
   }
}
