1 /*
2 * Copyright (C) 2019 sw4j.org
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 package org.sw4j.tool.barcode.random.config;
18
19 import com.fasterxml.jackson.annotation.JsonCreator;
20 import com.fasterxml.jackson.annotation.JsonProperty;
21
22 /**
23 * <p>
24 * This class configures the output file(s).
25 * </p>
26 * <p>
27 * To create a new instance programmatically use the
28 * {@link org.sw4j.tool.barcode.random.config.OutputConfig.Builder Builder} which can be obtained by the method
29 * {@link #builder()}.
30 * </p>
31 * <p>
32 * This class is immutable.
33 * </p>
34 * @author Uwe Plonus <u.plonus@gmail.com>
35 */
36 public class OutputConfig {
37
38 /**
39 * <p>
40 * The folder for the output files.
41 * </p>
42 */
43 private final String folder;
44
45 /**
46 * <p>
47 * The output file for the output csv file.
48 * </p>
49 */
50 private final FileConfig file;
51
52 /**
53 * <p>
54 * Create a new {@code OutputConfig} with the given file name.
55 * </p>
56 * <p>
57 * This constructor is annotated so that a YAML or JSON parsed with jackson fasterxml can create an instance
58 * directly.
59 * </p>
60 * @param folder the name of the file configuration.
61 * @param file the name of the output csv file.
62 * @throws IllegalArgumentException if either {@code folder} or {@code file} is {@code null}.
63 */
64 @JsonCreator
65 public OutputConfig(
66 @JsonProperty("folder") final String folder,
67 @JsonProperty("file") final FileConfig file) {
68 if (folder == null) {
69 throw new IllegalArgumentException(String.format("%s: Missing folder", getClass().getSimpleName()));
70 }
71 if (file == null) {
72 throw new IllegalArgumentException(String.format("%s: Missing file", getClass().getSimpleName()));
73 }
74 this.folder = folder;
75 this.file = file;
76 }
77
78 /**
79 * <p>
80 * Return the folder of the output files.
81 * </p>
82 * @return the folder of the output files.
83 */
84 public String getFolder() {
85 return folder;
86 }
87
88 /**
89 * <p>
90 * Return the output csv file.
91 * </p>
92 * @return the output csv file.
93 */
94 public FileConfig getFile() {
95 return file;
96 }
97
98 /**
99 * <p>
100 * Return a {@link org.sw4j.tool.barcode.random.config.OutputConfig.Builder Builder} that can be used to build a
101 * config.
102 * </p>
103 * @return a {@link org.sw4j.tool.barcode.random.config.OutputConfig.Builder Builder}.
104 */
105 public static Builder builder() {
106 return new Builder();
107 }
108
109
110 /**
111 * <p>
112 * This class is a Builder to build a {@link org.sw4j.tool.barcode.random.config.OutputConfig OutputConfig}
113 * programmatically. All methods to set the values are fluent to ease the building of a configuration.
114 * </p>
115 * <p>
116 * This class is not thread save.
117 * </p>
118 * @author Uwe Plonus <u.plonus@gmail.com>
119 */
120 public static class Builder {
121
122 /**
123 * <p>
124 * The folder for the output files.
125 * </p>
126 */
127 private String folder;
128
129 /**
130 * <p>
131 * The file of the csv output.
132 * </p>
133 */
134 private FileConfig file;
135
136 /**
137 * <p>
138 * Create a new {@code Builder}.
139 * </p>
140 */
141 public Builder() {
142 }
143
144 /**
145 * <p>
146 * Set the folder of the output files.
147 * </p>
148 * @param folder the folder of the output files.
149 * @return the builder for a fluent interface.
150 */
151 public Builder setFolder(final String folder) {
152 this.folder = folder;
153 return this;
154 }
155
156 /**
157 * <p>
158 * Set the file of the output csv file.
159 * </p>
160 * @param file the file of the output csv file.
161 * @return the builder for a fluent interface.
162 */
163 public Builder setFile(final FileConfig file) {
164 this.file = file;
165 return this;
166 }
167
168 /**
169 * <p>
170 * Build a new {@link org.sw4j.tool.barcode.random.config.OutputConfig OutputConfig} with the parameters set.
171 * </p>
172 * @return the new created {@link org.sw4j.tool.barcode.random.config.OutputConfig OutputConfig}.
173 * @throws IllegalArgumentException if either {@code folder} or {@code file} is {@code null}.
174 */
175 public OutputConfig build() {
176 return new OutputConfig(folder, file);
177 }
178
179 }
180
181 }