package com.ctrip.ops.sysdev.filters;

import com.ctrip.ops.sysdev.baseplugin.BaseFilter;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.Map;

@SuppressWarnings("ALL")
public class Filters extends BaseFilter {
    private static final Logger logger = Logger.getLogger(Filters.class.getName());

    public Filters(Map config) {
        super(config);
    }

    protected BaseFilter[] filterProcessors;

    protected void prepare() {
        ArrayList<Map> filters = (ArrayList<Map>) config.get("filters");

        this.filterProcessors = Utils.createFilterProcessors(filters);
    }

    @Override
    protected Map filter(Map event) {
        if (this.filterProcessors != null) {
            for (BaseFilter bf : filterProcessors) {
                if (event == null) {
                    break;
                }
                event = bf.process(event);
            }
        }
        return event;
    }
}

@@ -144,16 +144,39 @@
 ayList;%0A
+import java.util.List;%0A
 import j
@@ -635,330 +635,1534 @@
     
-%7D%0A%0A    @Override%0A    protected Map filter(Map event) %7B%0A        if (this.filterProcessors != null) %7B%0A            for (BaseFilter bf : filterProcessors) %7B%0A                if (event == null) %7B%0A                    break;%0A                %7D%0A                event = bf.process(event);%0A            %7D%0A        %7D%0A        return event
+    for (BaseFilter filterProcessor : filterProcessors) %7B%0A            if (filterProcessor.processExtraEventsFunc == true) %7B%0A                this.processExtraEventsFunc = true;%0A            %7D%0A        %7D%0A    %7D%0A%0A    @Override%0A    protected Map filter(Map event) %7B%0A        if (this.processExtraEventsFunc == true) %7B%0A            //will prcess the event in filterExtraEvents%0A            return event;%0A        %7D%0A        if (this.filterProcessors != null) %7B%0A            for (BaseFilter bf : filterProcessors) %7B%0A                if (event == null) %7B%0A                    break;%0A                %7D%0A                event = bf.process(event);%0A            %7D%0A        %7D%0A        return event;%0A    %7D%0A%0A    @Override%0A    protected List%3CMap%3CString, Object%3E%3E filterExtraEvents(Map event) %7B%0A        ArrayList%3CMap%3CString, Object%3E%3E events = new ArrayList%3CMap%3CString, Object%3E%3E();%0A        events.add(event);%0A        for (BaseFilter bf : filterProcessors) %7B%0A            if (events == null) %7B%0A                break;%0A            %7D%0A            for (int i = 0; i %3C events.size(); i++) %7B%0A                events.set(i, bf.process(events.get(i)));%0A            %7D%0A            if (bf.processExtraEventsFunc == true) %7B%0A                int originEventSize = events.size();%0A                for (int i = 0; i %3C originEventSize; i++) %7B%0A                    List rst = bf.processExtraEvents(events.get(i));%0A                    if (rst != null) %7B%0A                        events.addAll(rst);%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return events
 ;%0A  

fix extraevents