com.io7m.changelog.core.CVersionText Maven / Gradle / Ivy
Show all versions of io7m-changelog-core Show documentation
package com.io7m.changelog.core;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.Generated;
/**
*
* The type of arbitrary lexicographically ordered version strings.
*
*/
@SuppressWarnings({"all"})
@Generated({"Immutables.generator", "CVersionTextType"})
public final class CVersionText implements CVersionTextType {
private final String text;
private CVersionText(String text) {
this.text = Objects.requireNonNull(text, "text");
}
private CVersionText(CVersionText original, String text) {
this.text = text;
}
/**
* @return The version number text
*/
@Override
public String text() {
return text;
}
/**
* Copy the current immutable object by setting a value for the {@link CVersionTextType#text() text} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for text
* @return A modified copy of the {@code this} object
*/
public final CVersionText withText(String value) {
if (this.text.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "text");
return new CVersionText(this, newValue);
}
/**
* This instance is equal to all instances of {@code CVersionText} 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 CVersionText
&& equalTo((CVersionText) another);
}
private boolean equalTo(CVersionText another) {
return text.equals(another.text);
}
/**
* Computes a hash code from attributes: {@code text}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + text.hashCode();
return h;
}
/**
* Prints the immutable value {@code CVersionText} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "CVersionText{"
+ "text=" + text
+ "}";
}
/**
* Construct a new immutable {@code CVersionText} instance.
* @param text The value for the {@code text} attribute
* @return An immutable CVersionText instance
*/
public static CVersionText of(String text) {
return new CVersionText(text);
}
/**
* Creates an immutable copy of a {@link CVersionTextType} 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 CVersionText instance
*/
public static CVersionText copyOf(CVersionTextType instance) {
if (instance instanceof CVersionText) {
return (CVersionText) instance;
}
return CVersionText.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link CVersionText CVersionText}.
* @return A new CVersionText builder
*/
public static CVersionText.Builder builder() {
return new CVersionText.Builder();
}
/**
* Builds instances of type {@link CVersionText CVersionText}.
* 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_TEXT = 0x1L;
private long initBits = 0x1L;
private String text;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code CVersionTextType} 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(CVersionTextType instance) {
Objects.requireNonNull(instance, "instance");
setText(instance.text());
return this;
}
/**
* Initializes the value for the {@link CVersionTextType#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 CVersionText CVersionText}.
* @return An immutable instance of CVersionText
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public CVersionText build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new CVersionText(null, text);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList();
if ((initBits & INIT_BIT_TEXT) != 0) attributes.add("text");
return "Cannot build CVersionText, some of required attributes are not set " + attributes;
}
}
}