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

import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;

@Plugin(
   name = "Policies",
   category = "Core",
   printObject = true
)
public final class CompositeTriggeringPolicy implements TriggeringPolicy {
   private final TriggeringPolicy[] policies;

   private CompositeTriggeringPolicy(TriggeringPolicy... policies) {
      this.policies = policies;
   }

   public void initialize(RollingFileManager manager) {
      TriggeringPolicy[] arr$ = this.policies;
      int len$ = arr$.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         TriggeringPolicy policy = arr$[i$];
         policy.initialize(manager);
      }

   }

   public boolean isTriggeringEvent(LogEvent event) {
      TriggeringPolicy[] arr$ = this.policies;
      int len$ = arr$.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         TriggeringPolicy policy = arr$[i$];
         if (policy.isTriggeringEvent(event)) {
            return true;
         }
      }

      return false;
   }

   public String toString() {
      StringBuilder sb = new StringBuilder("CompositeTriggeringPolicy{");
      boolean first = true;
      TriggeringPolicy[] arr$ = this.policies;
      int len$ = arr$.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         TriggeringPolicy policy = arr$[i$];
         if (!first) {
            sb.append(", ");
         }

         sb.append(policy.toString());
         first = false;
      }

      sb.append('}');
      return sb.toString();
   }

   @PluginFactory
   public static CompositeTriggeringPolicy createPolicy(@PluginElement("Policies") TriggeringPolicy... policies) {
      return new CompositeTriggeringPolicy(policies);
   }
}
