Class PathGenerator
java.lang.Object
org.instancio.internal.generator.AbstractGenerator<Path>
org.instancio.internal.generator.nio.file.PathGenerator
- All Implemented Interfaces:
AsStringGeneratorSpec<Path>,Generator<Path>,GeneratorSpec<Path>,AsGeneratorSpec<Path>,FilePathSpec<Path>,NullableGeneratorSpec<Path>,PathAsGeneratorSpec<Path>,PathGeneratorSpec<Path>,PathSpec,ValueSpec<Path>
public class PathGenerator
extends AbstractGenerator<Path>
implements PathSpec, PathAsGeneratorSpec<Path>
-
Constructor Summary
ConstructorsConstructorDescriptionPathGenerator(GeneratorContext context) PathGenerator(GeneratorContext context, String... directories) -
Method Summary
Modifier and TypeMethodDescriptionReturns the public API method name of the generator spec.Terminal method to indicate that the generated path, including parent directories (if any), should be created as a directory in the file system.Terminal method to indicate that the generated path, including parent directories (if any), should be created as a file in the file system.createFile(InputStream content) Terminal method to indicate that the generated path, including parent directories (if any), should be created as a file in the file system and content provided by the input stream written to the file.Generator for the file or directory name.nullable()Indicates thatnullvalue can be generated.File or directory name prefix.File or directory name suffix.tmp()Generate path withjava.io.tmpdiras the parent directory.tryGenerateNonNull(Random random) Makes the best effort to return a non-null value.Methods inherited from class org.instancio.internal.generator.AbstractGenerator
generate, getContext, hints, isNullable, nullableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.instancio.generator.specs.AsGeneratorSpec
as, asStringMethods inherited from interface org.instancio.generator.AsStringGeneratorSpec
asString
-
Constructor Details
-
PathGenerator
public PathGenerator() -
PathGenerator
-
PathGenerator
-
-
Method Details
-
apiMethod
Description copied from class:AbstractGeneratorReturns the public API method name of the generator spec. The returned name is used for reporting validation errors.- Specified by:
apiMethodin classAbstractGenerator<Path>- Returns:
- spec name if defined, or
nullotherwise
-
tmp
Description copied from interface:PathGeneratorSpecGenerate path withjava.io.tmpdiras the parent directory.- Specified by:
tmpin interfaceFilePathSpec<Path>- Specified by:
tmpin interfacePathAsGeneratorSpec<Path>- Specified by:
tmpin interfacePathGeneratorSpec<Path>- Specified by:
tmpin interfacePathSpec- Returns:
- spec builder
-
prefix
Description copied from interface:PathGeneratorSpecFile or directory name prefix. No prefix is added by default.- Specified by:
prefixin interfaceFilePathSpec<Path>- Specified by:
prefixin interfacePathAsGeneratorSpec<Path>- Specified by:
prefixin interfacePathGeneratorSpec<Path>- Specified by:
prefixin interfacePathSpec- Parameters:
prefix- to add to the file or directory name- Returns:
- spec builder
-
suffix
Description copied from interface:PathGeneratorSpecFile or directory name suffix. No suffix is added by default.- Specified by:
suffixin interfaceFilePathSpec<Path>- Specified by:
suffixin interfacePathAsGeneratorSpec<Path>- Specified by:
suffixin interfacePathGeneratorSpec<Path>- Specified by:
suffixin interfacePathSpec- Parameters:
suffix- to add to the file or directory name- Returns:
- spec builder
-
name
Description copied from interface:PathGeneratorSpecGenerator for the file or directory name.Generated path names are formed using the following elements:
[prefix][name][suffix]- Prefix and suffix are optional and are
nullby default. - If no generator is supplied using this method, a random 16-character lowercase name will be generated.
- The concatenation of prefix, name, and suffix must not be blank.
Example:
List<Path> paths = Instancio.ofList(Path.class) .generate(all(Path.class), gen -> gen.nio().path() .prefix("queued_") .name(random -> random.alphanumeric(8)) .suffix(".csv")) .create(); // Sample paths: queued_t5LG4AUw.csv, queued_o0nBWkej.csv, etc- Specified by:
namein interfaceFilePathSpec<Path>- Specified by:
namein interfacePathAsGeneratorSpec<Path>- Specified by:
namein interfacePathGeneratorSpec<Path>- Specified by:
namein interfacePathSpec- Parameters:
nameGenerator- for generating the name- Returns:
- spec builder
- Prefix and suffix are optional and are
-
createFile
Description copied from interface:PathGeneratorSpecTerminal method to indicate that the generated path, including parent directories (if any), should be created as a file in the file system and content provided by the input stream written to the file.If the file already exists, then no action will be taken.
- Specified by:
createFilein interfaceFilePathSpec<Path>- Specified by:
createFilein interfacePathAsGeneratorSpec<Path>- Specified by:
createFilein interfacePathGeneratorSpec<Path>- Specified by:
createFilein interfacePathSpec- Parameters:
content- to write to the file- Returns:
- completed spec with no further methods
- See Also:
-
createFile
Description copied from interface:PathGeneratorSpecTerminal method to indicate that the generated path, including parent directories (if any), should be created as a file in the file system.If the file already exists, then no action will be taken.
- Specified by:
createFilein interfaceFilePathSpec<Path>- Specified by:
createFilein interfacePathAsGeneratorSpec<Path>- Specified by:
createFilein interfacePathGeneratorSpec<Path>- Specified by:
createFilein interfacePathSpec- Returns:
- completed spec with no further methods
- See Also:
-
createDirectory
Description copied from interface:PathGeneratorSpecTerminal method to indicate that the generated path, including parent directories (if any), should be created as a directory in the file system.If the directory already exists, then no action will be taken.
- Specified by:
createDirectoryin interfaceFilePathSpec<Path>- Specified by:
createDirectoryin interfacePathAsGeneratorSpec<Path>- Specified by:
createDirectoryin interfacePathGeneratorSpec<Path>- Specified by:
createDirectoryin interfacePathSpec- Returns:
- completed spec with no further methods
- See Also:
-
nullable
Description copied from interface:NullableGeneratorSpecIndicates thatnullvalue can be generated.- Specified by:
nullablein interfaceNullableGeneratorSpec<Path>- Specified by:
nullablein interfaceValueSpec<Path>- Overrides:
nullablein classAbstractGenerator<Path>- Returns:
- spec builder
-
tryGenerateNonNull
Description copied from class:AbstractGeneratorMakes the best effort to return a non-null value. However, in certain cases this method will produce anull.- Specified by:
tryGenerateNonNullin classAbstractGenerator<Path>- Parameters:
random- for generating the value- Returns:
- generated value, either a null or non-null
-