com.anaptecs.jeaf.junit.openapi.base.PersonBase Maven / Gradle / Ivy
The newest version!
/*
* anaptecs GmbH, Ricarda-Huch-Str. 71, 72760 Reutlingen, Germany
*
* Copyright 2004 - 2021. All rights reserved.
*/
package com.anaptecs.jeaf.junit.openapi.base;
import java.util.List;
import javax.validation.ConstraintViolationException;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import com.anaptecs.annotations.MyNotNullProperty;
import com.anaptecs.jeaf.tools.api.validation.ValidationTools;
import com.anaptecs.jeaf.xfun.api.common.ObjectIdentity;
@Valid
public abstract class PersonBase extends Partner {
/**
* Default serial version uid.
*/
private static final long serialVersionUID = 1L;
/**
*
* Alternate Name: Vorname
*/
@NotNull
private String surname;
@NotNull
private String firstName;
/**
* Default constructor is only intended to be used for deserialization by tools like Jackson for JSON. For "normal"
* object creation builder should be used instead.
*/
protected PersonBase( ) {
}
/**
* Initialize object using the passed builder.
*
* @param pBuilder Builder that should be used to initialize this object. The parameter must not be null.
*/
protected PersonBase( BuilderBase pBuilder ) {
// Call constructor of super class.
super(pBuilder);
// Read attribute values from builder.
surname = pBuilder.surname;
firstName = pBuilder.firstName;
}
/**
* Class implements builder to create a new instance of class Person. As the class has read only attributes or
* associations instances can not be created directly. Instead this builder class has to be used.
*/
public static abstract class BuilderBase extends Partner.Builder {
/**
*
* Alternate Name: Vorname
*/
private String surname;
private String firstName;
/**
* Use {@link Person.builder()} instead of protected constructor to create new builder.
*/
protected BuilderBase( ) {
super();
}
/**
* Use {@link Person.builder(Person)} instead of protected constructor to create new builder.
*/
protected BuilderBase( PersonBase pObject ) {
super(pObject);
if (pObject != null) {
// Read attribute values from passed object.
this.setSurname(pObject.surname);
this.setFirstName(pObject.firstName);
}
}
/**
* Method sets the identifier for the object created using the builder. The reference may be null since an id is not
* mandatory.
*/
@Override
public BuilderBase setID( ObjectIdentity> pObjectID ) {
super.setID(pObjectID);
return this;
}
/**
* Method sets association {@link #postalAddresses}.
*
* @param pPostalAddresses Collection to which {@link #postalAddresses} should be set.
* @return {@link BuilderBase} Instance of this builder to support chaining setters. Method never returns null.
*/
@Override
public BuilderBase setPostalAddresses( List pPostalAddresses ) {
// Call super class implementation.
super.setPostalAddresses(pPostalAddresses);
return this;
}
/**
* Method adds the passed objects to association {@link #postalAddresses}.
*
* @param pPostalAddresses Array of objects that should be added to {@link #postalAddresses}. The parameter may be
* null.
* @return {@link BuilderBase} Instance of this builder to support chaining. Method never returns null.
*/
public BuilderBase addToPostalAddresses( PostalAddress... pPostalAddresses ) {
// Call super class implementation.
super.addToPostalAddresses(pPostalAddresses);
return this;
}
/**
* Method sets attribute {@link #surname}.
*
* @param pSurname Value to which {@link #surname} should be set.
* @return {@link BuilderBase} Instance of this builder to support chaining setters. Method never returns null.
*/
public BuilderBase setSurname( @MyNotNullProperty String pSurname ) {
// Assign value to attribute
surname = pSurname;
return this;
}
/**
* Method sets attribute {@link #firstName}.
*
* @param pFirstName Value to which {@link #firstName} should be set.
* @return {@link BuilderBase} Instance of this builder to support chaining setters. Method never returns null.
*/
public BuilderBase setFirstName( @MyNotNullProperty String pFirstName ) {
// Assign value to attribute
firstName = pFirstName;
return this;
}
/**
* Method creates a new instance of class Person. The object will be initialized with the values of the builder.
*
* @return Person Created object. The method never returns null.
*/
public Person build( ) {
return new Person(this);
}
/**
* Method creates a new validated instance of class Person. The object will be initialized with the values of the
* builder and validated afterwards.
*
* @return Person Created and validated object. The method never returns null.
* @throws ConstraintViolationException in case that one or more validations for the created object failed.
*/
public Person buildValidated( ) throws ConstraintViolationException {
Person lPOJO = this.build();
ValidationTools.getValidationTools().enforceObjectValidation(lPOJO);
return lPOJO;
}
}
/**
* Method returns attribute {@link #surname}.
*
* @return {@link String} Value to which {@link #surname} is set.
*/
@MyNotNullProperty
public String getSurname( ) {
return surname;
}
/**
* Method sets attribute {@link #surname}.
*
* @param pSurname Value to which {@link #surname} should be set.
*/
public void setSurname( @MyNotNullProperty String pSurname ) {
// Assign value to attribute
surname = pSurname;
}
/**
* Method returns attribute {@link #firstName}.
*
* @return {@link String} Value to which {@link #firstName} is set.
*/
@MyNotNullProperty
public String getFirstName( ) {
return firstName;
}
/**
* Method sets attribute {@link #firstName}.
*
* @param pFirstName Value to which {@link #firstName} should be set.
*/
public void setFirstName( @MyNotNullProperty String pFirstName ) {
// Assign value to attribute
firstName = pFirstName;
}
/**
* Convenience method to create new instance of class Person.
*
*
* @param pSurname Value to which {@link #surname} should be set.
*
* @param pFirstName Value to which {@link #firstName} should be set.
*
* @return {@link com.anaptecs.jeaf.junit.openapi.base.Person}
*/
public static Person of( String pSurname, String pFirstName ) {
Person.Builder lBuilder = Person.builder();
lBuilder.setSurname(pSurname);
lBuilder.setFirstName(pFirstName);
return lBuilder.build();
}
/**
* @return {@link String}
*/
@MyNotNullProperty
public abstract String getDisplayName( );
/**
* Method returns a StringBuilder that can be used to create a String representation of this object. The returned
* StringBuilder also takes care about attributes of super classes.
*
* @return {@link StringBuilder} StringBuilder representing this object. The method never returns null.
*/
@Override
public StringBuilder toStringBuilder( String pIndent ) {
StringBuilder lBuilder = super.toStringBuilder(pIndent);
lBuilder.append(pIndent);
lBuilder.append("surname: ");
lBuilder.append(surname);
lBuilder.append(System.lineSeparator());
lBuilder.append(pIndent);
lBuilder.append("firstName: ");
lBuilder.append(firstName);
lBuilder.append(System.lineSeparator());
return lBuilder;
}
/**
* Method creates a new String with the values of all attributes of this class. All references to other objects will
* be ignored.
*
* @return {@link String} String representation of this object. The method never returns null.
*/
@Override
public String toString( ) {
return this.toStringBuilder("").toString();
}
/**
* Method creates a new builder and initializes it with the data of this object.
*
* @return {@link Builder} New builder that can be used to create new Person objects. The method never returns null.
*/
public Person.Builder toBuilder( ) {
return new Person.Builder((Person) this);
}
}