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

com.anaptecs.jeaf.junit.pojo.transientback.ReadOnlyMaster Maven / Gradle / Ivy

There is a newer version: 1.24.1
Show newest version
/*
 * anaptecs GmbH, Ricarda-Huch-Str. 71, 72760 Reutlingen, Germany
 *
 * Copyright 2004 - 2019. All rights reserved.
 */
package com.anaptecs.jeaf.junit.pojo.transientback;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

import javax.annotation.Generated;
import javax.validation.ConstraintViolationException;

import com.anaptecs.jeaf.tools.api.validation.ValidationTools;
import com.anaptecs.jeaf.xfun.api.checks.Check;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;

@Generated("com.anaptecs.jeaf.generator.JEAFGenerator")
@SuppressWarnings("JEAF_SUPPRESS_WARNINGS")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ReadOnlyMaster {
  /**
   * Constant for the name of attribute "name".
   */
  public static final String NAME = "name";

  /**
   * Constant for the name of attribute "clients".
   */
  public static final String CLIENTS = "clients";

  private String name;

  @JsonSetter(nulls = Nulls.SKIP)
  private List clients;

  /**
   * Attribute is required for correct handling of bidirectional associations in case of deserialization.
   */
  private transient boolean clientsBackReferenceInitialized;

  /**
   * 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 ReadOnlyMaster( ) {
    clients = new ArrayList();
    // Bidirectional back reference is not yet set up correctly
    clientsBackReferenceInitialized = false;
  }

  /**
   * Initialize object using the passed builder.
   *
   * @param pBuilder Builder that should be used to initialize this object. The parameter must not be null.
   */
  protected ReadOnlyMaster( Builder pBuilder ) {
    // Ensure that builder is not null.
    Check.checkInvalidParameterNull(pBuilder, "pBuilder");
    // Read attribute values from builder.
    name = pBuilder.name;
    if (pBuilder.clients != null) {
      clients = pBuilder.clients;
      // As association is bidirectional we also have to set it in the other direction.
      for (ReadOnlyClient lNext : clients) {
        lNext.setTransientMaster((ReadOnlyMaster) this);
      }
    }
    else {
      clients = new ArrayList();
    }
    // Bidirectional back reference is set up correctly as a builder is used.
    clientsBackReferenceInitialized = true;
  }

  /**
   * Method returns a new builder.
   *
   * @return {@link Builder} New builder that can be used to create new ReadOnlyMaster objects.
   */
  public static Builder builder( ) {
    return new Builder();
  }

  /**
   * Convenience method to create new instance of class ReadOnlyMaster.
   *
   *
   * @param pName Value to which {@link #name} should be set.
   *
   * @return {@link ReadOnlyMaster}
   */
  public static ReadOnlyMaster of( String pName ) {
    ReadOnlyMaster.Builder lBuilder = ReadOnlyMaster.builder();
    lBuilder.setName(pName);
    return lBuilder.build();
  }

  /**
   * Class implements builder to create a new instance of class ReadOnlyMaster.
   */
  public static class Builder {
    private String name;

    private List clients;

    /**
     * Use {@link ReadOnlyMaster#builder()} instead of private constructor to create new builder.
     */
    protected Builder( ) {
    }

    /**
     * Use {@link ReadOnlyMaster#builder(ReadOnlyMaster)} instead of private constructor to create new builder.
     */
    protected Builder( ReadOnlyMaster pObject ) {
      if (pObject != null) {
        // Read attribute values from passed object.
        this.setName(pObject.name);
        this.setClients(pObject.clients);
      }
    }

    /**
     * Method sets attribute {@link #name}.
* * @param pName Value to which {@link #name} should be set. * @return {@link Builder} Instance of this builder to support chaining setters. Method never returns null. */ public Builder setName( String pName ) { // Assign value to attribute name = pName; return this; } /** * Method sets association {@link #clients}.
* * @param pClients Collection to which {@link #clients} should be set. * @return {@link Builder} Instance of this builder to support chaining setters. Method never returns null. */ public Builder setClients( List pClients ) { // To ensure immutability we have to copy the content of the passed collection. if (pClients != null) { clients = new ArrayList(pClients); } else { clients = null; } return this; } /** * Method adds the passed objects to association {@link #clients}.
* * @param pClients Array of objects that should be added to {@link #clients}. The parameter may be null. * @return {@link Builder} Instance of this builder to support chaining. Method never returns null. */ public Builder addToClients( ReadOnlyClient... pClients ) { if (pClients != null) { if (clients == null) { clients = new ArrayList(); } clients.addAll(Arrays.asList(pClients)); } return this; } /** * Method creates a new instance of class ReadOnlyMaster. The object will be initialized with the values of the * builder. * * @return ReadOnlyMaster Created object. The method never returns null. */ public ReadOnlyMaster build( ) { return new ReadOnlyMaster(this); } /** * Method creates a new validated instance of class ReadOnlyMaster. The object will be initialized with the values * of the builder and validated afterwards. * * @return ReadOnlyMaster Created and validated object. The method never returns null. * @throws ConstraintViolationException in case that one or more validations for the created object failed. */ public ReadOnlyMaster buildValidated( ) throws ConstraintViolationException { ReadOnlyMaster lObject = this.build(); ValidationTools.getValidationTools().enforceObjectValidation(lObject); return lObject; } } /** * Method returns attribute {@link #name}.
* * @return {@link String} Value to which {@link #name} is set. */ public String getName( ) { return name; } /** * Method sets attribute {@link #name}.
* * @param pName Value to which {@link #name} should be set. */ public void setName( String pName ) { // Assign value to attribute name = pName; } /** * Method returns association {@link #clients}.
* * @return {@link List} Value to which {@link #clients} is set. The method never returns null and the * returned collection is unmodifiable. */ public List getClients( ) { // Due to restrictions in JSON serialization / deserialization bi-directional associations need a special handling // after an object was deserialized. if (clientsBackReferenceInitialized == false) { clientsBackReferenceInitialized = true; for (ReadOnlyClient lNext : clients) { lNext.setTransientMaster((ReadOnlyMaster) this); } } // Return all ReadOnlyClient objects as unmodifiable collection. return Collections.unmodifiableList(clients); } /** * Method adds the passed object to {@link #clients}. * * @param pClients Object that should be added to {@link #clients}. The parameter must not be null. */ public void addToClients( ReadOnlyClient pClients ) { // Check parameter "pClients" for invalid value null. Check.checkInvalidParameterNull(pClients, "pClients"); // Since this is not a many-to-many association the association to which the passed object belongs, has to be // released. pClients.unsetTransientMaster(); // Add passed object to collection of associated ReadOnlyClient objects. clients.add(pClients); // 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 (pClients != null && this.equals(pClients.getTransientMaster()) == false) { pClients.setTransientMaster((ReadOnlyMaster) this); } } /** * Method adds all passed objects to {@link #clients}. * * @param pClients Collection with all objects that should be added to {@link #clients}. The parameter must not be * null. */ public void addToClients( Collection pClients ) { // Check parameter "pClients" for invalid value null. Check.checkInvalidParameterNull(pClients, "pClients"); // Add all passed objects. for (ReadOnlyClient lNextObject : pClients) { this.addToClients(lNextObject); } } /** * Method removes the passed object from {@link #clients}.
* * @param pClients Object that should be removed from {@link #clients}. The parameter must not be null. */ public void removeFromClients( ReadOnlyClient pClients ) { // Check parameter for invalid value null. Check.checkInvalidParameterNull(pClients, "pClients"); // Remove passed object from collection of associated ReadOnlyClient objects. clients.remove(pClients); // 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(pClients.getTransientMaster()) == true) { pClients.unsetTransientMaster(); } } /** * Method removes all objects from {@link #clients}. */ public void clearClients( ) { // Remove all objects from association "clients". Collection lClients = new HashSet(clients); Iterator lIterator = lClients.iterator(); while (lIterator.hasNext()) { // As association is bidirectional we have to clear it in both directions. this.removeFromClients(lIterator.next()); } } @Override public int hashCode( ) { final int lPrime = 31; int lResult = 1; lResult = lPrime * lResult + Objects.hashCode(name); lResult = lPrime * lResult + Objects.hashCode(clients); return lResult; } @Override public boolean equals( Object pObject ) { boolean lEquals; if (this == pObject) { lEquals = true; } else if (pObject == null) { lEquals = false; } else if (this.getClass() != pObject.getClass()) { lEquals = false; } else { ReadOnlyMaster lOther = (ReadOnlyMaster) pObject; lEquals = Objects.equals(name, lOther.name) && Objects.equals(clients, lOther.clients); } return lEquals; } /** * 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("name: "); lBuilder.append(name); lBuilder.append(System.lineSeparator()); lBuilder.append(pIndent); lBuilder.append("clients: "); if (clients != null) { lBuilder.append(clients.size()); lBuilder.append(" element(s)"); } else { lBuilder.append(" null"); } lBuilder.append(System.lineSeparator()); if (clients != null) { for (ReadOnlyClient lNext : clients) { lBuilder.append(lNext.toStringBuilder(pIndent + " ")); 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 ReadOnlyMaster objects. The method never returns * null. */ public Builder toBuilder( ) { return new Builder(this); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy