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

net.jqwik.api.JavaBeanReportingFormat Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
package net.jqwik.api;

import java.util.*;
import java.util.function.*;

import org.apiguardian.api.*;

import static org.apiguardian.api.API.Status.*;

@API(status = MAINTAINED, since = "1.3.10")
public abstract class JavaBeanReportingFormat implements SampleReportingFormat {

	@API(status = INTERNAL)
	abstract public static class JavaBeanReportingFormatFacade {
		private static final JavaBeanReportingFormatFacade implementation;

		static {
			implementation = FacadeLoader.load(JavaBeanReportingFormatFacade.class);
		}

		public abstract Object reportJavaBean(
				Object bean,
				boolean reportNulls,
				Collection excludeProperties,
				Function, List> sortProperies
		);

	}

	protected abstract Collection> beanTypes();

	protected Collection excludeProperties() {
		return Collections.emptySet();
	}

	protected List sortProperties(List properties) {
		return properties;
	}

	protected boolean reportNulls() {
		return false;
	}

	@Override
	public Optional label(Object value) {
		return Optional.of(value.getClass().getSimpleName());
	}

	@Override
	public boolean appliesTo(final Object value) {
		if (value == null) {
			return false;
		}
		return beanTypes().stream().anyMatch(beanType -> beanType.isAssignableFrom(value.getClass()));
	}

	@Override
	public final Object report(Object value) {
		return JavaBeanReportingFormatFacade.implementation.reportJavaBean(
				value,
				reportNulls(),
				excludeProperties(),
				this::sortProperties
		);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy