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

de.team33.patterns.arbitrary.mimas.Charger Maven / Gradle / Ivy

Go to download

Provides classes that support the generation of arbitrary values of virtually any type.

The newest version!
package de.team33.patterns.arbitrary.mimas;

import java.util.Arrays;

/**
 * A utility interface:
 * can extend producer classes with the functionality to fill classic mutable Java data objects* with (typically)
 * random values.
 * 

* In more general terms, all target instances can be filled with values via reflection if they have suitable * methods for receiving these values: so-called setters**. * Within certain limits, this can also apply, for example, to target instances according to the builder pattern. *

* The producer class that implements this interface must provide appropriate getters*** to supply the values * that can be passed to the target instance's setters. *

* Static, synthetic and native methods are generally ignored. *

* *Classic Java data objects in this context means objects that are (essentially) made up of properties * and whose property values can be determined or set using so-called getters and setters**. *

* **Setters in this context are public instance methods that take exactly one argument as a parameter * and return nothing (void) or, according to the builder pattern, the target instance itself as the result. *

* ***Getters in this context are public instance methods that take no parameters and return a result * of a specific type (not void). The {@link Object#hashCode() hashCode()} and {@link Object#toString() toString()} * methods are ignored. * * @see de.team33.patterns.arbitrary.mimas package */ public interface Charger { /** * Initializes the properties of a given {@code target} instance with values provided by this Charger instance * itself and returns the initialized target. *

* In order for a property to be initialized, the {@code target}'s class must provide a corresponding setter * that is actually accessible from this {@link Charger}. In addition, this {@link Charger}'s implementation class * must provide a parameterless method that can return an appropriate value for the property in question. *

* The default implementation provides the intended functionality. * It makes little sense to override this method or then even use this interface at all. * * @param target The target of the operation. * @param ignore The names of methods that shell be ignored. * @param The target type. * @return The target. */ default T charge(final T target, final String... ignore) { return new Charging<>(this, target, Arrays.asList(ignore)).result(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy