OutputConfig.java

/*
 * Copyright (C) 2019 sw4j.org
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.sw4j.tool.barcode.random.config;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * <p>
 * This class configures the output file(s).
 * </p>
 * <p>
 * To create a new instance programmatically use the
 * {@link org.sw4j.tool.barcode.random.config.OutputConfig.Builder Builder} which can be obtained by the method
 * {@link #builder()}.
 * </p>
 * <p>
 * This class is immutable.
 * </p>
 * @author Uwe Plonus &lt;u.plonus@gmail.com&gt;
 */
public class OutputConfig {

    /**
     * <p>
     * The folder for the output files.
     * </p>
     */
    private final String folder;

    /**
     * <p>
     * The output file for the output csv file.
     * </p>
     */
    private final FileConfig file;

    /**
     * <p>
     * Create a new {@code OutputConfig} with the given file name.
     * </p>
     * <p>
     * This constructor is annotated so that a YAML or JSON parsed with jackson fasterxml can create an instance
     * directly.
     * </p>
     * @param folder the name of the file configuration.
     * @param file the name of the output csv file.
     * @throws IllegalArgumentException if either {@code folder} or {@code file} is {@code null}.
     */
    @JsonCreator
    public OutputConfig(
            @JsonProperty("folder") final String folder,
            @JsonProperty("file") final FileConfig file) {
        if (folder == null) {
            throw new IllegalArgumentException(String.format("%s: Missing folder", getClass().getSimpleName()));
        }
        if (file == null) {
            throw new IllegalArgumentException(String.format("%s: Missing file", getClass().getSimpleName()));
        }
        this.folder = folder;
        this.file = file;
    }

    /**
     * <p>
     * Return the folder of the output files.
     * </p>
     * @return the folder of the output files.
     */
    public String getFolder() {
        return folder;
    }

    /**
     * <p>
     * Return the output csv file.
     * </p>
     * @return the output csv file.
     */
    public FileConfig getFile() {
        return file;
    }

    /**
     * <p>
     * Return a {@link org.sw4j.tool.barcode.random.config.OutputConfig.Builder Builder} that can be used to build a
     * config.
     * </p>
     * @return a {@link org.sw4j.tool.barcode.random.config.OutputConfig.Builder Builder}.
     */
    public static Builder builder() {
        return new Builder();
    }


    /**
     * <p>
     * This class is a Builder to build a {@link org.sw4j.tool.barcode.random.config.OutputConfig OutputConfig}
     * programmatically. All methods to set the values are fluent to ease the building of a configuration.
     * </p>
     * <p>
     * This class is not thread save.
     * </p>
     * @author Uwe Plonus &lt;u.plonus@gmail.com&gt;
     */
    public static class Builder {

        /**
         * <p>
         * The folder for the output files.
         * </p>
         */
        private String folder;

        /**
         * <p>
         * The file of the csv output.
         * </p>
         */
        private FileConfig file;

        /**
         * <p>
         * Create a new {@code Builder}.
         * </p>
         */
        public Builder() {
        }

        /**
         * <p>
         * Set the folder of the output files.
         * </p>
         * @param folder the folder of the output files.
         * @return the builder for a fluent interface.
         */
        public Builder setFolder(final String folder) {
            this.folder = folder;
            return this;
        }

        /**
         * <p>
         * Set the file of the output csv file.
         * </p>
         * @param file the file of the output csv file.
         * @return the builder for a fluent interface.
         */
        public Builder setFile(final FileConfig file) {
            this.file = file;
            return this;
        }

        /**
         * <p>
         * Build a new {@link org.sw4j.tool.barcode.random.config.OutputConfig OutputConfig} with the parameters set.
         * </p>
         * @return the new created {@link org.sw4j.tool.barcode.random.config.OutputConfig OutputConfig}.
         * @throws IllegalArgumentException if either {@code folder} or {@code file} is {@code null}.
         */
        public OutputConfig build() {
            return new OutputConfig(folder, file);
        }

    }

}