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

com.github.TKnudsen.ComplexDataObject.model.tools.Functions Maven / Gradle / Ivy

Go to download

A library that models real-world objects in Java, referred to as ComplexDataObjects. Other features: IO and preprocessing of ComplexDataObjects.

The newest version!
package com.github.TKnudsen.ComplexDataObject.model.tools;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

public class Functions {

	/**
	 * useful if computation is expensive and values remain constant. Do not use
	 * this if function values may change over time.
	 * 
	 * @param 
	 * @param 
	 * @param f
	 * @return
	 */
	public static  Function bufferedFunction(Function f) {
		Map buffer = new HashMap<>();

		return new Function() {

			@Override
			public R apply(T t) {
				if (buffer.containsKey(t))
					return buffer.get(t);

				buffer.put(t, f.apply(t));
				return buffer.get(t);
			}

		};
	}

	private Functions() {

	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy