com.anaptecs.jeaf.junit.openapi.base.ResellerBase 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.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import javax.validation.ConstraintViolationException;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import com.anaptecs.annotations.MyNotEmptyProperty;
import com.anaptecs.annotations.MyNotNullProperty;
import com.anaptecs.jeaf.core.api.ServiceObject;
import com.anaptecs.jeaf.core.api.ServiceObjectID;
import com.anaptecs.jeaf.tools.api.validation.ValidationTools;
import com.anaptecs.jeaf.xfun.api.checks.Check;
import com.anaptecs.jeaf.xfun.api.common.Identifiable;
import com.anaptecs.jeaf.xfun.api.common.ObjectIdentity;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
@Valid
public abstract class ResellerBase implements ServiceObject, Identifiable {
/**
* Default serial version uid.
*/
private static final long serialVersionUID = 1L;
/**
* Reference to the identifier of this object. The reference may be null since an id is not mandatory.
*/
private final ServiceObjectID objectID;
@JsonSetter(nulls = Nulls.SKIP)
@Size(min = 1)
@NotNull
private List channels;
/**
* Attribute is required for correct handling of bidirectional associations in case of deserialization.
*/
private transient boolean channelsBackReferenceInitialized;
private transient Set products;
/**
*
* Breaking Change with 1.1: Maximum size will be increased.
*/
@NotBlank
@Size(min = 0, max = 32)
private String name;
@NotNull
private Locale language;
/**
* 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 ResellerBase( ) {
objectID = null;
channels = new ArrayList();
// Bidirectional back reference is not yet set up correctly
channelsBackReferenceInitialized = false;
products = new HashSet();
}
/**
* Initialize object using the passed builder.
*
* @param pBuilder Builder that should be used to initialize this object. The parameter must not be null.
*/
protected ResellerBase( BuilderBase pBuilder ) {
// Ensure that builder is not null.
Check.checkInvalidParameterNull(pBuilder, "pBuilder");
// Read object ID.
ObjectIdentity> lObjectID = pBuilder.objectID;
if (lObjectID != null) {
objectID = new ServiceObjectID(pBuilder.objectID);
}
else {
objectID = null;
}
// Read attribute values from builder.
if (pBuilder.channels != null) {
channels = pBuilder.channels;
// As association is bidirectional we also have to set it in the other direction.
for (Channel lNext : channels) {
lNext.setReseller((Reseller) this);
}
}
else {
channels = new ArrayList();
}
// Bidirectional back reference is set up correctly as a builder is used.
channelsBackReferenceInitialized = true;
products = new HashSet();
name = pBuilder.name;
language = pBuilder.language;
}
/**
* Class implements builder to create a new instance of class Reseller. 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 {
/**
* Reference to the identifier of this object. The reference may be null since an id is not mandatory.
*/
private ObjectIdentity> objectID;
private List channels;
/**
*
* Breaking Change with 1.1: Maximum size will be increased.
*/
@NotBlank
@Size(min = 0, max = 32)
private String name;
private Locale language;
/**
* Use {@link Reseller.builder()} instead of protected constructor to create new builder.
*/
protected BuilderBase( ) {
}
/**
* Use {@link Reseller.builder(Reseller)} instead of protected constructor to create new builder.
*/
protected BuilderBase( ResellerBase pObject ) {
if (pObject != null) {
// Read attribute values from passed object.
objectID = pObject.objectID;
this.setChannels(pObject.channels);
this.setName(pObject.name);
this.setLanguage(pObject.language);
}
}
/**
* Method sets the identifier for the object created using the builder. The reference may be null since an id is not
* mandatory.
*/
public BuilderBase setID( ObjectIdentity> pObjectID ) {
objectID = pObjectID;
return this;
}
/**
* Method sets association {@link #channels}.
*
* @param pChannels Collection to which {@link #channels} should be set.
* @return {@link BuilderBase} Instance of this builder to support chaining setters. Method never returns null.
*/
public BuilderBase setChannels( @MyNotEmptyProperty List pChannels ) {
// To ensure immutability we have to copy the content of the passed collection.
if (pChannels != null) {
channels = new ArrayList(pChannels);
}
else {
channels = null;
}
return this;
}
/**
* Method adds the passed objects to association {@link #channels}.
*
* @param pChannels Array of objects that should be added to {@link #channels}. The parameter may be null.
* @return {@link BuilderBase} Instance of this builder to support chaining. Method never returns null.
*/
public BuilderBase addToChannels( @MyNotEmptyProperty Channel... pChannels ) {
if (pChannels != null) {
if (channels == null) {
channels = new ArrayList();
}
channels.addAll(Arrays.asList(pChannels));
}
return this;
}
/**
* Method sets attribute {@link #name}.
*
* Breaking Change with 1.1: Maximum size will be increased.
*
* @param pName Value to which {@link #name} should be set.
* @return {@link BuilderBase} Instance of this builder to support chaining setters. Method never returns null.
*/
public BuilderBase setName( @MyNotNullProperty String pName ) {
// Assign value to attribute
name = pName;
return this;
}
/**
* Method sets attribute {@link #language}.
*
* @param pLanguage Value to which {@link #language} should be set.
* @return {@link BuilderBase} Instance of this builder to support chaining setters. Method never returns null.
*/
public BuilderBase setLanguage( @MyNotNullProperty Locale pLanguage ) {
// Assign value to attribute
language = pLanguage;
return this;
}
/**
* Method creates a new instance of class Reseller. The object will be initialized with the values of the builder.
*
* @return Reseller Created object. The method never returns null.
*/
public Reseller build( ) {
return new Reseller(this);
}
/**
* Method creates a new validated instance of class Reseller. The object will be initialized with the values of the
* builder and validated afterwards.
*
* @return Reseller Created and validated object. The method never returns null.
* @throws ConstraintViolationException in case that one or more validations for the created object failed.
*/
public Reseller buildValidated( ) throws ConstraintViolationException {
Reseller lPOJO = this.build();
ValidationTools.getValidationTools().enforceObjectValidation(lPOJO);
return lPOJO;
}
}
/**
* Method returns the id of this object.
*
* @return {@link ServiceObjectID} ID of this object. Since an object must not have an id the method may also return
* null.
*/
@Override
public final ServiceObjectID getID( ) {
return objectID;
}
/**
* Method returns the unversioned object id of this object.
*
* @return {@link ServiceObjectID} ID of this object. Since an object must not have an id the method may also return
* null.
*/
@Override
public final ServiceObjectID getUnversionedID( ) {
ServiceObjectID lUnversionedID;
if (objectID != null) {
lUnversionedID = objectID.getUnversionedObjectID();
}
else {
lUnversionedID = null;
}
return lUnversionedID;
}
/**
* Method returns association {@link #channels}.
*
* @return {@link List} Value to which {@link #channels} is set. The method never returns null and the
* returned collection is modifiable.
*/
@MyNotEmptyProperty
public List getChannels( ) {
// Due to restrictions in JSON serialization / deserialization bi-directional associations need a special handling
// after an object was deserialized.
if (channelsBackReferenceInitialized == false) {
channelsBackReferenceInitialized = true;
for (Channel lNext : channels) {
lNext.setReseller((Reseller) this);
}
}
// Return all Channel objects directly without any protection against modification.
return channels;
}
/**
* Method adds the passed object to {@link #channels}.
*
* @param pChannels Object that should be added to {@link #channels}. The parameter must not be null.
*/
public void addToChannels( Channel pChannels ) {
// Check parameter "pChannels" for invalid value null.
Check.checkInvalidParameterNull(pChannels, "pChannels");
// Since this is not a many-to-many association the association to which the passed object belongs, has to be
// released.
pChannels.unsetReseller();
// Add passed object to collection of associated Channel objects.
channels.add(pChannels);
// The association is set in both directions because within the UML model it is defined to be bidirectional.
// In case that one side will be removed from the association the other side will also be removed.
if (pChannels != null && this.equals(pChannels.getReseller()) == false) {
pChannels.setReseller((Reseller) this);
}
}
/**
* Method adds all passed objects to {@link #channels}.
*
* @param pChannels Collection with all objects that should be added to {@link #channels}. The parameter must not be
* null.
*/
public void addToChannels( Collection pChannels ) {
// Check parameter "pChannels" for invalid value null.
Check.checkInvalidParameterNull(pChannels, "pChannels");
// Add all passed objects.
for (Channel lNextObject : pChannels) {
this.addToChannels(lNextObject);
}
}
/**
* Method removes the passed object from {@link #channels}.
*
* @param pChannels Object that should be removed from {@link #channels}. The parameter must not be null.
*/
public void removeFromChannels( Channel pChannels ) {
// Check parameter for invalid value null.
Check.checkInvalidParameterNull(pChannels, "pChannels");
// Remove passed object from collection of associated Channel objects.
channels.remove(pChannels);
// The association is set in both directions because within the UML model it is defined to be bidirectional.
// In case that one side will be removed from the association the other side will also be removed.
if (this.equals(pChannels.getReseller()) == true) {
pChannels.unsetReseller();
}
}
/**
* Method removes all objects from {@link #channels}.
*/
public void clearChannels( ) {
// Remove all objects from association "channels".
Collection lChannels = new HashSet(channels);
Iterator lIterator = lChannels.iterator();
while (lIterator.hasNext()) {
// As association is bidirectional we have to clear it in both directions.
this.removeFromChannels(lIterator.next());
}
}
/**
* Method returns association {@link #products}.
*
* @return {@link Set} Value to which {@link #products} is set. The method never returns null and the
* returned collection is modifiable.
*/
@MyNotEmptyProperty
public Set getProducts( ) {
// Return all Product objects directly without any protection against modification.
return products;
}
/**
* Method adds the passed object to {@link #products}.
*
* @param pProducts Object that should be added to {@link #products}. The parameter must not be null.
*/
void addToProducts( Product pProducts ) {
// Check parameter "pProducts" for invalid value null.
Check.checkInvalidParameterNull(pProducts, "pProducts");
// Add passed object to collection of associated Product objects.
products.add(pProducts);
}
/**
* Method adds all passed objects to {@link #products}.
*
* @param pProducts Collection with all objects that should be added to {@link #products}. The parameter must not be
* null.
*/
void addToProducts( Collection pProducts ) {
// Check parameter "pProducts" for invalid value null.
Check.checkInvalidParameterNull(pProducts, "pProducts");
// Add all passed objects.
for (Product lNextObject : pProducts) {
this.addToProducts(lNextObject);
}
}
/**
* Method removes the passed object from {@link #products}.
*
* @param pProducts Object that should be removed from {@link #products}. The parameter must not be null.
*/
void removeFromProducts( Product pProducts ) {
// Check parameter for invalid value null.
Check.checkInvalidParameterNull(pProducts, "pProducts");
// Remove passed object from collection of associated Product objects.
products.remove(pProducts);
}
/**
* Method removes all objects from {@link #products}.
*/
void clearProducts( ) {
// Remove all objects from association "products".
Collection lProducts = new HashSet(products);
Iterator lIterator = lProducts.iterator();
while (lIterator.hasNext()) {
// As association is bidirectional we have to clear it in both directions.
this.removeFromProducts(lIterator.next());
}
}
/**
* Method returns attribute {@link #name}.
*
* Breaking Change with 1.1: Maximum size will be increased.
*
* @return {@link String} Value to which {@link #name} is set.
*/
@MyNotNullProperty
public String getName( ) {
return name;
}
/**
* Method sets attribute {@link #name}.
*
* Breaking Change with 1.1: Maximum size will be increased.
*
* @param pName Value to which {@link #name} should be set.
*/
public void setName( @MyNotNullProperty String pName ) {
// Assign value to attribute
name = pName;
}
/**
* Method returns attribute {@link #language}.
*
* @return {@link Locale} Value to which {@link #language} is set.
*/
@MyNotNullProperty
public Locale getLanguage( ) {
return language;
}
/**
* Method sets attribute {@link #language}.
*
* @param pLanguage Value to which {@link #language} should be set.
*/
public void setLanguage( @MyNotNullProperty Locale pLanguage ) {
// Assign value to attribute
language = pLanguage;
}
/**
* Convenience method to create new instance of class Reseller.
*
*
* @param pChannels Value to which {@link #channels} should be set.
*
* @param pName Value to which {@link #name} should be set.
*
* @param pLanguage Value to which {@link #language} should be set.
*
* @return {@link Reseller}
*/
public static Reseller of( List pChannels, String pName, Locale pLanguage ) {
Reseller.Builder lBuilder = Reseller.builder();
lBuilder.setChannels(pChannels);
lBuilder.setName(pName);
lBuilder.setLanguage(pLanguage);
return lBuilder.build();
}
/**
* @return {@link Integer}
*/
@MyNotNullProperty
public abstract Integer doSomething( );
/**
* @return double
*/
public abstract double returnPrimitive( );
/**
* 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.
*/
public StringBuilder toStringBuilder( String pIndent ) {
StringBuilder lBuilder = new StringBuilder();
lBuilder.append(pIndent);
lBuilder.append(this.getClass().getName());
lBuilder.append(System.lineSeparator());
lBuilder.append(pIndent);
lBuilder.append("channels: ");
if (channels != null) {
lBuilder.append(channels.size());
lBuilder.append(" element(s)");
}
else {
lBuilder.append(" null");
}
lBuilder.append(System.lineSeparator());
if (channels != null) {
for (Channel lNext : channels) {
lBuilder.append(lNext.toStringBuilder(pIndent + " "));
lBuilder.append(System.lineSeparator());
}
}
lBuilder.append(pIndent);
lBuilder.append("name: ");
lBuilder.append(name);
lBuilder.append(System.lineSeparator());
lBuilder.append(pIndent);
lBuilder.append("language: ");
lBuilder.append(language);
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 Reseller objects. The method never returns null.
*/
public Reseller.Builder toBuilder( ) {
return new Reseller.Builder((Reseller) this);
}
}