Module java.base
Package java.lang.module

## Class ModuleDescriptor.Builder

- java.lang.Object
- - java.lang.module.ModuleDescriptor.Builder

Enclosing class:
  ModuleDescriptor

    public static final class ModuleDescriptor.Builder
    extends Object

A builder used for building `ModuleDescriptor` objects.

Example usage:

         ModuleDescriptor descriptor = new ModuleDescriptor.Builder("m1")
             .requires("m2")
             .exports("p")
             .build();

API Note:
  A `Builder` cannot be used to create an `automatic` or a `synthetic` module.
Since:
  9

### Constructor Summary

Constructors
Constructor and Description
`Builder(String name)` Initializes a new builder with the given module name.

### Method Summary

All Methods Instance Methods Concrete Methods
`ModuleDescriptor` `build()` Builds and returns a `ModuleDescriptor` from its components.
`ModuleDescriptor.Builder` `conceals(String pn)` Adds a concealed package.
`ModuleDescriptor.Builder` `conceals(Set<String> pns)` Adds a set of (possible empty) concealed packages.
`ModuleDescriptor.Builder` `exports(ModuleDescriptor.Exports e)` Adds an export.
`ModuleDescriptor.Builder` `exports(String pn)` Adds an export.
`ModuleDescriptor.Builder` `exports(String pn, String target)` Adds an export to a target module.
`ModuleDescriptor.Builder` `exports(String pn, Set<String> targets)` Adds an export to a set of target modules.
`ModuleDescriptor.Builder` `mainClass(String mc)` Sets the module main class.
`ModuleDescriptor.Builder` `osArch(String arch)` Sets the operating system architecture.
`ModuleDescriptor.Builder` `osName(String name)` Sets the operating system name.
`ModuleDescriptor.Builder` `osVersion(String version)` Sets the operating system version.
`ModuleDescriptor.Builder` `provides(ModuleDescriptor.Provides p)` Provides a service with one or more implementations.
`ModuleDescriptor.Builder` `provides(String st, String pc)` Provides service `st` with implementation `pc`.
`ModuleDescriptor.Builder` `provides(String st, Set<String> pcs)` Provides service `st` with implementations `pcs`.
`ModuleDescriptor.Builder` `requires(ModuleDescriptor.Requires req)` Adds a dependence on a module.
`ModuleDescriptor.Builder` `requires(ModuleDescriptor.Requires.Modifier mod, String mn)` Adds a dependence on a module with the given modifier.
`ModuleDescriptor.Builder` `requires(String mn)` Adds a dependence on a module with an empty set of modifiers.
`ModuleDescriptor.Builder` `requires(Set<ModuleDescriptor.Requires.Modifier> mods, String mn)` Adds a dependence on a module with the given (and possibly empty) set of modifiers.
`ModuleDescriptor.Builder` `uses(String st)` Adds a service dependence.
`ModuleDescriptor.Builder` `version(ModuleDescriptor.Version v)` Sets the module version.
`ModuleDescriptor.Builder` `version(String v)` Sets the module version.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### Builder

    public Builder(String name)

Initializes a new builder with the given module name.

Parameters:
  `name` - The module name
Throws:
  `IllegalArgumentException` - If the module name is `null` or is not a legal Java identifier

### Method Detail

#### requires

    public ModuleDescriptor.Builder requires(ModuleDescriptor.Requires req)

Adds a dependence on a module.

Parameters:
  `req` - The dependence
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If the dependence is on the module that this builder was initialized to build
  `IllegalStateException` - If the dependence on the module has already been declared

#### requires

    public ModuleDescriptor.Builder requires(Set<ModuleDescriptor.Requires.Modifier> mods,
                                             String mn)

Adds a dependence on a module with the given (and possibly empty) set of modifiers.

Parameters:
  `mods` - The set of modifiers
  `mn` - The module name
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If the module name is `null`, is not a legal Java identifier, or is equal to the module name that this builder was initialized to build
  `IllegalStateException` - If the dependence on the module has already been declared

#### requires

    public ModuleDescriptor.Builder requires(String mn)

Adds a dependence on a module with an empty set of modifiers.

Parameters:
  `mn` - The module name
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If the module name is `null`, is not a legal Java identifier, or is equal to the module name that this builder was initialized to build
  `IllegalStateException` - If the dependence on the module has already been declared

#### requires

    public ModuleDescriptor.Builder requires(ModuleDescriptor.Requires.Modifier mod,
                                             String mn)

Adds a dependence on a module with the given modifier.

Parameters:
  `mod` - The modifier
  `mn` - The module name
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If the module name is `null`, is not a legal Java identifier, or is equal to the module name that this builder was initialized to build
  `IllegalStateException` - If the dependence on the module has already been declared

#### uses

    public ModuleDescriptor.Builder uses(String st)

Adds a service dependence.

Parameters:
  `st` - The service type
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If the service type is `null` or is not a legal Java identifier
  `IllegalStateException` - If a dependency on the service type has already been declared

#### exports

    public ModuleDescriptor.Builder exports(ModuleDescriptor.Exports e)

Adds an export.

Parameters:
  `e` - The export
Returns:
  This builder
Throws:
  `IllegalStateException` - If the package is already declared as an exported or concealed package

#### exports

    public ModuleDescriptor.Builder exports(String pn,
                                            Set<String> targets)

Adds an export to a set of target modules.

Parameters:
  `pn` - The package name
  `targets` - The set of target modules names
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If the package name or any of the target modules is `null` or is not a legal Java identifier, or the set of targets is empty
  `IllegalStateException` - If the package is already declared as an exported or concealed package

#### exports

    public ModuleDescriptor.Builder exports(String pn,
                                            String target)

Adds an export to a target module.

Parameters:
  `pn` - The package name
  `target` - The target module name
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If the package name or target module is `null` or is not a legal Java identifier
  `IllegalStateException` - If the package is already declared as an exported or concealed package

#### exports

    public ModuleDescriptor.Builder exports(String pn)

Adds an export.

Parameters:
  `pn` - The package name
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If the package name is `null` or is not a legal Java identifier
  `IllegalStateException` - If the package is already declared as an exported or concealed package

#### provides

    public ModuleDescriptor.Builder provides(ModuleDescriptor.Provides p)

Provides a service with one or more implementations.

Parameters:
  `p` - The provides
Returns:
  This builder
Throws:
  `IllegalStateException` - If the providers for the service type have already been declared

#### provides

    public ModuleDescriptor.Builder provides(String st,
                                             Set<String> pcs)

Provides service `st` with implementations `pcs`.

Parameters:
  `st` - The service type
  `pcs` - The set of provider class names
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If the service type or any of the provider class names is `null` or is not a legal Java identifier, or the set of provider class names is empty
  `IllegalStateException` - If the providers for the service type have already been declared

#### provides

    public ModuleDescriptor.Builder provides(String st,
                                             String pc)

Provides service `st` with implementation `pc`.

Parameters:
  `st` - The service type
  `pc` - The provider class name
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If the service type or the provider class name is `null` or is not a legal Java identifier
  `IllegalStateException` - If the providers for the service type have already been declared

#### conceals

    public ModuleDescriptor.Builder conceals(Set<String> pns)

Adds a set of (possible empty) concealed packages.

Parameters:
  `pns` - The set of package names of the concealed packages
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If any of the package names is `null` or is not a legal Java identifier
  `IllegalStateException` - If any of packages are already declared as a concealed or exported package

#### conceals

    public ModuleDescriptor.Builder conceals(String pn)

Adds a concealed package.

Parameters:
  `pn` - The package name
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If the package name is `null`, or is not a legal Java identifier
  `IllegalStateException` - If the package is already declared as a concealed or exported package

#### version

    public ModuleDescriptor.Builder version(ModuleDescriptor.Version v)

Sets the module version.

Parameters:
  `v` - The version
Returns:
  This builder
Throws:
  `IllegalStateException` - If the module version is already set

#### version

    public ModuleDescriptor.Builder version(String v)

Sets the module version.

Parameters:
  `v` - The version string to parse
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If `v` is null or cannot be parsed as a version string
  `IllegalStateException` - If the module version is already set
See Also:
  `ModuleDescriptor.Version.parse(String)`

#### mainClass

    public ModuleDescriptor.Builder mainClass(String mc)

Sets the module main class.

Parameters:
  `mc` - The module main class
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If `mainClass` is null or is not a legal Java identifier
  `IllegalStateException` - If the module main class is already set

#### osName

    public ModuleDescriptor.Builder osName(String name)

Sets the operating system name.

Parameters:
  `name` - The operating system name
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If `name` is null or the empty String
  `IllegalStateException` - If the operating system name is already set

#### osArch

    public ModuleDescriptor.Builder osArch(String arch)

Sets the operating system architecture.

Parameters:
  `arch` - The operating system architecture
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If `name` is null or the empty String
  `IllegalStateException` - If the operating system architecture is already set

#### osVersion

    public ModuleDescriptor.Builder osVersion(String version)

Sets the operating system version.

Parameters:
  `version` - The operating system version
Returns:
  This builder
Throws:
  `IllegalArgumentException` - If `name` is null or the empty String
  `IllegalStateException` - If the operating system version is already set

#### build

    public ModuleDescriptor build()

Builds and returns a `ModuleDescriptor` from its components.

Returns:
  The module descriptor