All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.yudichev.jiotty.common.lang.DeduplicatingBiConsumer Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package net.yudichev.jiotty.common.lang;

import javax.annotation.Nullable;
import java.util.function.BiConsumer;

import static com.google.common.base.Preconditions.checkNotNull;

public final class DeduplicatingBiConsumer implements BiConsumer {
    private final BiConsumer delegate;
    @Nullable
    private T lastValue1;
    @Nullable
    private U lastValue2;

    public DeduplicatingBiConsumer(BiConsumer delegate) {
        this.delegate = checkNotNull(delegate);
    }

    @Override
    public void accept(T t, U u) {
        if (!t.equals(lastValue1) || !u.equals(lastValue2)) {
            delegate.accept(t, u);
            lastValue1 = t;
            lastValue2 = u;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy