com.anaptecs.spring.base.Stop Maven / Gradle / Ivy
/*
* anaptecs GmbH, Ricarda-Huch-Str. 71, 72760 Reutlingen, Germany
*
* Copyright 2004 - 2019. All rights reserved.
*/
package com.anaptecs.spring.base;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class Stop {
/**
* Constant for the name of attribute "name".
*/
public static final String NAME = "name";
/**
* Constant for the name of attribute "links".
*/
public static final String LINKS = "links";
private String name;
private List links;
/**
* 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 Stop( ) {
links = new ArrayList();
}
/**
* Initialize object using the passed builder.
*
* @param pBuilder Builder that should be used to initialize this object. The parameter must not be null.
*/
protected Stop( Builder pBuilder ) {
// Read attribute values from builder.
name = pBuilder.name;
if (pBuilder.links != null) {
links = pBuilder.links;
}
else {
links = new ArrayList();
}
}
/**
* Method returns a new builder.
*
* @return {@link Builder} New builder that can be used to create new Stop objects.
*/
public static Builder builder( ) {
return new Builder();
}
/**
* Convenience method to create new instance of class Stop.
*
*
* @param pName Value to which {@link #name} should be set.
*
* @return {@link com.anaptecs.spring.base.Stop}
*/
public static Stop of( String pName ) {
Stop.Builder lBuilder = Stop.builder();
lBuilder.setName(pName);
return lBuilder.build();
}
/**
* Class implements builder to create a new instance of class Stop
.
*/
public static class Builder {
private String name;
private List links;
/**
* Use {@link Stop#builder()} instead of private constructor to create new builder.
*/
protected Builder( ) {
}
/**
* Use {@link Stop#builder(Stop)} instead of private constructor to create new builder.
*/
protected Builder( Stop pObject ) {
if (pObject != null) {
// Read attribute values from passed object.
this.setName(pObject.name);
this.setLinks(pObject.links);
}
}
/**
* 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 #links}.
*
* @param pLinks Collection to which {@link #links} should be set.
* @return {@link Builder} Instance of this builder to support chaining setters. Method never returns null.
*/
public Builder setLinks( List pLinks ) {
links = pLinks;
return this;
}
/**
* Method adds the passed objects to association {@link #links}.
*
* @param pLinks Array of objects that should be added to {@link #links}. The parameter may be null.
* @return {@link Builder} Instance of this builder to support chaining. Method never returns null.
*/
public Builder addToLinks( LinkObject... pLinks ) {
if (pLinks != null) {
if (links == null) {
links = new ArrayList();
}
links.addAll(Arrays.asList(pLinks));
}
return this;
}
/**
* Method creates a new instance of class Stop. The object will be initialized with the values of the builder.
*
* @return Stop Created object. The method never returns null.
*/
public Stop build( ) {
return new Stop(this);
}
}
/**
* 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 #links}.
*
* @return {@link List} Value to which {@link #links} is set. The method never returns null and the
* returned collection is unmodifiable.
*/
public List getLinks( ) {
// Return all LinkObject objects as unmodifiable collection.
return Collections.unmodifiableList(links);
}
/**
* Method adds the passed object to {@link #links}.
*
* @param pLinks Object that should be added to {@link #links}. The parameter must not be null.
*/
public void addToLinks( LinkObject pLinks ) {
// Add passed object to collection of associated LinkObject objects.
links.add(pLinks);
}
/**
* Method adds all passed objects to {@link #links}.
*
* @param pLinks Collection with all objects that should be added to {@link #links}. The parameter must not be null.
*/
public void addToLinks( Collection pLinks ) {
// Add all passed objects.
for (LinkObject lNextObject : pLinks) {
this.addToLinks(lNextObject);
}
}
/**
* Method removes the passed object from {@link #links}.
*
* @param pLinks Object that should be removed from {@link #links}. The parameter must not be null.
*/
public void removeFromLinks( LinkObject pLinks ) {
// Remove passed object from collection of associated LinkObject objects.
links.remove(pLinks);
}
/**
* Method removes all objects from {@link #links}.
*/
public void clearLinks( ) {
// Remove all objects from association "links".
links.clear();
}
@Override
public int hashCode( ) {
final int lPrime = 31;
int lResult = 1;
lResult = lPrime * lResult + Objects.hashCode(name);
lResult = lPrime * lResult + Objects.hashCode(links);
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 {
Stop lOther = (Stop) pObject;
lEquals = Objects.equals(name, lOther.name) && Objects.equals(links, lOther.links);
}
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("links: ");
if (links != null) {
lBuilder.append(links.size());
lBuilder.append(" element(s)");
}
else {
lBuilder.append(" null");
}
lBuilder.append(System.lineSeparator());
if (links != null) {
for (LinkObject lNext : links) {
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 Stop objects. The method never returns null.
*/
public Builder toBuilder( ) {
return new Builder(this);
}
}