// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public static TriggerResult trig(boolean doConsumer, long nextPeriod) {
//     return new TriggerResult(doConsumer, nextPeriod);
// }
// 
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public static class TriggerResult {
// 
//     private static final TriggerResult EMPTY = new TriggerResult(false, DAYS.toMillis(1));
//     private final boolean doConsumer;
//     private final long nextPeriod;
// 
//     private TriggerResult(boolean doConsumer, long nextPeriod) {
//         this.doConsumer = doConsumer;
//         this.nextPeriod = nextPeriod;
//     }
// 
//     public static TriggerResult trig(boolean doConsumer, long nextPeriod) {
//         return new TriggerResult(doConsumer, nextPeriod);
//     }
// 
//     public static TriggerResult empty() {
//         return EMPTY;
//     }
// }
// 
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public interface TriggerStrategy {
// 
//     /**
//      * 获取触发器执行结果，用于判断是否可执行消费回调
//      */
//     TriggerResult canTrigger(long lastConsumeTimestamp, long changedCount);
// }


import static com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerResult.trig;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.Math.abs;
import static java.lang.Math.min;
import static java.lang.System.currentTimeMillis;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerResult;
import com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerStrategy;
            if (maxTrigChangeCount == null) {
                maxTrigChangeCount = trigChangedCount;
            } else {
                if (maxTrigChangeCount <= trigChangedCount) {
                    throw new IllegalArgumentException(
                            "found invalid trigger setting:" + triggerMap);
                }
            }
            lastPeriod = period;
        }
        return minPeriod;
    }

    @Override
    public TriggerResult canTrigger(long lastConsumeTimestamp, long changedCount) {
        checkArgument(!triggerMap.isEmpty());

        boolean doConsumer = false;

        long now = currentTimeMillis();

        for (Entry<Long, Long> entry : triggerMap.entrySet()) {
            if (now - lastConsumeTimestamp < entry.getKey()) {
                continue;
            }
            if (changedCount >= entry.getValue()) {
                doConsumer = true;
                break;
            }
        }
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public static TriggerResult trig(boolean doConsumer, long nextPeriod) {
//     return new TriggerResult(doConsumer, nextPeriod);
// }
// 
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public static class TriggerResult {
// 
//     private static final TriggerResult EMPTY = new TriggerResult(false, DAYS.toMillis(1));
//     private final boolean doConsumer;
//     private final long nextPeriod;
// 
//     private TriggerResult(boolean doConsumer, long nextPeriod) {
//         this.doConsumer = doConsumer;
//         this.nextPeriod = nextPeriod;
//     }
// 
//     public static TriggerResult trig(boolean doConsumer, long nextPeriod) {
//         return new TriggerResult(doConsumer, nextPeriod);
//     }
// 
//     public static TriggerResult empty() {
//         return EMPTY;
//     }
// }
// 
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public interface TriggerStrategy {
// 
//     /**
//      * 获取触发器执行结果，用于判断是否可执行消费回调
//      */
//     TriggerResult canTrigger(long lastConsumeTimestamp, long changedCount);
// }


// Path: src/main/java/com/github/phantomthief/collection/impl/MultiIntervalTriggerStrategy.java
import static com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerResult.trig;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.Math.abs;
import static java.lang.Math.min;
import static java.lang.System.currentTimeMillis;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerResult;
import com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerStrategy;

            if (maxTrigChangeCount == null) {
                maxTrigChangeCount = trigChangedCount;
            } else {
                if (maxTrigChangeCount <= trigChangedCount) {
                    throw new IllegalArgumentException(
                            "found invalid trigger setting:" + triggerMap);
                }
            }
            lastPeriod = period;
        }
        return minPeriod;
    }

    @Override
    public TriggerResult canTrigger(long lastConsumeTimestamp, long changedCount) {
        checkArgument(!triggerMap.isEmpty());

        boolean doConsumer = false;

        long now = currentTimeMillis();

        for (Entry<Long, Long> entry : triggerMap.entrySet()) {
            if (now - lastConsumeTimestamp < entry.getKey()) {
                continue;
            }
            if (changedCount >= entry.getValue()) {
                doConsumer = true;
                break;
            }
        }
        return trig(doConsumer, minTriggerPeriod);