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

com.g2forge.alexandria.java.function.cache.CachingSupplier Maven / Gradle / Ivy

There is a newer version: 0.0.18
Show newest version
package com.g2forge.alexandria.java.function.cache;

import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class CachingSupplier implements Supplier {
	protected final Supplier supplier;

	protected final Function function;

	protected I input;

	protected O output;

	@Override
	public O get() {
		final I input = supplier.get();
		if (!Objects.equals(input, this.input)) {
			output = function.apply(input);
			this.input = input;
		}
		return output;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy