public class CodeConfig extends Object
This class configures a concrete code to generate. A code is determined by the encoding (e.g. hex), the file type
(e.g. png), the url (or text) with {code}
as placeholder for the random code, and the barcode parameters
(type, width, height and error correction).
To create a new instance programmatically use the
Builder
which can be obtained with the method
builder()
.
Supported barcode types:
Supported file types: All types supported by Image IO.
This class is immutable.
Modifier and Type | Class and Description |
---|---|
static class |
CodeConfig.Builder
This class is a Builder to build a
CodeConfig
programmatically. |
Constructor and Description |
---|
CodeConfig(String type,
String size,
String errorCorrection,
String filetype,
EncodingConfig encoding,
String url)
Create a new
CodeConfig object with the given parameters. |
Modifier and Type | Method and Description |
---|---|
static CodeConfig.Builder |
builder()
Return a
Builder that can be used to build a
config. |
EncodingConfig |
getEncoding()
Return the encoding of the random number in the barcode.
|
String |
getErrorCorrection()
Return the error correction of the barcode.
|
String |
getFiletype()
Return the file type of the barcode.
|
int |
getHeight()
Return the height of the barcode.
|
CodeType |
getType()
Return the type of the barcode (e.g.
|
String |
getUrl()
Return the URL (or text) of the barcode with the placeholder
{code} replaced by the encoded random
number. |
int |
getWidth()
Return the width of the barcode.
|
public CodeConfig(String type, String size, String errorCorrection, String filetype, EncodingConfig encoding, String url)
Create a new CodeConfig
object with the given parameters.
If the size cannot be parsed then the default size will be used.
This constructor is annotated so that a YAML or JSON parsed with jackson fasterxml can create an instance directly.
type
- the type of the barcode to create (e.g. qrcode). May not be null.size
- the size of the barcode, given in the format "(width)x(height)", e.g. 120x150 for with 120 and height
150. If only a single number is given a square with the given number as width and height is configured.errorCorrection
- the error correction of the barcode (if applicable), e.g. "M" for QRCode.filetype
- the file type for the final barcode image.encoding
- the encoding to use for encoding the random number. May not be null.url
- the URL (or text) to encode in the barcode.IllegalArgumentException
- if either type
or encoding
is null
or the type
is unknown.public CodeType getType()
Return the type of the barcode (e.g. qrcode).
null
.public int getWidth()
Return the width of the barcode. Defaults to 200.
public int getHeight()
Return the height of the barcode. Defaults to 200.
public String getErrorCorrection()
Return the error correction of the barcode. May be null
or empty.
public String getFiletype()
Return the file type of the barcode. Defaults to png.
public EncodingConfig getEncoding()
Return the encoding of the random number in the barcode. Is never null
.
public String getUrl()
Return the URL (or text) of the barcode with the placeholder {code}
replaced by the encoded random
number.
public static CodeConfig.Builder builder()
Return a Builder
that can be used to build a
config.
Builder
.Copyright © 2020 sw4j.org. All rights reserved.