Interface Charger


public interface Charger
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 hashCode() and toString() methods are ignored.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default <T> T
    charge(T target, String... ignore)
    Initializes the properties of a given target instance with values provided by this Charger instance itself and returns the initialized target.
  • Method Details

    • charge

      default <T> T charge(T target, String... ignore)
      Initializes the properties of a given target instance with values provided by this Charger instance itself and returns the initialized target.

      In order for a property to be initialized, the target's class must provide a corresponding setter that is actually accessible from this. In addition, this 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.

      Type Parameters:
      T - The target type.
      Parameters:
      target - The target of the operation.
      ignore - The names of methods that shell be ignored.
      Returns:
      The target.