public final class UrlBuilder extends Object
Default values:
Modifier and Type | Field and Description |
---|---|
static int |
CHANCE_IN_PARAM_VALUE_AS_STRING
Represents the
in value for the chance method |
static int |
CHANCE_OF_PARAM_VALUE_AS_STRING
Represents the chance of generating a string value for a query param
|
static String |
COUNTRY_TOP_LEVEL_DOMAIN_KEY
Points to a list of country top level domains
|
static int |
DEFAULT_PORT
Default port value (must be compatible with the URL class)
|
static String |
DEFAULT_TOP_LEVEL_DOMAIN_KEY
Points to a list of possible top level domains
|
static String |
GENERIC_TOP_LEVEL_DOMAIN_KEY
Points to a list of generic top level domains
|
static int |
MAX_PORT
Upper boundary for randomly generated url port
|
static int |
MIN_PORT
Lower boundary for randomly generated url port
|
static String |
PARAM_KEY
Points to a list of random words that are used as parameter names
|
static String |
PARAM_VALUE_KEY
Points to a list of random words that are used as parameter values
|
static String |
POPULAR_TOP_LEVEL_DOMAIN_KEY
Points to a list of popular top level domains
|
static String |
ROOT_DOMAIN_KEY
Points to a list of random words that are used as domains
|
Constructor and Description |
---|
UrlBuilder(Dummy4j dummy4j) |
Modifier and Type | Method and Description |
---|---|
URL |
build()
Returns a URL instance
|
UrlBuilder |
minLength(int minLength)
The generated url will be expanded with random characters until it is
minLength characters long. |
String |
toString() |
UrlBuilder |
withCountryTopLevelDomain()
Chooses a top level domain at random from a list of country domains.
|
UrlBuilder |
withFilePath()
Adds a file name constructed from 10 random characters with the
.html extension |
UrlBuilder |
withGenericTopLevelDomain()
Chooses a top level domain at random from a list of generic domains.
|
UrlBuilder |
withoutWwwPrefix()
Removes the
www prefix from the generated url |
UrlBuilder |
withPopularTopLevelDomain()
Chooses a top level domain at random from a list of popular domains.
|
UrlBuilder |
withPort(int port)
Sets the port for the generated url.
|
UrlBuilder |
withProtocol(UrlProtocol protocol)
Sets the protocol for the generated url
|
UrlBuilder |
withQueryParam()
Adds one query param with a randomly generated value that will be either numeric or alphabetical
|
UrlBuilder |
withQueryParams(int howManyParams)
Adds the specified amount of query params with randomly generated values that will be either
numeric or alphabetical.
|
UrlBuilder |
withRandomPort()
Sets the port to a random 4-digit
int value |
UrlBuilder |
withRandomProtocol(UrlProtocol... protocols)
Sets the protocol for the generated url to one that is randomly chosen from provided arguments.
|
UrlBuilder |
withTopLevelDomain(String domain)
Sets the top level domain for the generated url
|
public static final int MIN_PORT
public static final int MAX_PORT
public static final int DEFAULT_PORT
public static final String DEFAULT_TOP_LEVEL_DOMAIN_KEY
public static final String POPULAR_TOP_LEVEL_DOMAIN_KEY
public static final String COUNTRY_TOP_LEVEL_DOMAIN_KEY
public static final String GENERIC_TOP_LEVEL_DOMAIN_KEY
public static final String ROOT_DOMAIN_KEY
public static final String PARAM_KEY
public static final String PARAM_VALUE_KEY
public static final int CHANCE_OF_PARAM_VALUE_AS_STRING
public static final int CHANCE_IN_PARAM_VALUE_AS_STRING
in
value for the chance methodpublic UrlBuilder(Dummy4j dummy4j)
public UrlBuilder withProtocol(UrlProtocol protocol)
public UrlBuilder withRandomProtocol(UrlProtocol... protocols)
UrlProtocol
enum.public UrlBuilder withoutWwwPrefix()
www
prefix from the generated urlpublic UrlBuilder withPort(int port)
Default value is -1
which means no port will be present in the generated url.
The port must be greater than -1
.
public UrlBuilder withRandomPort()
int
valuepublic UrlBuilder withFilePath()
.html
extensionpublic UrlBuilder withQueryParam()
public UrlBuilder withQueryParams(int howManyParams)
IllegalArgumentException
- when a negative number is given as the argumentpublic UrlBuilder withTopLevelDomain(String domain)
public UrlBuilder withPopularTopLevelDomain()
E.g. com, dev, io, org
.
public UrlBuilder withCountryTopLevelDomain()
E.g. es, uk, it
.
public UrlBuilder withGenericTopLevelDomain()
E.g. academy, photography, tech
.
public UrlBuilder minLength(int minLength)
minLength
characters long.
Random characters will be added to a domain, a filename or the value of the last query param – depending on which elements are included in the generated url.
In case the generated url is already at least minLength
characters long no characters will be added.
public URL build()
UrlCouldNotBeCreatedException
- if the url can't be createdURL
Copyright © 2020. All rights reserved.