BakerCliBakeOptions_Builder.java
// Autogenerated code. Do not modify.
package com.varmateo.yawg.cli;
import io.vavr.collection.Map;
import io.vavr.control.Option;
import java.nio.file.Path;
import java.util.EnumSet;
import java.util.Objects;
import java.util.function.UnaryOperator;
import javax.annotation.Generated;
/**
* Auto-generated superclass of {@link BakerCliBakeOptions.Builder}, derived from the API of {@link
* BakerCliBakeOptions}.
*/
@Generated("org.inferred.freebuilder.processor.Processor")
abstract class BakerCliBakeOptions_Builder {
/**
* Creates a new builder using {@code value} as a template.
*
* <p>If {@code value} is a partial, the builder will return more partials.
*/
public static BakerCliBakeOptions.Builder from(BakerCliBakeOptions value) {
if (value instanceof Rebuildable) {
return ((Rebuildable) value).toBuilder();
} else {
return BakerCliBakeOptions.builder().mergeFrom(value);
}
}
private enum Property {
SOURCE_DIR("sourceDir"),
TARGET_DIR("targetDir"),
TEMPLATES_DIR("templatesDir"),
EXTERNAL_PAGE_VARS("externalPageVars"),
;
private final String name;
private Property(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}
private Path sourceDir;
private Path targetDir;
private Option<Path> templatesDir;
private Map<String, String> externalPageVars;
private final EnumSet<Property> _unsetProperties = EnumSet.allOf(Property.class);
/**
* Sets the value to be returned by {@link BakerCliBakeOptions#sourceDir()}.
*
* @return this {@code Builder} object
* @throws NullPointerException if {@code sourceDir} is null
*/
public BakerCliBakeOptions.Builder sourceDir(Path sourceDir) {
this.sourceDir = Objects.requireNonNull(sourceDir);
_unsetProperties.remove(Property.SOURCE_DIR);
return (BakerCliBakeOptions.Builder) this;
}
/**
* Replaces the value to be returned by {@link BakerCliBakeOptions#sourceDir()} by applying {@code
* mapper} to it and using the result.
*
* @return this {@code Builder} object
* @throws NullPointerException if {@code mapper} is null or returns null
* @throws IllegalStateException if the field has not been set
*/
public BakerCliBakeOptions.Builder mapSourceDir(UnaryOperator<Path> mapper) {
Objects.requireNonNull(mapper);
return sourceDir(mapper.apply(sourceDir()));
}
/**
* Returns the value that will be returned by {@link BakerCliBakeOptions#sourceDir()}.
*
* @throws IllegalStateException if the field has not been set
*/
public Path sourceDir() {
if (_unsetProperties.contains(Property.SOURCE_DIR)) {
throw new IllegalStateException("sourceDir not set");
}
return sourceDir;
}
/**
* Sets the value to be returned by {@link BakerCliBakeOptions#targetDir()}.
*
* @return this {@code Builder} object
* @throws NullPointerException if {@code targetDir} is null
*/
public BakerCliBakeOptions.Builder targetDir(Path targetDir) {
this.targetDir = Objects.requireNonNull(targetDir);
_unsetProperties.remove(Property.TARGET_DIR);
return (BakerCliBakeOptions.Builder) this;
}
/**
* Replaces the value to be returned by {@link BakerCliBakeOptions#targetDir()} by applying {@code
* mapper} to it and using the result.
*
* @return this {@code Builder} object
* @throws NullPointerException if {@code mapper} is null or returns null
* @throws IllegalStateException if the field has not been set
*/
public BakerCliBakeOptions.Builder mapTargetDir(UnaryOperator<Path> mapper) {
Objects.requireNonNull(mapper);
return targetDir(mapper.apply(targetDir()));
}
/**
* Returns the value that will be returned by {@link BakerCliBakeOptions#targetDir()}.
*
* @throws IllegalStateException if the field has not been set
*/
public Path targetDir() {
if (_unsetProperties.contains(Property.TARGET_DIR)) {
throw new IllegalStateException("targetDir not set");
}
return targetDir;
}
/**
* Sets the value to be returned by {@link BakerCliBakeOptions#templatesDir()}.
*
* @return this {@code Builder} object
* @throws NullPointerException if {@code templatesDir} is null
*/
public BakerCliBakeOptions.Builder templatesDir(Option<Path> templatesDir) {
this.templatesDir = Objects.requireNonNull(templatesDir);
_unsetProperties.remove(Property.TEMPLATES_DIR);
return (BakerCliBakeOptions.Builder) this;
}
/**
* Replaces the value to be returned by {@link BakerCliBakeOptions#templatesDir()} by applying
* {@code mapper} to it and using the result.
*
* @return this {@code Builder} object
* @throws NullPointerException if {@code mapper} is null or returns null
* @throws IllegalStateException if the field has not been set
*/
public BakerCliBakeOptions.Builder mapTemplatesDir(UnaryOperator<Option<Path>> mapper) {
Objects.requireNonNull(mapper);
return templatesDir(mapper.apply(templatesDir()));
}
/**
* Returns the value that will be returned by {@link BakerCliBakeOptions#templatesDir()}.
*
* @throws IllegalStateException if the field has not been set
*/
public Option<Path> templatesDir() {
if (_unsetProperties.contains(Property.TEMPLATES_DIR)) {
throw new IllegalStateException("templatesDir not set");
}
return templatesDir;
}
/**
* Sets the value to be returned by {@link BakerCliBakeOptions#externalPageVars()}.
*
* @return this {@code Builder} object
* @throws NullPointerException if {@code externalPageVars} is null
*/
public BakerCliBakeOptions.Builder externalPageVars(Map<String, String> externalPageVars) {
this.externalPageVars = Objects.requireNonNull(externalPageVars);
_unsetProperties.remove(Property.EXTERNAL_PAGE_VARS);
return (BakerCliBakeOptions.Builder) this;
}
/**
* Replaces the value to be returned by {@link BakerCliBakeOptions#externalPageVars()} by applying
* {@code mapper} to it and using the result.
*
* @return this {@code Builder} object
* @throws NullPointerException if {@code mapper} is null or returns null
* @throws IllegalStateException if the field has not been set
*/
public BakerCliBakeOptions.Builder mapExternalPageVars(
UnaryOperator<Map<String, String>> mapper) {
Objects.requireNonNull(mapper);
return externalPageVars(mapper.apply(externalPageVars()));
}
/**
* Returns the value that will be returned by {@link BakerCliBakeOptions#externalPageVars()}.
*
* @throws IllegalStateException if the field has not been set
*/
public Map<String, String> externalPageVars() {
if (_unsetProperties.contains(Property.EXTERNAL_PAGE_VARS)) {
throw new IllegalStateException("externalPageVars not set");
}
return externalPageVars;
}
/**
* Copies values from {@code value}.
*
* @return this {@code Builder} object
*/
public BakerCliBakeOptions.Builder mergeFrom(BakerCliBakeOptions value) {
BakerCliBakeOptions_Builder defaults = BakerCliBakeOptions.builder();
if (defaults._unsetProperties.contains(Property.SOURCE_DIR)
|| !Objects.equals(value.sourceDir(), defaults.sourceDir())) {
sourceDir(value.sourceDir());
}
if (defaults._unsetProperties.contains(Property.TARGET_DIR)
|| !Objects.equals(value.targetDir(), defaults.targetDir())) {
targetDir(value.targetDir());
}
if (defaults._unsetProperties.contains(Property.TEMPLATES_DIR)
|| !Objects.equals(value.templatesDir(), defaults.templatesDir())) {
templatesDir(value.templatesDir());
}
if (defaults._unsetProperties.contains(Property.EXTERNAL_PAGE_VARS)
|| !Objects.equals(value.externalPageVars(), defaults.externalPageVars())) {
externalPageVars(value.externalPageVars());
}
return (BakerCliBakeOptions.Builder) this;
}
/**
* Copies values from {@code template}, skipping unset properties.
*
* @return this {@code Builder} object
*/
public BakerCliBakeOptions.Builder mergeFrom(BakerCliBakeOptions.Builder template) {
// Upcast to access private fields; otherwise, oddly, we get an access violation.
BakerCliBakeOptions_Builder base = template;
BakerCliBakeOptions_Builder defaults = BakerCliBakeOptions.builder();
if (!base._unsetProperties.contains(Property.SOURCE_DIR)
&& (defaults._unsetProperties.contains(Property.SOURCE_DIR)
|| !Objects.equals(template.sourceDir(), defaults.sourceDir()))) {
sourceDir(template.sourceDir());
}
if (!base._unsetProperties.contains(Property.TARGET_DIR)
&& (defaults._unsetProperties.contains(Property.TARGET_DIR)
|| !Objects.equals(template.targetDir(), defaults.targetDir()))) {
targetDir(template.targetDir());
}
if (!base._unsetProperties.contains(Property.TEMPLATES_DIR)
&& (defaults._unsetProperties.contains(Property.TEMPLATES_DIR)
|| !Objects.equals(template.templatesDir(), defaults.templatesDir()))) {
templatesDir(template.templatesDir());
}
if (!base._unsetProperties.contains(Property.EXTERNAL_PAGE_VARS)
&& (defaults._unsetProperties.contains(Property.EXTERNAL_PAGE_VARS)
|| !Objects.equals(template.externalPageVars(), defaults.externalPageVars()))) {
externalPageVars(template.externalPageVars());
}
return (BakerCliBakeOptions.Builder) this;
}
/**
* Resets the state of this builder.
*
* @return this {@code Builder} object
*/
public BakerCliBakeOptions.Builder clear() {
BakerCliBakeOptions_Builder defaults = BakerCliBakeOptions.builder();
sourceDir = defaults.sourceDir;
targetDir = defaults.targetDir;
templatesDir = defaults.templatesDir;
externalPageVars = defaults.externalPageVars;
_unsetProperties.clear();
_unsetProperties.addAll(defaults._unsetProperties);
return (BakerCliBakeOptions.Builder) this;
}
/**
* Returns a newly-created {@link BakerCliBakeOptions} based on the contents of this {@code
* Builder}.
*
* @throws IllegalStateException if any field has not been set
*/
public BakerCliBakeOptions build() {
if (!_unsetProperties.isEmpty()) {
throw new IllegalStateException("Not set: " + _unsetProperties);
}
return new Value(this);
}
/**
* Returns a newly-created partial {@link BakerCliBakeOptions} for use in unit tests. State
* checking will not be performed. Unset properties will throw an {@link
* UnsupportedOperationException} when accessed via the partial object.
*
* <p>The builder returned by {@link BakerCliBakeOptions.Builder#from(BakerCliBakeOptions)} will
* propagate the partial status of its input, overriding {@link
* BakerCliBakeOptions.Builder#build() build()} to return another partial. This allows for robust
* tests of modify-rebuild code.
*
* <p>Partials should only ever be used in tests. They permit writing robust test cases that won't
* fail if this type gains more application-level constraints (e.g. new required fields) in
* future. If you require partially complete values in production code, consider using a Builder.
*/
public BakerCliBakeOptions buildPartial() {
return new Partial(this);
}
private abstract static class Rebuildable implements BakerCliBakeOptions {
public abstract Builder toBuilder();
}
private static final class Value extends Rebuildable {
private final Path sourceDir;
private final Path targetDir;
private final Option<Path> templatesDir;
private final Map<String, String> externalPageVars;
private Value(BakerCliBakeOptions_Builder builder) {
this.sourceDir = builder.sourceDir;
this.targetDir = builder.targetDir;
this.templatesDir = builder.templatesDir;
this.externalPageVars = builder.externalPageVars;
}
@Override
public Path sourceDir() {
return sourceDir;
}
@Override
public Path targetDir() {
return targetDir;
}
@Override
public Option<Path> templatesDir() {
return templatesDir;
}
@Override
public Map<String, String> externalPageVars() {
return externalPageVars;
}
@Override
public Builder toBuilder() {
BakerCliBakeOptions_Builder builder = BakerCliBakeOptions.builder();
builder.sourceDir = sourceDir;
builder.targetDir = targetDir;
builder.templatesDir = templatesDir;
builder.externalPageVars = externalPageVars;
builder._unsetProperties.clear();
return (Builder) builder;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Value)) {
return false;
}
Value other = (Value) obj;
return Objects.equals(sourceDir, other.sourceDir)
&& Objects.equals(targetDir, other.targetDir)
&& Objects.equals(templatesDir, other.templatesDir)
&& Objects.equals(externalPageVars, other.externalPageVars);
}
@Override
public int hashCode() {
return Objects.hash(sourceDir, targetDir, templatesDir, externalPageVars);
}
@Override
public String toString() {
return "BakerCliBakeOptions{sourceDir="
+ sourceDir
+ ", targetDir="
+ targetDir
+ ", templatesDir="
+ templatesDir
+ ", externalPageVars="
+ externalPageVars
+ "}";
}
}
private static final class Partial extends Rebuildable {
private final Path sourceDir;
private final Path targetDir;
private final Option<Path> templatesDir;
private final Map<String, String> externalPageVars;
private final EnumSet<Property> _unsetProperties;
Partial(BakerCliBakeOptions_Builder builder) {
this.sourceDir = builder.sourceDir;
this.targetDir = builder.targetDir;
this.templatesDir = builder.templatesDir;
this.externalPageVars = builder.externalPageVars;
this._unsetProperties = builder._unsetProperties.clone();
}
@Override
public Path sourceDir() {
if (_unsetProperties.contains(Property.SOURCE_DIR)) {
throw new UnsupportedOperationException("sourceDir not set");
}
return sourceDir;
}
@Override
public Path targetDir() {
if (_unsetProperties.contains(Property.TARGET_DIR)) {
throw new UnsupportedOperationException("targetDir not set");
}
return targetDir;
}
@Override
public Option<Path> templatesDir() {
if (_unsetProperties.contains(Property.TEMPLATES_DIR)) {
throw new UnsupportedOperationException("templatesDir not set");
}
return templatesDir;
}
@Override
public Map<String, String> externalPageVars() {
if (_unsetProperties.contains(Property.EXTERNAL_PAGE_VARS)) {
throw new UnsupportedOperationException("externalPageVars not set");
}
return externalPageVars;
}
@Override
public Builder toBuilder() {
throw new UnsupportedOperationException();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Partial)) {
return false;
}
Partial other = (Partial) obj;
return Objects.equals(sourceDir, other.sourceDir)
&& Objects.equals(targetDir, other.targetDir)
&& Objects.equals(templatesDir, other.templatesDir)
&& Objects.equals(externalPageVars, other.externalPageVars)
&& Objects.equals(_unsetProperties, other._unsetProperties);
}
@Override
public int hashCode() {
return Objects.hash(sourceDir, targetDir, templatesDir, externalPageVars, _unsetProperties);
}
@Override
public String toString() {
StringBuilder result = new StringBuilder("partial BakerCliBakeOptions{");
String separator = "";
if (!_unsetProperties.contains(Property.SOURCE_DIR)) {
result.append("sourceDir=").append(sourceDir);
separator = ", ";
}
if (!_unsetProperties.contains(Property.TARGET_DIR)) {
result.append(separator).append("targetDir=").append(targetDir);
separator = ", ";
}
if (!_unsetProperties.contains(Property.TEMPLATES_DIR)) {
result.append(separator).append("templatesDir=").append(templatesDir);
separator = ", ";
}
if (!_unsetProperties.contains(Property.EXTERNAL_PAGE_VARS)) {
result.append(separator).append("externalPageVars=").append(externalPageVars);
}
return result.append("}").toString();
}
}
}