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 a file.
25 * </p>
26 * <p>
27 * To create a new instance programmatically use the
28 * {@link org.sw4j.tool.barcode.random.config.FileConfig.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 FileConfig {
37
38 /**
39 * <p>
40 * The name of the file.
41 * </p>
42 */
43 private final String name;
44
45 /**
46 * <p>
47 * Create a new {@code FileConfig} with the given file name.
48 * </p>
49 * <p>
50 * This constructor is annotated so that a YAML or JSON parsed with jackson fasterxml can create an instance
51 * directly.
52 * </p>
53 * @param name the name of the file configuration.
54 * @throws IllegalArgumentException if {@code name} is {@code null}.
55 */
56 @JsonCreator
57 public FileConfig(@JsonProperty("name") final String name) {
58 if (name == null || "".equals(name.trim())) {
59 throw new IllegalArgumentException(String.format("%s: Missing name", getClass().getSimpleName()));
60 }
61 this.name = name;
62 }
63
64 /**
65 * <p>
66 * The name of the file configured.
67 * </p>
68 * @return the name of the file.
69 */
70 public String getName() {
71 return name;
72 }
73
74 /**
75 * <p>
76 * Return a {@link org.sw4j.tool.barcode.random.config.FileConfig.Builder Builder} that can be used to build a
77 * config.
78 * </p>
79 * @return a {@link org.sw4j.tool.barcode.random.config.FileConfig.Builder Builder}.
80 */
81 public static Builder builder() {
82 return new Builder();
83 }
84
85
86 /**
87 * <p>
88 * This class is a Builder to build a {@link org.sw4j.tool.barcode.random.config.FileConfig FileConfig}
89 * programmatically. All methods to set the values are fluent to ease the building of a configuration.
90 * </p>
91 * <p>
92 * This class is not thread save.
93 * </p>
94 * @author Uwe Plonus <u.plonus@gmail.com>
95 */
96 public static class Builder {
97
98 /**
99 * <p>
100 * The name of the file.
101 * </p>
102 */
103 private String name;
104
105 /**
106 * <p>
107 * Create a new {@code Builder}.
108 * </p>
109 */
110 public Builder() {
111 }
112
113 /**
114 * <p>
115 * Set the name of the file.
116 * </p>
117 * @param name the name of the file.
118 * @return the builder for a fluent interface.
119 */
120 public Builder setName(final String name) {
121 this.name = name;
122 return this;
123 }
124
125 /**
126 * <p>
127 * Build a new {@link org.sw4j.tool.barcode.random.config.FileConfig FileConfig} with the parameters set.
128 * </p>
129 * @return the new created {@link org.sw4j.tool.barcode.random.config.FileConfig FileConfig}.
130 * @throws IllegalArgumentException if {@code name} is {@code null}.
131 */
132 public FileConfig build() {
133 return new FileConfig(name);
134 }
135
136 }
137
138 }