
com.io7m.minisite.core.MinConfiguration Maven / Gradle / Ivy
package com.io7m.minisite.core;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* Configurations for sites.
*/
@SuppressWarnings({"all"})
public final class MinConfiguration implements MinConfigurationType {
private final String projectName;
private final String projectGroupName;
private final List projectModules;
private final String release;
private final String centralReposPath;
private final Path header;
private final Path overview;
private final Path features;
private final Path documentation;
private final MinChangesConfiguration changelog;
private final Path license;
private final MinBugTrackerConfiguration bugTracker;
private final MinSourcesConfiguration sources;
private final List cssIncludes;
private final boolean cssGenerateStyle;
@SuppressWarnings("unchecked") // safe covariant cast
private MinConfiguration(
String projectName,
String projectGroupName,
Iterable projectModules,
String release,
String centralReposPath,
Optional extends Path> header,
Optional extends Path> overview,
Optional extends Path> features,
Optional extends Path> documentation,
Optional extends MinChangesConfiguration> changelog,
Optional extends Path> license,
Optional extends MinBugTrackerConfiguration> bugTracker,
Optional extends MinSourcesConfiguration> sources,
Iterable cssIncludes,
boolean cssGenerateStyle) {
this.projectName = Objects.requireNonNull(projectName, "projectName");
this.projectGroupName = Objects.requireNonNull(projectGroupName, "projectGroupName");
this.projectModules = createUnmodifiableList(false, createSafeList(projectModules, true, false));
this.release = Objects.requireNonNull(release, "release");
this.centralReposPath = Objects.requireNonNull(centralReposPath, "centralReposPath");
this.header = header.orElse(null);
this.overview = overview.orElse(null);
this.features = features.orElse(null);
this.documentation = documentation.orElse(null);
this.changelog = changelog.orElse(null);
this.license = license.orElse(null);
this.bugTracker = bugTracker.orElse(null);
this.sources = sources.orElse(null);
this.cssIncludes = createUnmodifiableList(false, createSafeList(cssIncludes, true, false));
this.cssGenerateStyle = cssGenerateStyle;
this.initShim = null;
}
private MinConfiguration(MinConfiguration.Builder builder) {
this.projectName = builder.projectName;
this.projectGroupName = builder.projectGroupName;
this.projectModules = createUnmodifiableList(true, builder.projectModules);
this.release = builder.release;
this.centralReposPath = builder.centralReposPath;
this.header = builder.header;
this.overview = builder.overview;
this.features = builder.features;
this.documentation = builder.documentation;
this.changelog = builder.changelog;
this.license = builder.license;
this.bugTracker = builder.bugTracker;
this.sources = builder.sources;
if (builder.cssIncludesIsSet()) {
initShim.setCssIncludes(createUnmodifiableList(true, builder.cssIncludes));
}
if (builder.cssGenerateStyleIsSet()) {
initShim.setCssGenerateStyle(builder.cssGenerateStyle);
}
this.cssIncludes = initShim.cssIncludes();
this.cssGenerateStyle = initShim.cssGenerateStyle();
this.initShim = null;
}
private MinConfiguration(
MinConfiguration original,
String projectName,
String projectGroupName,
List projectModules,
String release,
String centralReposPath,
Path header,
Path overview,
Path features,
Path documentation,
MinChangesConfiguration changelog,
Path license,
MinBugTrackerConfiguration bugTracker,
MinSourcesConfiguration sources,
List cssIncludes,
boolean cssGenerateStyle) {
this.projectName = projectName;
this.projectGroupName = projectGroupName;
this.projectModules = projectModules;
this.release = release;
this.centralReposPath = centralReposPath;
this.header = header;
this.overview = overview;
this.features = features;
this.documentation = documentation;
this.changelog = changelog;
this.license = license;
this.bugTracker = bugTracker;
this.sources = sources;
this.cssIncludes = cssIncludes;
this.cssGenerateStyle = cssGenerateStyle;
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();
private final class InitShim {
private byte cssIncludesBuildStage = STAGE_UNINITIALIZED;
private List cssIncludes;
List cssIncludes() {
if (cssIncludesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (cssIncludesBuildStage == STAGE_UNINITIALIZED) {
cssIncludesBuildStage = STAGE_INITIALIZING;
this.cssIncludes = createUnmodifiableList(false, createSafeList(cssIncludesInitialize(), true, false));
cssIncludesBuildStage = STAGE_INITIALIZED;
}
return this.cssIncludes;
}
void setCssIncludes(List cssIncludes) {
this.cssIncludes = cssIncludes;
cssIncludesBuildStage = STAGE_INITIALIZED;
}
private byte cssGenerateStyleBuildStage = STAGE_UNINITIALIZED;
private boolean cssGenerateStyle;
boolean cssGenerateStyle() {
if (cssGenerateStyleBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (cssGenerateStyleBuildStage == STAGE_UNINITIALIZED) {
cssGenerateStyleBuildStage = STAGE_INITIALIZING;
this.cssGenerateStyle = cssGenerateStyleInitialize();
cssGenerateStyleBuildStage = STAGE_INITIALIZED;
}
return this.cssGenerateStyle;
}
void setCssGenerateStyle(boolean cssGenerateStyle) {
this.cssGenerateStyle = cssGenerateStyle;
cssGenerateStyleBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (cssIncludesBuildStage == STAGE_INITIALIZING) attributes.add("cssIncludes");
if (cssGenerateStyleBuildStage == STAGE_INITIALIZING) attributes.add("cssGenerateStyle");
return "Cannot build MinConfiguration, attribute initializers form cycle " + attributes;
}
}
private List cssIncludesInitialize() {
return MinConfigurationType.super.cssIncludes();
}
private boolean cssGenerateStyleInitialize() {
return MinConfigurationType.super.cssGenerateStyle();
}
/**
* @return The name of the project
*/
@Override
public String projectName() {
return projectName;
}
/**
* @return The group name of the project
*/
@Override
public String projectGroupName() {
return projectGroupName;
}
/**
* @return The project modules
*/
@Override
public List projectModules() {
return projectModules;
}
/**
* @return The version number of the current release
*/
@Override
public String release() {
return release;
}
/**
* @return The path to the project within the Central Repository
*/
@Override
public String centralReposPath() {
return centralReposPath;
}
/**
* @return An XHTML file containing a header inserted above the title and logo in generated sites.
*/
@Override
public Optional header() {
return Optional.ofNullable(header);
}
/**
* @return An XHTML file containing an overview of the project
*/
@Override
public Optional overview() {
return Optional.ofNullable(overview);
}
/**
* @return An XHTML file containing the features of the project
*/
@Override
public Optional features() {
return Optional.ofNullable(features);
}
/**
* @return An XHTML file containing the documentation links of the project
*/
@Override
public Optional documentation() {
return Optional.ofNullable(documentation);
}
/**
* @return The changelog configuration, if any
*/
@Override
public Optional changelog() {
return Optional.ofNullable(changelog);
}
/**
* @return A plain text file containing the project license
*/
@Override
public Optional license() {
return Optional.ofNullable(license);
}
/**
* @return The bug tracker configuration, if any
*/
@Override
public Optional bugTracker() {
return Optional.ofNullable(bugTracker);
}
/**
* @return The project source configuration, if any
*/
@Override
public Optional sources() {
return Optional.ofNullable(sources);
}
/**
* @return The list of stylesheets that will be included by the generated site
*/
@Override
public List cssIncludes() {
InitShim shim = this.initShim;
return shim != null
? shim.cssIncludes()
: this.cssIncludes;
}
/**
* @return {@code true} if the default style should be copied to the generated site directory
*/
@Override
public boolean cssGenerateStyle() {
InitShim shim = this.initShim;
return shim != null
? shim.cssGenerateStyle()
: this.cssGenerateStyle;
}
/**
* Copy the current immutable object by setting a value for the {@link MinConfigurationType#projectName() projectName} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for projectName
* @return A modified copy of the {@code this} object
*/
public final MinConfiguration withProjectName(String value) {
String newValue = Objects.requireNonNull(value, "projectName");
if (this.projectName.equals(newValue)) return this;
return new MinConfiguration(
this,
newValue,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting a value for the {@link MinConfigurationType#projectGroupName() projectGroupName} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for projectGroupName
* @return A modified copy of the {@code this} object
*/
public final MinConfiguration withProjectGroupName(String value) {
String newValue = Objects.requireNonNull(value, "projectGroupName");
if (this.projectGroupName.equals(newValue)) return this;
return new MinConfiguration(
this,
this.projectName,
newValue,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object with elements that replace the content of {@link MinConfigurationType#projectModules() projectModules}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final MinConfiguration withProjectModules(String... elements) {
List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
newValue,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object with elements that replace the content of {@link MinConfigurationType#projectModules() projectModules}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of projectModules elements to set
* @return A modified copy of {@code this} object
*/
public final MinConfiguration withProjectModules(Iterable elements) {
if (this.projectModules == elements) return this;
List newValue = createUnmodifiableList(false, createSafeList(elements, true, false));
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
newValue,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting a value for the {@link MinConfigurationType#release() release} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for release
* @return A modified copy of the {@code this} object
*/
public final MinConfiguration withRelease(String value) {
String newValue = Objects.requireNonNull(value, "release");
if (this.release.equals(newValue)) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
newValue,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting a value for the {@link MinConfigurationType#centralReposPath() centralReposPath} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for centralReposPath
* @return A modified copy of the {@code this} object
*/
public final MinConfiguration withCentralReposPath(String value) {
String newValue = Objects.requireNonNull(value, "centralReposPath");
if (this.centralReposPath.equals(newValue)) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
newValue,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link MinConfigurationType#header() header} attribute.
* @param value The value for header
* @return A modified copy of {@code this} object
*/
public final MinConfiguration withHeader(Path value) {
Path newValue = Objects.requireNonNull(value, "header");
if (this.header == newValue) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
newValue,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting an optional value for the {@link MinConfigurationType#header() header} attribute.
* A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}.
* @param optional A value for header
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final MinConfiguration withHeader(Optional extends Path> optional) {
Path value = optional.orElse(null);
if (this.header == value) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
value,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link MinConfigurationType#overview() overview} attribute.
* @param value The value for overview
* @return A modified copy of {@code this} object
*/
public final MinConfiguration withOverview(Path value) {
Path newValue = Objects.requireNonNull(value, "overview");
if (this.overview == newValue) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
newValue,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting an optional value for the {@link MinConfigurationType#overview() overview} attribute.
* A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}.
* @param optional A value for overview
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final MinConfiguration withOverview(Optional extends Path> optional) {
Path value = optional.orElse(null);
if (this.overview == value) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
value,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link MinConfigurationType#features() features} attribute.
* @param value The value for features
* @return A modified copy of {@code this} object
*/
public final MinConfiguration withFeatures(Path value) {
Path newValue = Objects.requireNonNull(value, "features");
if (this.features == newValue) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
newValue,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting an optional value for the {@link MinConfigurationType#features() features} attribute.
* A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}.
* @param optional A value for features
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final MinConfiguration withFeatures(Optional extends Path> optional) {
Path value = optional.orElse(null);
if (this.features == value) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
value,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link MinConfigurationType#documentation() documentation} attribute.
* @param value The value for documentation
* @return A modified copy of {@code this} object
*/
public final MinConfiguration withDocumentation(Path value) {
Path newValue = Objects.requireNonNull(value, "documentation");
if (this.documentation == newValue) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
newValue,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting an optional value for the {@link MinConfigurationType#documentation() documentation} attribute.
* A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}.
* @param optional A value for documentation
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final MinConfiguration withDocumentation(Optional extends Path> optional) {
Path value = optional.orElse(null);
if (this.documentation == value) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
value,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link MinConfigurationType#changelog() changelog} attribute.
* @param value The value for changelog
* @return A modified copy of {@code this} object
*/
public final MinConfiguration withChangelog(MinChangesConfiguration value) {
MinChangesConfiguration newValue = Objects.requireNonNull(value, "changelog");
if (this.changelog == newValue) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
newValue,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting an optional value for the {@link MinConfigurationType#changelog() changelog} attribute.
* A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}.
* @param optional A value for changelog
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final MinConfiguration withChangelog(Optional extends MinChangesConfiguration> optional) {
MinChangesConfiguration value = optional.orElse(null);
if (this.changelog == value) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
value,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link MinConfigurationType#license() license} attribute.
* @param value The value for license
* @return A modified copy of {@code this} object
*/
public final MinConfiguration withLicense(Path value) {
Path newValue = Objects.requireNonNull(value, "license");
if (this.license == newValue) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
newValue,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting an optional value for the {@link MinConfigurationType#license() license} attribute.
* A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}.
* @param optional A value for license
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final MinConfiguration withLicense(Optional extends Path> optional) {
Path value = optional.orElse(null);
if (this.license == value) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
value,
this.bugTracker,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link MinConfigurationType#bugTracker() bugTracker} attribute.
* @param value The value for bugTracker
* @return A modified copy of {@code this} object
*/
public final MinConfiguration withBugTracker(MinBugTrackerConfiguration value) {
MinBugTrackerConfiguration newValue = Objects.requireNonNull(value, "bugTracker");
if (this.bugTracker == newValue) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
newValue,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting an optional value for the {@link MinConfigurationType#bugTracker() bugTracker} attribute.
* A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}.
* @param optional A value for bugTracker
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final MinConfiguration withBugTracker(Optional extends MinBugTrackerConfiguration> optional) {
MinBugTrackerConfiguration value = optional.orElse(null);
if (this.bugTracker == value) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
value,
this.sources,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link MinConfigurationType#sources() sources} attribute.
* @param value The value for sources
* @return A modified copy of {@code this} object
*/
public final MinConfiguration withSources(MinSourcesConfiguration value) {
MinSourcesConfiguration newValue = Objects.requireNonNull(value, "sources");
if (this.sources == newValue) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
newValue,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting an optional value for the {@link MinConfigurationType#sources() sources} attribute.
* A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}.
* @param optional A value for sources
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final MinConfiguration withSources(Optional extends MinSourcesConfiguration> optional) {
MinSourcesConfiguration value = optional.orElse(null);
if (this.sources == value) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
value,
this.cssIncludes,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object with elements that replace the content of {@link MinConfigurationType#cssIncludes() cssIncludes}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final MinConfiguration withCssIncludes(String... elements) {
List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
newValue,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object with elements that replace the content of {@link MinConfigurationType#cssIncludes() cssIncludes}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of cssIncludes elements to set
* @return A modified copy of {@code this} object
*/
public final MinConfiguration withCssIncludes(Iterable elements) {
if (this.cssIncludes == elements) return this;
List newValue = createUnmodifiableList(false, createSafeList(elements, true, false));
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
newValue,
this.cssGenerateStyle);
}
/**
* Copy the current immutable object by setting a value for the {@link MinConfigurationType#cssGenerateStyle() cssGenerateStyle} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for cssGenerateStyle
* @return A modified copy of the {@code this} object
*/
public final MinConfiguration withCssGenerateStyle(boolean value) {
if (this.cssGenerateStyle == value) return this;
return new MinConfiguration(
this,
this.projectName,
this.projectGroupName,
this.projectModules,
this.release,
this.centralReposPath,
this.header,
this.overview,
this.features,
this.documentation,
this.changelog,
this.license,
this.bugTracker,
this.sources,
this.cssIncludes,
value);
}
/**
* This instance is equal to all instances of {@code MinConfiguration} 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 MinConfiguration
&& equalTo(0, (MinConfiguration) another);
}
private boolean equalTo(int synthetic, MinConfiguration another) {
return projectName.equals(another.projectName)
&& projectGroupName.equals(another.projectGroupName)
&& projectModules.equals(another.projectModules)
&& release.equals(another.release)
&& centralReposPath.equals(another.centralReposPath)
&& Objects.equals(header, another.header)
&& Objects.equals(overview, another.overview)
&& Objects.equals(features, another.features)
&& Objects.equals(documentation, another.documentation)
&& Objects.equals(changelog, another.changelog)
&& Objects.equals(license, another.license)
&& Objects.equals(bugTracker, another.bugTracker)
&& Objects.equals(sources, another.sources)
&& cssIncludes.equals(another.cssIncludes)
&& cssGenerateStyle == another.cssGenerateStyle;
}
/**
* Computes a hash code from attributes: {@code projectName}, {@code projectGroupName}, {@code projectModules}, {@code release}, {@code centralReposPath}, {@code header}, {@code overview}, {@code features}, {@code documentation}, {@code changelog}, {@code license}, {@code bugTracker}, {@code sources}, {@code cssIncludes}, {@code cssGenerateStyle}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + projectName.hashCode();
h += (h << 5) + projectGroupName.hashCode();
h += (h << 5) + projectModules.hashCode();
h += (h << 5) + release.hashCode();
h += (h << 5) + centralReposPath.hashCode();
h += (h << 5) + Objects.hashCode(header);
h += (h << 5) + Objects.hashCode(overview);
h += (h << 5) + Objects.hashCode(features);
h += (h << 5) + Objects.hashCode(documentation);
h += (h << 5) + Objects.hashCode(changelog);
h += (h << 5) + Objects.hashCode(license);
h += (h << 5) + Objects.hashCode(bugTracker);
h += (h << 5) + Objects.hashCode(sources);
h += (h << 5) + cssIncludes.hashCode();
h += (h << 5) + Boolean.hashCode(cssGenerateStyle);
return h;
}
/**
* Prints the immutable value {@code MinConfiguration} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("MinConfiguration{");
builder.append("projectName=").append(projectName);
builder.append(", ");
builder.append("projectGroupName=").append(projectGroupName);
builder.append(", ");
builder.append("projectModules=").append(projectModules);
builder.append(", ");
builder.append("release=").append(release);
builder.append(", ");
builder.append("centralReposPath=").append(centralReposPath);
if (header != null) {
builder.append(", ");
builder.append("header=").append(header);
}
if (overview != null) {
builder.append(", ");
builder.append("overview=").append(overview);
}
if (features != null) {
builder.append(", ");
builder.append("features=").append(features);
}
if (documentation != null) {
builder.append(", ");
builder.append("documentation=").append(documentation);
}
if (changelog != null) {
builder.append(", ");
builder.append("changelog=").append(changelog);
}
if (license != null) {
builder.append(", ");
builder.append("license=").append(license);
}
if (bugTracker != null) {
builder.append(", ");
builder.append("bugTracker=").append(bugTracker);
}
if (sources != null) {
builder.append(", ");
builder.append("sources=").append(sources);
}
builder.append(", ");
builder.append("cssIncludes=").append(cssIncludes);
builder.append(", ");
builder.append("cssGenerateStyle=").append(cssGenerateStyle);
return builder.append("}").toString();
}
/**
* Construct a new immutable {@code MinConfiguration} instance.
* @param projectName The value for the {@code projectName} attribute
* @param projectGroupName The value for the {@code projectGroupName} attribute
* @param projectModules The value for the {@code projectModules} attribute
* @param release The value for the {@code release} attribute
* @param centralReposPath The value for the {@code centralReposPath} attribute
* @param header The value for the {@code header} attribute
* @param overview The value for the {@code overview} attribute
* @param features The value for the {@code features} attribute
* @param documentation The value for the {@code documentation} attribute
* @param changelog The value for the {@code changelog} attribute
* @param license The value for the {@code license} attribute
* @param bugTracker The value for the {@code bugTracker} attribute
* @param sources The value for the {@code sources} attribute
* @param cssIncludes The value for the {@code cssIncludes} attribute
* @param cssGenerateStyle The value for the {@code cssGenerateStyle} attribute
* @return An immutable MinConfiguration instance
*/
public static MinConfiguration of(String projectName, String projectGroupName, List projectModules, String release, String centralReposPath, Optional header, Optional overview, Optional features, Optional documentation, Optional changelog, Optional license, Optional bugTracker, Optional sources, List cssIncludes, boolean cssGenerateStyle) {
return of(projectName, projectGroupName, (Iterable) projectModules, release, centralReposPath, header, overview, features, documentation, changelog, license, bugTracker, sources, (Iterable) cssIncludes, cssGenerateStyle);
}
/**
* Construct a new immutable {@code MinConfiguration} instance.
* @param projectName The value for the {@code projectName} attribute
* @param projectGroupName The value for the {@code projectGroupName} attribute
* @param projectModules The value for the {@code projectModules} attribute
* @param release The value for the {@code release} attribute
* @param centralReposPath The value for the {@code centralReposPath} attribute
* @param header The value for the {@code header} attribute
* @param overview The value for the {@code overview} attribute
* @param features The value for the {@code features} attribute
* @param documentation The value for the {@code documentation} attribute
* @param changelog The value for the {@code changelog} attribute
* @param license The value for the {@code license} attribute
* @param bugTracker The value for the {@code bugTracker} attribute
* @param sources The value for the {@code sources} attribute
* @param cssIncludes The value for the {@code cssIncludes} attribute
* @param cssGenerateStyle The value for the {@code cssGenerateStyle} attribute
* @return An immutable MinConfiguration instance
*/
public static MinConfiguration of(String projectName, String projectGroupName, Iterable projectModules, String release, String centralReposPath, Optional extends Path> header, Optional extends Path> overview, Optional extends Path> features, Optional extends Path> documentation, Optional extends MinChangesConfiguration> changelog, Optional extends Path> license, Optional extends MinBugTrackerConfiguration> bugTracker, Optional extends MinSourcesConfiguration> sources, Iterable cssIncludes, boolean cssGenerateStyle) {
return new MinConfiguration(projectName, projectGroupName, projectModules, release, centralReposPath, header, overview, features, documentation, changelog, license, bugTracker, sources, cssIncludes, cssGenerateStyle);
}
/**
* Creates an immutable copy of a {@link MinConfigurationType} 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 MinConfiguration instance
*/
public static MinConfiguration copyOf(MinConfigurationType instance) {
if (instance instanceof MinConfiguration) {
return (MinConfiguration) instance;
}
return MinConfiguration.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link MinConfiguration MinConfiguration}.
*
* MinConfiguration.builder()
* .setProjectName(String) // required {@link MinConfigurationType#projectName() projectName}
* .setProjectGroupName(String) // required {@link MinConfigurationType#projectGroupName() projectGroupName}
* .addProjectModules|addAllProjectModules(String) // {@link MinConfigurationType#projectModules() projectModules} elements
* .setRelease(String) // required {@link MinConfigurationType#release() release}
* .setCentralReposPath(String) // required {@link MinConfigurationType#centralReposPath() centralReposPath}
* .setHeader(java.nio.file.Path) // optional {@link MinConfigurationType#header() header}
* .setOverview(java.nio.file.Path) // optional {@link MinConfigurationType#overview() overview}
* .setFeatures(java.nio.file.Path) // optional {@link MinConfigurationType#features() features}
* .setDocumentation(java.nio.file.Path) // optional {@link MinConfigurationType#documentation() documentation}
* .setChangelog(MinChangesConfiguration) // optional {@link MinConfigurationType#changelog() changelog}
* .setLicense(java.nio.file.Path) // optional {@link MinConfigurationType#license() license}
* .setBugTracker(MinBugTrackerConfiguration) // optional {@link MinConfigurationType#bugTracker() bugTracker}
* .setSources(MinSourcesConfiguration) // optional {@link MinConfigurationType#sources() sources}
* .addCssIncludes|addAllCssIncludes(String) // {@link MinConfigurationType#cssIncludes() cssIncludes} elements
* .setCssGenerateStyle(boolean) // optional {@link MinConfigurationType#cssGenerateStyle() cssGenerateStyle}
* .build();
*
* @return A new MinConfiguration builder
*/
public static MinConfiguration.Builder builder() {
return new MinConfiguration.Builder();
}
/**
* Builds instances of type {@link MinConfiguration MinConfiguration}.
* 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_PROJECT_NAME = 0x1L;
private static final long INIT_BIT_PROJECT_GROUP_NAME = 0x2L;
private static final long INIT_BIT_RELEASE = 0x4L;
private static final long INIT_BIT_CENTRAL_REPOS_PATH = 0x8L;
private static final long OPT_BIT_CSS_INCLUDES = 0x1L;
private static final long OPT_BIT_CSS_GENERATE_STYLE = 0x2L;
private long initBits = 0xfL;
private long optBits;
private String projectName;
private String projectGroupName;
private List projectModules = new ArrayList();
private String release;
private String centralReposPath;
private Path header;
private Path overview;
private Path features;
private Path documentation;
private MinChangesConfiguration changelog;
private Path license;
private MinBugTrackerConfiguration bugTracker;
private MinSourcesConfiguration sources;
private List cssIncludes = new ArrayList();
private boolean cssGenerateStyle;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code MinConfigurationType} 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
*/
public final Builder from(MinConfigurationType instance) {
Objects.requireNonNull(instance, "instance");
this.setProjectName(instance.projectName());
this.setProjectGroupName(instance.projectGroupName());
addAllProjectModules(instance.projectModules());
this.setRelease(instance.release());
this.setCentralReposPath(instance.centralReposPath());
Optional headerOptional = instance.header();
if (headerOptional.isPresent()) {
setHeader(headerOptional);
}
Optional overviewOptional = instance.overview();
if (overviewOptional.isPresent()) {
setOverview(overviewOptional);
}
Optional featuresOptional = instance.features();
if (featuresOptional.isPresent()) {
setFeatures(featuresOptional);
}
Optional documentationOptional = instance.documentation();
if (documentationOptional.isPresent()) {
setDocumentation(documentationOptional);
}
Optional changelogOptional = instance.changelog();
if (changelogOptional.isPresent()) {
setChangelog(changelogOptional);
}
Optional licenseOptional = instance.license();
if (licenseOptional.isPresent()) {
setLicense(licenseOptional);
}
Optional bugTrackerOptional = instance.bugTracker();
if (bugTrackerOptional.isPresent()) {
setBugTracker(bugTrackerOptional);
}
Optional sourcesOptional = instance.sources();
if (sourcesOptional.isPresent()) {
setSources(sourcesOptional);
}
addAllCssIncludes(instance.cssIncludes());
this.setCssGenerateStyle(instance.cssGenerateStyle());
return this;
}
/**
* Initializes the value for the {@link MinConfigurationType#projectName() projectName} attribute.
* @param projectName The value for projectName
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setProjectName(String projectName) {
this.projectName = Objects.requireNonNull(projectName, "projectName");
initBits &= ~INIT_BIT_PROJECT_NAME;
return this;
}
/**
* Initializes the value for the {@link MinConfigurationType#projectGroupName() projectGroupName} attribute.
* @param projectGroupName The value for projectGroupName
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setProjectGroupName(String projectGroupName) {
this.projectGroupName = Objects.requireNonNull(projectGroupName, "projectGroupName");
initBits &= ~INIT_BIT_PROJECT_GROUP_NAME;
return this;
}
/**
* Adds one element to {@link MinConfigurationType#projectModules() projectModules} list.
* @param element A projectModules element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addProjectModules(String element) {
this.projectModules.add(Objects.requireNonNull(element, "projectModules element"));
return this;
}
/**
* Adds elements to {@link MinConfigurationType#projectModules() projectModules} list.
* @param elements An array of projectModules elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addProjectModules(String... elements) {
for (String element : elements) {
this.projectModules.add(Objects.requireNonNull(element, "projectModules element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link MinConfigurationType#projectModules() projectModules} list.
* @param elements An iterable of projectModules elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setProjectModules(Iterable elements) {
this.projectModules.clear();
return addAllProjectModules(elements);
}
/**
* Adds elements to {@link MinConfigurationType#projectModules() projectModules} list.
* @param elements An iterable of projectModules elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllProjectModules(Iterable elements) {
for (String element : elements) {
this.projectModules.add(Objects.requireNonNull(element, "projectModules element"));
}
return this;
}
/**
* Initializes the value for the {@link MinConfigurationType#release() release} attribute.
* @param release The value for release
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setRelease(String release) {
this.release = Objects.requireNonNull(release, "release");
initBits &= ~INIT_BIT_RELEASE;
return this;
}
/**
* Initializes the value for the {@link MinConfigurationType#centralReposPath() centralReposPath} attribute.
* @param centralReposPath The value for centralReposPath
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setCentralReposPath(String centralReposPath) {
this.centralReposPath = Objects.requireNonNull(centralReposPath, "centralReposPath");
initBits &= ~INIT_BIT_CENTRAL_REPOS_PATH;
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#header() header} to header.
* @param header The value for header
* @return {@code this} builder for chained invocation
*/
public final Builder setHeader(Path header) {
this.header = Objects.requireNonNull(header, "header");
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#header() header} to header.
* @param header The value for header
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setHeader(Optional extends Path> header) {
this.header = header.orElse(null);
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#overview() overview} to overview.
* @param overview The value for overview
* @return {@code this} builder for chained invocation
*/
public final Builder setOverview(Path overview) {
this.overview = Objects.requireNonNull(overview, "overview");
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#overview() overview} to overview.
* @param overview The value for overview
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setOverview(Optional extends Path> overview) {
this.overview = overview.orElse(null);
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#features() features} to features.
* @param features The value for features
* @return {@code this} builder for chained invocation
*/
public final Builder setFeatures(Path features) {
this.features = Objects.requireNonNull(features, "features");
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#features() features} to features.
* @param features The value for features
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setFeatures(Optional extends Path> features) {
this.features = features.orElse(null);
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#documentation() documentation} to documentation.
* @param documentation The value for documentation
* @return {@code this} builder for chained invocation
*/
public final Builder setDocumentation(Path documentation) {
this.documentation = Objects.requireNonNull(documentation, "documentation");
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#documentation() documentation} to documentation.
* @param documentation The value for documentation
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setDocumentation(Optional extends Path> documentation) {
this.documentation = documentation.orElse(null);
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#changelog() changelog} to changelog.
* @param changelog The value for changelog
* @return {@code this} builder for chained invocation
*/
public final Builder setChangelog(MinChangesConfiguration changelog) {
this.changelog = Objects.requireNonNull(changelog, "changelog");
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#changelog() changelog} to changelog.
* @param changelog The value for changelog
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setChangelog(Optional extends MinChangesConfiguration> changelog) {
this.changelog = changelog.orElse(null);
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#license() license} to license.
* @param license The value for license
* @return {@code this} builder for chained invocation
*/
public final Builder setLicense(Path license) {
this.license = Objects.requireNonNull(license, "license");
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#license() license} to license.
* @param license The value for license
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setLicense(Optional extends Path> license) {
this.license = license.orElse(null);
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#bugTracker() bugTracker} to bugTracker.
* @param bugTracker The value for bugTracker
* @return {@code this} builder for chained invocation
*/
public final Builder setBugTracker(MinBugTrackerConfiguration bugTracker) {
this.bugTracker = Objects.requireNonNull(bugTracker, "bugTracker");
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#bugTracker() bugTracker} to bugTracker.
* @param bugTracker The value for bugTracker
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setBugTracker(Optional extends MinBugTrackerConfiguration> bugTracker) {
this.bugTracker = bugTracker.orElse(null);
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#sources() sources} to sources.
* @param sources The value for sources
* @return {@code this} builder for chained invocation
*/
public final Builder setSources(MinSourcesConfiguration sources) {
this.sources = Objects.requireNonNull(sources, "sources");
return this;
}
/**
* Initializes the optional value {@link MinConfigurationType#sources() sources} to sources.
* @param sources The value for sources
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setSources(Optional extends MinSourcesConfiguration> sources) {
this.sources = sources.orElse(null);
return this;
}
/**
* Adds one element to {@link MinConfigurationType#cssIncludes() cssIncludes} list.
* @param element A cssIncludes element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addCssIncludes(String element) {
this.cssIncludes.add(Objects.requireNonNull(element, "cssIncludes element"));
optBits |= OPT_BIT_CSS_INCLUDES;
return this;
}
/**
* Adds elements to {@link MinConfigurationType#cssIncludes() cssIncludes} list.
* @param elements An array of cssIncludes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addCssIncludes(String... elements) {
for (String element : elements) {
this.cssIncludes.add(Objects.requireNonNull(element, "cssIncludes element"));
}
optBits |= OPT_BIT_CSS_INCLUDES;
return this;
}
/**
* Sets or replaces all elements for {@link MinConfigurationType#cssIncludes() cssIncludes} list.
* @param elements An iterable of cssIncludes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setCssIncludes(Iterable elements) {
this.cssIncludes.clear();
return addAllCssIncludes(elements);
}
/**
* Adds elements to {@link MinConfigurationType#cssIncludes() cssIncludes} list.
* @param elements An iterable of cssIncludes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllCssIncludes(Iterable elements) {
for (String element : elements) {
this.cssIncludes.add(Objects.requireNonNull(element, "cssIncludes element"));
}
optBits |= OPT_BIT_CSS_INCLUDES;
return this;
}
/**
* Initializes the value for the {@link MinConfigurationType#cssGenerateStyle() cssGenerateStyle} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link MinConfigurationType#cssGenerateStyle() cssGenerateStyle}.
* @param cssGenerateStyle The value for cssGenerateStyle
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setCssGenerateStyle(boolean cssGenerateStyle) {
this.cssGenerateStyle = cssGenerateStyle;
optBits |= OPT_BIT_CSS_GENERATE_STYLE;
return this;
}
/**
* Builds a new {@link MinConfiguration MinConfiguration}.
* @return An immutable instance of MinConfiguration
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public MinConfiguration build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new MinConfiguration(this);
}
private boolean cssIncludesIsSet() {
return (optBits & OPT_BIT_CSS_INCLUDES) != 0;
}
private boolean cssGenerateStyleIsSet() {
return (optBits & OPT_BIT_CSS_GENERATE_STYLE) != 0;
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_PROJECT_NAME) != 0) attributes.add("projectName");
if ((initBits & INIT_BIT_PROJECT_GROUP_NAME) != 0) attributes.add("projectGroupName");
if ((initBits & INIT_BIT_RELEASE) != 0) attributes.add("release");
if ((initBits & INIT_BIT_CENTRAL_REPOS_PATH) != 0) attributes.add("centralReposPath");
return "Cannot build MinConfiguration, some of required attributes are not set " + attributes;
}
}
private static List createSafeList(Iterable extends T> iterable, boolean checkNulls, boolean skipNulls) {
ArrayList list;
if (iterable instanceof Collection>) {
int size = ((Collection>) iterable).size();
if (size == 0) return Collections.emptyList();
list = new ArrayList<>(size);
} else {
list = new ArrayList<>();
}
for (T element : iterable) {
if (skipNulls && element == null) continue;
if (checkNulls) Objects.requireNonNull(element, "element");
list.add(element);
}
return list;
}
private static List createUnmodifiableList(boolean clone, List list) {
switch(list.size()) {
case 0: return Collections.emptyList();
case 1: return Collections.singletonList(list.get(0));
default:
if (clone) {
return Collections.unmodifiableList(new ArrayList<>(list));
} else {
if (list instanceof ArrayList>) {
((ArrayList>) list).trimToSize();
}
return Collections.unmodifiableList(list);
}
}
}
}