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

org.archifacts.integration.c4.model.Collectors Maven / Gradle / Ivy

The newest version!
package org.archifacts.integration.c4.model;

import java.util.Optional;
import java.util.stream.Collector;

public final class Collectors {
	private Collectors() {
	}

	public static  Collector> toOptionalSingleton() {
		return java.util.stream.Collectors.collectingAndThen(
				java.util.stream.Collectors.toList(),
				list -> {
					if (list.isEmpty()) {
						return Optional.empty();
					}
					if (list.size() > 1) {
						throw new IllegalStateException();
					}
					return Optional.of(list.get(0));
				});
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy