com.io7m.changelog.xom.CAtomFeedMeta Maven / Gradle / Ivy
package com.io7m.changelog.xom;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.Generated;
/**
* The type of Atom feed metadata.
*/
@SuppressWarnings({"all"})
@Generated({"Immutables.generator", "CAtomFeedMetaType"})
public final class CAtomFeedMeta implements CAtomFeedMetaType {
private final String authorEmail;
private final String authorName;
private final String title;
private final URI uri;
private CAtomFeedMeta(String authorEmail, String authorName, String title, URI uri) {
this.authorEmail = Objects.requireNonNull(authorEmail, "authorEmail");
this.authorName = Objects.requireNonNull(authorName, "authorName");
this.title = Objects.requireNonNull(title, "title");
this.uri = Objects.requireNonNull(uri, "uri");
}
private CAtomFeedMeta(
CAtomFeedMeta original,
String authorEmail,
String authorName,
String title,
URI uri) {
this.authorEmail = authorEmail;
this.authorName = authorName;
this.title = title;
this.uri = uri;
}
/**
* @return The email of the feed author
*/
@Override
public String authorEmail() {
return authorEmail;
}
/**
* @return The name of the feed author
*/
@Override
public String authorName() {
return authorName;
}
/**
* @return The feed title
*/
@Override
public String title() {
return title;
}
/**
* @return The URI of the feed
*/
@Override
public URI uri() {
return uri;
}
/**
* Copy the current immutable object by setting a value for the {@link CAtomFeedMetaType#authorEmail() authorEmail} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for authorEmail
* @return A modified copy of the {@code this} object
*/
public final CAtomFeedMeta withAuthorEmail(String value) {
if (this.authorEmail.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "authorEmail");
return new CAtomFeedMeta(this, newValue, this.authorName, this.title, this.uri);
}
/**
* Copy the current immutable object by setting a value for the {@link CAtomFeedMetaType#authorName() authorName} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for authorName
* @return A modified copy of the {@code this} object
*/
public final CAtomFeedMeta withAuthorName(String value) {
if (this.authorName.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "authorName");
return new CAtomFeedMeta(this, this.authorEmail, newValue, this.title, this.uri);
}
/**
* Copy the current immutable object by setting a value for the {@link CAtomFeedMetaType#title() title} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for title
* @return A modified copy of the {@code this} object
*/
public final CAtomFeedMeta withTitle(String value) {
if (this.title.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "title");
return new CAtomFeedMeta(this, this.authorEmail, this.authorName, newValue, this.uri);
}
/**
* Copy the current immutable object by setting a value for the {@link CAtomFeedMetaType#uri() uri} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for uri
* @return A modified copy of the {@code this} object
*/
public final CAtomFeedMeta withUri(URI value) {
if (this.uri == value) return this;
URI newValue = Objects.requireNonNull(value, "uri");
return new CAtomFeedMeta(this, this.authorEmail, this.authorName, this.title, newValue);
}
/**
* This instance is equal to all instances of {@code CAtomFeedMeta} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(Object another) {
if (this == another) return true;
return another instanceof CAtomFeedMeta
&& equalTo((CAtomFeedMeta) another);
}
private boolean equalTo(CAtomFeedMeta another) {
return authorEmail.equals(another.authorEmail)
&& authorName.equals(another.authorName)
&& title.equals(another.title)
&& uri.equals(another.uri);
}
/**
* Computes a hash code from attributes: {@code authorEmail}, {@code authorName}, {@code title}, {@code uri}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + authorEmail.hashCode();
h = h * 17 + authorName.hashCode();
h = h * 17 + title.hashCode();
h = h * 17 + uri.hashCode();
return h;
}
/**
* Prints the immutable value {@code CAtomFeedMeta} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "CAtomFeedMeta{"
+ "authorEmail=" + authorEmail
+ ", authorName=" + authorName
+ ", title=" + title
+ ", uri=" + uri
+ "}";
}
/**
* Construct a new immutable {@code CAtomFeedMeta} instance.
* @param authorEmail The value for the {@code authorEmail} attribute
* @param authorName The value for the {@code authorName} attribute
* @param title The value for the {@code title} attribute
* @param uri The value for the {@code uri} attribute
* @return An immutable CAtomFeedMeta instance
*/
public static CAtomFeedMeta of(String authorEmail, String authorName, String title, URI uri) {
return new CAtomFeedMeta(authorEmail, authorName, title, uri);
}
/**
* Creates an immutable copy of a {@link CAtomFeedMetaType} value.
* Uses accessors to get values to initialize the new immutable instance.
* If an instance is already immutable, it is returned as is.
* @param instance The instance to copy
* @return A copied immutable CAtomFeedMeta instance
*/
public static CAtomFeedMeta copyOf(CAtomFeedMetaType instance) {
if (instance instanceof CAtomFeedMeta) {
return (CAtomFeedMeta) instance;
}
return CAtomFeedMeta.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link CAtomFeedMeta CAtomFeedMeta}.
* @return A new CAtomFeedMeta builder
*/
public static CAtomFeedMeta.Builder builder() {
return new CAtomFeedMeta.Builder();
}
/**
* Builds instances of type {@link CAtomFeedMeta CAtomFeedMeta}.
* Initialize attributes and then invoke the {@link #build()} method to create an
* immutable instance.
* {@code Builder} is not thread-safe and generally should not be stored in a field or collection,
* but instead used immediately to create instances.
*/
public static final class Builder {
private static final long INIT_BIT_AUTHOR_EMAIL = 0x1L;
private static final long INIT_BIT_AUTHOR_NAME = 0x2L;
private static final long INIT_BIT_TITLE = 0x4L;
private static final long INIT_BIT_URI = 0x8L;
private long initBits = 0xfL;
private String authorEmail;
private String authorName;
private String title;
private URI uri;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code CAtomFeedMetaType} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(CAtomFeedMetaType instance) {
Objects.requireNonNull(instance, "instance");
setAuthorEmail(instance.authorEmail());
setAuthorName(instance.authorName());
setTitle(instance.title());
setUri(instance.uri());
return this;
}
/**
* Initializes the value for the {@link CAtomFeedMetaType#authorEmail() authorEmail} attribute.
* @param authorEmail The value for authorEmail
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setAuthorEmail(String authorEmail) {
this.authorEmail = Objects.requireNonNull(authorEmail, "authorEmail");
initBits &= ~INIT_BIT_AUTHOR_EMAIL;
return this;
}
/**
* Initializes the value for the {@link CAtomFeedMetaType#authorName() authorName} attribute.
* @param authorName The value for authorName
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setAuthorName(String authorName) {
this.authorName = Objects.requireNonNull(authorName, "authorName");
initBits &= ~INIT_BIT_AUTHOR_NAME;
return this;
}
/**
* Initializes the value for the {@link CAtomFeedMetaType#title() title} attribute.
* @param title The value for title
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setTitle(String title) {
this.title = Objects.requireNonNull(title, "title");
initBits &= ~INIT_BIT_TITLE;
return this;
}
/**
* Initializes the value for the {@link CAtomFeedMetaType#uri() uri} attribute.
* @param uri The value for uri
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setUri(URI uri) {
this.uri = Objects.requireNonNull(uri, "uri");
initBits &= ~INIT_BIT_URI;
return this;
}
/**
* Builds a new {@link CAtomFeedMeta CAtomFeedMeta}.
* @return An immutable instance of CAtomFeedMeta
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public CAtomFeedMeta build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new CAtomFeedMeta(null, authorEmail, authorName, title, uri);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList();
if ((initBits & INIT_BIT_AUTHOR_EMAIL) != 0) attributes.add("authorEmail");
if ((initBits & INIT_BIT_AUTHOR_NAME) != 0) attributes.add("authorName");
if ((initBits & INIT_BIT_TITLE) != 0) attributes.add("title");
if ((initBits & INIT_BIT_URI) != 0) attributes.add("uri");
return "Cannot build CAtomFeedMeta, some of required attributes are not set " + attributes;
}
}
}