package com.atlassian.bitbucket.mesh.util;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

public class CachingSatiableConsumer<T> implements SatiableConsumer<T> {

    private final SatiableConsumer<T> delegate;

    private volatile boolean satiated;

    public CachingSatiableConsumer(@Nonnull SatiableConsumer<T> delegate) {
        this.delegate = requireNonNull(delegate, "delegate");
    }

    @Override
    public boolean accept(T value) {
        return satiated = delegate.accept(value);
    }

    public boolean isSatiated() {
        return satiated;
    }
}
