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

com.softicar.platform.common.core.interfaces.Consumers Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.core.interfaces;

import java.util.Arrays;
import java.util.Collection;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * Utility methods for the {@link Consumer} interface.
 *
 * @author Oliver Richers
 */
public class Consumers {

	private static final Consumer NO_OPERATION = x -> {
		// nothing to do by design
	};

	@SuppressWarnings("unchecked")
	public static  Consumer noOperation() {

		return (Consumer) NO_OPERATION;
	}

	public static  boolean isNoOperation(Consumer consumer) {

		return consumer == NO_OPERATION;
	}

	@SafeVarargs
	public static  Consumer concat(Consumer...consumers) {

		return concat(Arrays.asList(consumers));
	}

	public static  Consumer concat(Collection> consumers) {

		return (T object) -> consumers.forEach(consumer -> consumer.accept(object));
	}

	public static  Function toFunction(Consumer consumer, R result) {

		return value -> {
			consumer.accept(value);
			return result;
		};
	}
}