com.io7m.zeptoblog.glossary.ZGlossaryItemBody Maven / Gradle / Ivy
Show all versions of com.io7m.zeptoblog.glossary Show documentation
package com.io7m.zeptoblog.glossary;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.immutables.value.Generated;
/**
* The body of a glossary item.
*/
@Generated(from = "ZGlossaryItemBodyType", generator = "Immutables")
@SuppressWarnings({"all"})
public final class ZGlossaryItemBody implements ZGlossaryItemBodyType {
private final String format;
private final String text;
private ZGlossaryItemBody(String format, String text) {
this.format = Objects.requireNonNull(format, "format");
this.text = Objects.requireNonNull(text, "text");
}
private ZGlossaryItemBody(ZGlossaryItemBody.Builder builder) {
this.format = builder.format;
this.text = builder.text;
}
/**
* @return The name of the format provider
*/
@Override
public String format() {
return format;
}
/**
* @return The body text
*/
@Override
public String text() {
return text;
}
/**
* This instance is equal to all instances of {@code ZGlossaryItemBody} 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 ZGlossaryItemBody
&& equalTo(0, (ZGlossaryItemBody) another);
}
private boolean equalTo(int synthetic, ZGlossaryItemBody another) {
return format.equals(another.format)
&& text.equals(another.text);
}
/**
* Computes a hash code from attributes: {@code format}, {@code text}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + format.hashCode();
h += (h << 5) + text.hashCode();
return h;
}
/**
* Prints the immutable value {@code ZGlossaryItemBody} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "ZGlossaryItemBody{"
+ "format=" + format
+ ", text=" + text
+ "}";
}
/**
* Construct a new immutable {@code ZGlossaryItemBody} instance.
* @param format The value for the {@code format} attribute
* @param text The value for the {@code text} attribute
* @return An immutable ZGlossaryItemBody instance
*/
public static ZGlossaryItemBody of(String format, String text) {
return new ZGlossaryItemBody(format, text);
}
/**
* Creates a builder for {@link ZGlossaryItemBody ZGlossaryItemBody}.
*
* ZGlossaryItemBody.builder()
* .setFormat(String) // required {@link ZGlossaryItemBodyType#format() format}
* .setText(String) // required {@link ZGlossaryItemBodyType#text() text}
* .build();
*
* @return A new ZGlossaryItemBody builder
*/
public static ZGlossaryItemBody.Builder builder() {
return new ZGlossaryItemBody.Builder();
}
/**
* Builds instances of type {@link ZGlossaryItemBody ZGlossaryItemBody}.
* 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.
*/
@Generated(from = "ZGlossaryItemBodyType", generator = "Immutables")
public static final class Builder {
private static final long INIT_BIT_FORMAT = 0x1L;
private static final long INIT_BIT_TEXT = 0x2L;
private long initBits = 0x3L;
private String format;
private String text;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ZGlossaryItemBodyType} 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(ZGlossaryItemBodyType instance) {
Objects.requireNonNull(instance, "instance");
this.setFormat(instance.format());
this.setText(instance.text());
return this;
}
/**
* Initializes the value for the {@link ZGlossaryItemBodyType#format() format} attribute.
* @param format The value for format
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setFormat(String format) {
this.format = Objects.requireNonNull(format, "format");
initBits &= ~INIT_BIT_FORMAT;
return this;
}
/**
* Initializes the value for the {@link ZGlossaryItemBodyType#text() text} attribute.
* @param text The value for text
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setText(String text) {
this.text = Objects.requireNonNull(text, "text");
initBits &= ~INIT_BIT_TEXT;
return this;
}
/**
* Builds a new {@link ZGlossaryItemBody ZGlossaryItemBody}.
* @return An immutable instance of ZGlossaryItemBody
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ZGlossaryItemBody build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ZGlossaryItemBody(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_FORMAT) != 0) attributes.add("format");
if ((initBits & INIT_BIT_TEXT) != 0) attributes.add("text");
return "Cannot build ZGlossaryItemBody, some of required attributes are not set " + attributes;
}
}
}