io.thestencil.client.api.ImmutableMarkdown Maven / Gradle / Ivy
package io.thestencil.client.api;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link Markdowns.Markdown}.
*
* Use the builder to create immutable instances:
* {@code ImmutableMarkdown.builder()}.
*/
@Generated(from = "Markdowns.Markdown", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableMarkdown implements Markdowns.Markdown {
private final String locale;
private final String path;
private final String value;
private final ImmutableList headings;
private final ImmutableList images;
private ImmutableMarkdown(
String locale,
String path,
String value,
ImmutableList headings,
ImmutableList images) {
this.locale = locale;
this.path = path;
this.value = value;
this.headings = headings;
this.images = images;
}
/**
* @return The value of the {@code locale} attribute
*/
@Override
public String getLocale() {
return locale;
}
/**
* @return The value of the {@code path} attribute
*/
@Override
public String getPath() {
return path;
}
/**
* @return The value of the {@code value} attribute
*/
@Override
public String getValue() {
return value;
}
/**
* @return The value of the {@code headings} attribute
*/
@Override
public ImmutableList getHeadings() {
return headings;
}
/**
* @return The value of the {@code images} attribute
*/
@Override
public ImmutableList getImages() {
return images;
}
/**
* Copy the current immutable object by setting a value for the {@link Markdowns.Markdown#getLocale() locale} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for locale
* @return A modified copy of the {@code this} object
*/
public final ImmutableMarkdown withLocale(String value) {
String newValue = Objects.requireNonNull(value, "locale");
if (this.locale.equals(newValue)) return this;
return new ImmutableMarkdown(newValue, this.path, this.value, this.headings, this.images);
}
/**
* Copy the current immutable object by setting a value for the {@link Markdowns.Markdown#getPath() path} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for path
* @return A modified copy of the {@code this} object
*/
public final ImmutableMarkdown withPath(String value) {
String newValue = Objects.requireNonNull(value, "path");
if (this.path.equals(newValue)) return this;
return new ImmutableMarkdown(this.locale, newValue, this.value, this.headings, this.images);
}
/**
* Copy the current immutable object by setting a value for the {@link Markdowns.Markdown#getValue() value} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for value
* @return A modified copy of the {@code this} object
*/
public final ImmutableMarkdown withValue(String value) {
String newValue = Objects.requireNonNull(value, "value");
if (this.value.equals(newValue)) return this;
return new ImmutableMarkdown(this.locale, this.path, newValue, this.headings, this.images);
}
/**
* Copy the current immutable object with elements that replace the content of {@link Markdowns.Markdown#getHeadings() headings}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableMarkdown withHeadings(Markdowns.Heading... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableMarkdown(this.locale, this.path, this.value, newValue, this.images);
}
/**
* Copy the current immutable object with elements that replace the content of {@link Markdowns.Markdown#getHeadings() headings}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of headings elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableMarkdown withHeadings(Iterable extends Markdowns.Heading> elements) {
if (this.headings == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableMarkdown(this.locale, this.path, this.value, newValue, this.images);
}
/**
* Copy the current immutable object with elements that replace the content of {@link Markdowns.Markdown#getImages() images}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableMarkdown withImages(Markdowns.ImageTag... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableMarkdown(this.locale, this.path, this.value, this.headings, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link Markdowns.Markdown#getImages() images}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of images elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableMarkdown withImages(Iterable extends Markdowns.ImageTag> elements) {
if (this.images == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableMarkdown(this.locale, this.path, this.value, this.headings, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableMarkdown} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@Nullable Object another) {
if (this == another) return true;
return another instanceof ImmutableMarkdown
&& equalTo(0, (ImmutableMarkdown) another);
}
private boolean equalTo(int synthetic, ImmutableMarkdown another) {
return locale.equals(another.locale)
&& path.equals(another.path)
&& value.equals(another.value)
&& headings.equals(another.headings)
&& images.equals(another.images);
}
/**
* Computes a hash code from attributes: {@code locale}, {@code path}, {@code value}, {@code headings}, {@code images}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + locale.hashCode();
h += (h << 5) + path.hashCode();
h += (h << 5) + value.hashCode();
h += (h << 5) + headings.hashCode();
h += (h << 5) + images.hashCode();
return h;
}
/**
* Prints the immutable value {@code Markdown} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Markdown")
.omitNullValues()
.add("locale", locale)
.add("path", path)
.add("value", value)
.add("headings", headings)
.add("images", images)
.toString();
}
/**
* Creates an immutable copy of a {@link Markdowns.Markdown} 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 Markdown instance
*/
public static ImmutableMarkdown copyOf(Markdowns.Markdown instance) {
if (instance instanceof ImmutableMarkdown) {
return (ImmutableMarkdown) instance;
}
return ImmutableMarkdown.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableMarkdown ImmutableMarkdown}.
*
* ImmutableMarkdown.builder()
* .locale(String) // required {@link Markdowns.Markdown#getLocale() locale}
* .path(String) // required {@link Markdowns.Markdown#getPath() path}
* .value(String) // required {@link Markdowns.Markdown#getValue() value}
* .addHeadings|addAllHeadings(io.thestencil.client.api.Markdowns.Heading) // {@link Markdowns.Markdown#getHeadings() headings} elements
* .addImages|addAllImages(io.thestencil.client.api.Markdowns.ImageTag) // {@link Markdowns.Markdown#getImages() images} elements
* .build();
*
* @return A new ImmutableMarkdown builder
*/
public static ImmutableMarkdown.Builder builder() {
return new ImmutableMarkdown.Builder();
}
/**
* Builds instances of type {@link ImmutableMarkdown ImmutableMarkdown}.
* 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 = "Markdowns.Markdown", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_LOCALE = 0x1L;
private static final long INIT_BIT_PATH = 0x2L;
private static final long INIT_BIT_VALUE = 0x4L;
private long initBits = 0x7L;
private @Nullable String locale;
private @Nullable String path;
private @Nullable String value;
private ImmutableList.Builder headings = ImmutableList.builder();
private ImmutableList.Builder images = ImmutableList.builder();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code Markdown} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(Markdowns.Markdown instance) {
Objects.requireNonNull(instance, "instance");
this.locale(instance.getLocale());
this.path(instance.getPath());
this.value(instance.getValue());
addAllHeadings(instance.getHeadings());
addAllImages(instance.getImages());
return this;
}
/**
* Initializes the value for the {@link Markdowns.Markdown#getLocale() locale} attribute.
* @param locale The value for locale
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder locale(String locale) {
this.locale = Objects.requireNonNull(locale, "locale");
initBits &= ~INIT_BIT_LOCALE;
return this;
}
/**
* Initializes the value for the {@link Markdowns.Markdown#getPath() path} attribute.
* @param path The value for path
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder path(String path) {
this.path = Objects.requireNonNull(path, "path");
initBits &= ~INIT_BIT_PATH;
return this;
}
/**
* Initializes the value for the {@link Markdowns.Markdown#getValue() value} attribute.
* @param value The value for value
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder value(String value) {
this.value = Objects.requireNonNull(value, "value");
initBits &= ~INIT_BIT_VALUE;
return this;
}
/**
* Adds one element to {@link Markdowns.Markdown#getHeadings() headings} list.
* @param element A headings element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addHeadings(Markdowns.Heading element) {
this.headings.add(element);
return this;
}
/**
* Adds elements to {@link Markdowns.Markdown#getHeadings() headings} list.
* @param elements An array of headings elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addHeadings(Markdowns.Heading... elements) {
this.headings.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link Markdowns.Markdown#getHeadings() headings} list.
* @param elements An iterable of headings elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder headings(Iterable extends Markdowns.Heading> elements) {
this.headings = ImmutableList.builder();
return addAllHeadings(elements);
}
/**
* Adds elements to {@link Markdowns.Markdown#getHeadings() headings} list.
* @param elements An iterable of headings elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllHeadings(Iterable extends Markdowns.Heading> elements) {
this.headings.addAll(elements);
return this;
}
/**
* Adds one element to {@link Markdowns.Markdown#getImages() images} list.
* @param element A images element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addImages(Markdowns.ImageTag element) {
this.images.add(element);
return this;
}
/**
* Adds elements to {@link Markdowns.Markdown#getImages() images} list.
* @param elements An array of images elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addImages(Markdowns.ImageTag... elements) {
this.images.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link Markdowns.Markdown#getImages() images} list.
* @param elements An iterable of images elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder images(Iterable extends Markdowns.ImageTag> elements) {
this.images = ImmutableList.builder();
return addAllImages(elements);
}
/**
* Adds elements to {@link Markdowns.Markdown#getImages() images} list.
* @param elements An iterable of images elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllImages(Iterable extends Markdowns.ImageTag> elements) {
this.images.addAll(elements);
return this;
}
/**
* Builds a new {@link ImmutableMarkdown ImmutableMarkdown}.
* @return An immutable instance of Markdown
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableMarkdown build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableMarkdown(locale, path, value, headings.build(), images.build());
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_LOCALE) != 0) attributes.add("locale");
if ((initBits & INIT_BIT_PATH) != 0) attributes.add("path");
if ((initBits & INIT_BIT_VALUE) != 0) attributes.add("value");
return "Cannot build Markdown, some of required attributes are not set " + attributes;
}
}
}