FileConfig.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 a file.
* </p>
* <p>
* To create a new instance programmatically use the
* {@link org.sw4j.tool.barcode.random.config.FileConfig.Builder Builder} which can be obtained by the method
* {@link #builder()}.
* </p>
* <p>
* This class is immutable.
* </p>
* @author Uwe Plonus <u.plonus@gmail.com>
*/
public class FileConfig {
/**
* <p>
* The name of the file.
* </p>
*/
private final String name;
/**
* <p>
* Create a new {@code FileConfig} 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 name the name of the file configuration.
* @throws IllegalArgumentException if {@code name} is {@code null}.
*/
@JsonCreator
public FileConfig(@JsonProperty("name") final String name) {
if (name == null || "".equals(name.trim())) {
throw new IllegalArgumentException(String.format("%s: Missing name", getClass().getSimpleName()));
}
this.name = name;
}
/**
* <p>
* The name of the file configured.
* </p>
* @return the name of the file.
*/
public String getName() {
return name;
}
/**
* <p>
* Return a {@link org.sw4j.tool.barcode.random.config.FileConfig.Builder Builder} that can be used to build a
* config.
* </p>
* @return a {@link org.sw4j.tool.barcode.random.config.FileConfig.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.FileConfig FileConfig}
* 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 <u.plonus@gmail.com>
*/
public static class Builder {
/**
* <p>
* The name of the file.
* </p>
*/
private String name;
/**
* <p>
* Create a new {@code Builder}.
* </p>
*/
public Builder() {
}
/**
* <p>
* Set the name of the file.
* </p>
* @param name the name of the file.
* @return the builder for a fluent interface.
*/
public Builder setName(final String name) {
this.name = name;
return this;
}
/**
* <p>
* Build a new {@link org.sw4j.tool.barcode.random.config.FileConfig FileConfig} with the parameters set.
* </p>
* @return the new created {@link org.sw4j.tool.barcode.random.config.FileConfig FileConfig}.
* @throws IllegalArgumentException if {@code name} is {@code null}.
*/
public FileConfig build() {
return new FileConfig(name);
}
}
}