org.springframework.data.mapping

## Class PreferredConstructor<T,P extends PersistentProperty<P>>

- java.lang.Object
- - org.springframework.data.mapping.PreferredConstructor<T,P>

    public class PreferredConstructor<T,P extends PersistentProperty<P>>
    extends Object

Value object to encapsulate the constructor to be used when mapping persistent data to objects.

Author:
  Oliver Gierke, Jon Brisbin, Thomas Darimont, Christoph Strobl, Mark Paluch, Myeonghyeon Lee

### Nested Class Summary

Nested Classes
`static class` `PreferredConstructor.Parameter<T,P extends PersistentProperty<P>>` Value object to represent constructor parameters.

### Constructor Summary

Constructors
Constructor and Description
`PreferredConstructor(Constructor<T> constructor, PreferredConstructor.Parameter<Object,P>... parameters)` Creates a new `PreferredConstructor` from the given `Constructor` and `PreferredConstructor.Parameter`s.

### Method Summary

All Methods Instance Methods Concrete Methods
`Constructor<T>` `getConstructor()` Returns the underlying `Constructor`.
`List<PreferredConstructor.Parameter<Object,P>>` `getParameters()` Returns the `PreferredConstructor.Parameter`s of the constructor.
`boolean` `hasParameters()` Returns whether the constructor has `PreferredConstructor.Parameter`s.
`boolean` `isConstructorParameter(PersistentProperty<?> property)` Returns whether the given `PersistentProperty` is referenced in a constructor argument of the `PersistentEntity` backing this `PreferredConstructor`.
`boolean` `isEnclosingClassParameter(PreferredConstructor.Parameter<?,P> parameter)` Returns whether the given `PreferredConstructor.Parameter` is one referring to an enclosing class.
`boolean` `isExplicitlyAnnotated()` Returns whether the constructor was explicitly selected (by `PersistenceConstructor`).
`boolean` `isNoArgConstructor()` Returns whether the constructor does not have any arguments.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### PreferredConstructor

    @SafeVarargs
    public PreferredConstructor(Constructor<T> constructor,
                                             PreferredConstructor.Parameter<Object,P>... parameters)

Creates a new `PreferredConstructor` from the given `Constructor` and `PreferredConstructor.Parameter`s.

Parameters:
  `constructor` - must not be null.
  `parameters` - must not be null.

### Method Detail

#### getConstructor

    public Constructor<T> getConstructor()

Returns the underlying `Constructor`.

Returns:

#### getParameters

    public List<PreferredConstructor.Parameter<Object,P>> getParameters()

Returns the `PreferredConstructor.Parameter`s of the constructor.

Returns:

#### hasParameters

    public boolean hasParameters()

Returns whether the constructor has `PreferredConstructor.Parameter`s.

Returns:
See Also:
  `isNoArgConstructor()`

#### isNoArgConstructor

    public boolean isNoArgConstructor()

Returns whether the constructor does not have any arguments.

Returns:
See Also:
  `hasParameters()`

#### isExplicitlyAnnotated

    public boolean isExplicitlyAnnotated()

Returns whether the constructor was explicitly selected (by `PersistenceConstructor`).

Returns:

#### isConstructorParameter

    public boolean isConstructorParameter(PersistentProperty<?> property)

Returns whether the given `PersistentProperty` is referenced in a constructor argument of the `PersistentEntity` backing this `PreferredConstructor`.

Parameters:
  `property` - must not be null.
Returns:
  true if the `PersistentProperty` is used in the constructor.

#### isEnclosingClassParameter

    public boolean isEnclosingClassParameter(PreferredConstructor.Parameter<?,P> parameter)

Returns whether the given `PreferredConstructor.Parameter` is one referring to an enclosing class. That is in case the class this `PreferredConstructor` belongs to is a member class actually. If that's the case the compiler creates a first constructor argument of the enclosing class type.

Parameters:
  `parameter` - must not be null.
Returns:
  true if the `PersistentProperty` maps to the enclosing class.