com.io7m.zeptoblog.glossary.ZGlossaryItem Maven / Gradle / Ivy
Show all versions of com.io7m.zeptoblog.glossary Show documentation
package com.io7m.zeptoblog.glossary;
import io.vavr.collection.HashSet;
import io.vavr.collection.Set;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.immutables.value.Generated;
/**
* The type of glossary items.
*/
@Generated(from = "ZGlossaryItemType", generator = "Immutables")
@SuppressWarnings({"all"})
public final class ZGlossaryItem implements ZGlossaryItemType {
private final String term;
private final Set seeAlso;
private final ZGlossaryItemBody body;
private final Path path;
private ZGlossaryItem(
String term,
Set seeAlso,
ZGlossaryItemBody body,
Path path) {
this.term = Objects.requireNonNull(term, "term");
this.seeAlso = seeAlso;
this.body = Objects.requireNonNull(body, "body");
this.path = Objects.requireNonNull(path, "path");
this.initShim = null;
}
private ZGlossaryItem(ZGlossaryItem.Builder builder) {
this.term = builder.term;
this.seeAlso = builder.seeAlso_build();
this.body = builder.body;
this.path = builder.path;
this.initShim = null;
}
private static final byte STAGE_INITIALIZING = -1;
private static final byte STAGE_UNINITIALIZED = 0;
private static final byte STAGE_INITIALIZED = 1;
private transient volatile InitShim initShim = new InitShim();
@Generated(from = "ZGlossaryItemType", generator = "Immutables")
private final class InitShim {
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
return "Cannot build ZGlossaryItem, attribute initializers form cycle " + attributes;
}
}
/**
* @return The glossary term
*/
@Override
public String term() {
return term;
}
/**
* @return The terms related to this term.
*/
@Override
public Set seeAlso() {
return seeAlso;
}
/**
* @return The body of the glossary term.
*/
@Override
public ZGlossaryItemBody body() {
return body;
}
/**
* @return The file containing the definition
*/
@Override
public Path path() {
return path;
}
/**
* This instance is equal to all instances of {@code ZGlossaryItem} 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 ZGlossaryItem
&& equalTo(0, (ZGlossaryItem) another);
}
private boolean equalTo(int synthetic, ZGlossaryItem another) {
return term.equals(another.term)
&& this.seeAlso().equals(another.seeAlso())
&& body.equals(another.body)
&& path.equals(another.path);
}
/**
* Computes a hash code from attributes: {@code term}, {@code seeAlso}, {@code body}, {@code path}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + term.hashCode();
h += (h << 5) + (seeAlso().hashCode());
h += (h << 5) + body.hashCode();
h += (h << 5) + path.hashCode();
return h;
}
/**
* Prints the immutable value {@code ZGlossaryItem} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "ZGlossaryItem{"
+ "term=" + term
+ ", seeAlso=" + (seeAlso().toString())
+ ", body=" + body
+ ", path=" + path
+ "}";
}
/**
* Construct a new immutable {@code ZGlossaryItem} instance.
* @param term The value for the {@code term} attribute
* @param seeAlso The value for the {@code seeAlso} attribute
* @param body The value for the {@code body} attribute
* @param path The value for the {@code path} attribute
* @return An immutable ZGlossaryItem instance
*/
public static ZGlossaryItem of(String term, Set seeAlso, ZGlossaryItemBody body, Path path) {
return new ZGlossaryItem(term, seeAlso, body, path);
}
/**
* Creates a builder for {@link ZGlossaryItem ZGlossaryItem}.
*
* ZGlossaryItem.builder()
* .setTerm(String) // required {@link ZGlossaryItemType#term() term}
* .setSeeAlso(io.vavr.collection.Set<String>) // {@link ZGlossaryItemType#seeAlso() seeAlso}
* .setBody(com.io7m.zeptoblog.glossary.ZGlossaryItemBody) // required {@link ZGlossaryItemType#body() body}
* .setPath(java.nio.file.Path) // required {@link ZGlossaryItemType#path() path}
* .build();
*
* @return A new ZGlossaryItem builder
*/
public static ZGlossaryItem.Builder builder() {
return new ZGlossaryItem.Builder();
}
/**
* Builds instances of type {@link ZGlossaryItem ZGlossaryItem}.
* 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 = "ZGlossaryItemType", generator = "Immutables")
public static final class Builder {
private static final long INIT_BIT_TERM = 0x1L;
private static final long INIT_BIT_BODY = 0x2L;
private static final long INIT_BIT_PATH = 0x4L;
private long initBits = 0x7L;
private Set seeAlso_set = HashSet.empty();
private String term;
private ZGlossaryItemBody body;
private Path path;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ZGlossaryItemType} 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(ZGlossaryItemType instance) {
Objects.requireNonNull(instance, "instance");
this.setTerm(instance.term());
setSeeAlso(instance.seeAlso());
this.setBody(instance.body());
this.setPath(instance.path());
return this;
}
/**
* Initializes the value for the {@link ZGlossaryItemType#term() term} attribute.
* @param term The value for term
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setTerm(String term) {
this.term = Objects.requireNonNull(term, "term");
initBits &= ~INIT_BIT_TERM;
return this;
}
public Builder addSeeAlso(String element) {
this.seeAlso_set = this.seeAlso_set.add(element);
return this;
}
@SafeVarargs
public final Builder addSeeAlso(String... elements) {
this.seeAlso_set = this.seeAlso_set.addAll(HashSet.of(elements));
return this;
}
public Builder addAllSeeAlso(Iterable element) {
this.seeAlso_set = this.seeAlso_set.addAll(element);
return this;
}
public Builder setSeeAlso(Set elements) {
this.seeAlso_set = elements;
return this;
}
public Builder setIterableSeeAlso(Iterable elements) {
this.seeAlso_set = HashSet.ofAll(elements);
return this;
}
/**
* Initializes the value for the {@link ZGlossaryItemType#body() body} attribute.
* @param body The value for body
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setBody(ZGlossaryItemBody body) {
this.body = Objects.requireNonNull(body, "body");
initBits &= ~INIT_BIT_BODY;
return this;
}
/**
* Initializes the value for the {@link ZGlossaryItemType#path() path} attribute.
* @param path The value for path
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setPath(Path path) {
this.path = Objects.requireNonNull(path, "path");
initBits &= ~INIT_BIT_PATH;
return this;
}
/**
* Builds a new {@link ZGlossaryItem ZGlossaryItem}.
* @return An immutable instance of ZGlossaryItem
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ZGlossaryItem build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ZGlossaryItem(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_TERM) != 0) attributes.add("term");
if ((initBits & INIT_BIT_BODY) != 0) attributes.add("body");
if ((initBits & INIT_BIT_PATH) != 0) attributes.add("path");
return "Cannot build ZGlossaryItem, some of required attributes are not set " + attributes;
}
private Set seeAlso_build() {
return this.seeAlso_set;
}
}
}