< prev index next >

src/java.base/share/classes/jdk/internal/module/Builder.java

Print this page




 176 
 177     /**
 178      * Adds a concealed package.
 179      */
 180     public Builder conceals(String pn) {
 181         conceals.add(pn);
 182         return this;
 183     }
 184 
 185     /**
 186      * Sets the module version.
 187      *
 188      * @throws IllegalArgumentException if {@code v} is null or cannot be
 189      *         parsed as a version string
 190      * @throws IllegalStateException if the module version is already set
 191      *
 192      * @see Version#parse(String)
 193      */
 194     public Builder version(String v) {
 195         if (version != null)
 196             throw new IllegalStateException("module version already set");

 197         Version ver = cachedVersion;
 198         if (ver != null && v.equals(ver.toString())) {
 199             version = ver;
 200         } else {
 201             cachedVersion = version = Version.parse(v);
 202         }
 203         return this;
 204     }
 205 
 206     /**
 207      * Sets the module main class.
 208      *
 209      * @throws IllegalStateException if already set
 210      */
 211     public Builder mainClass(String mc) {
 212         if (mainClass != null)
 213             throw new IllegalStateException("main class already set");

 214         mainClass = mc;
 215         return this;
 216     }
 217 
 218     /**
 219      * Sets the OS name.
 220      *
 221      * @throws IllegalStateException if already set
 222      */
 223     public Builder osName(String name) {
 224         if (osName != null)
 225             throw new IllegalStateException("OS name already set");

 226         this.osName = name;
 227         return this;
 228     }
 229 
 230     /**
 231      * Sets the OS arch.
 232      *
 233      * @throws IllegalStateException if already set
 234      */
 235     public Builder osArch(String arch) {
 236         if (osArch != null)
 237             throw new IllegalStateException("OS arch already set");

 238         this.osArch = arch;
 239         return this;
 240     }
 241 
 242     /**
 243      * Sets the OS version.
 244      *
 245      * @throws IllegalStateException if already set
 246      */
 247     public Builder osVersion(String version) {
 248         if (osVersion != null)
 249             throw new IllegalStateException("OS version already set");

 250         this.osVersion = version;
 251         return this;
 252     }
 253 
 254     /**
 255      * Returns the set of packages that is the union of the exported and
 256      * concealed packages.
 257      */
 258     private Set<String> computePackages(Set<Exports> exports, Set<String> conceals) {
 259         if (exports.isEmpty())
 260             return conceals;
 261 
 262         Set<String> pkgs = new HashSet<>(numPackages);
 263         pkgs.addAll(conceals);
 264         for (Exports e : exports) {
 265             pkgs.add(e.source());
 266         }
 267         return pkgs;
 268     }
 269 




 176 
 177     /**
 178      * Adds a concealed package.
 179      */
 180     public Builder conceals(String pn) {
 181         conceals.add(pn);
 182         return this;
 183     }
 184 
 185     /**
 186      * Sets the module version.
 187      *
 188      * @throws IllegalArgumentException if {@code v} is null or cannot be
 189      *         parsed as a version string
 190      * @throws IllegalStateException if the module version is already set
 191      *
 192      * @see Version#parse(String)
 193      */
 194     public Builder version(String v) {
 195         if (version != null)
 196             throw new IllegalStateException(
 197                 "module version already set: " + version);
 198         Version ver = cachedVersion;
 199         if (ver != null && v.equals(ver.toString())) {
 200             version = ver;
 201         } else {
 202             cachedVersion = version = Version.parse(v);
 203         }
 204         return this;
 205     }
 206 
 207     /**
 208      * Sets the module main class.
 209      *
 210      * @throws IllegalStateException if already set
 211      */
 212     public Builder mainClass(String mc) {
 213         if (mainClass != null)
 214             throw new IllegalStateException(
 215                 "main class already set: " + mainClass);
 216         mainClass = mc;
 217         return this;
 218     }
 219 
 220     /**
 221      * Sets the OS name.
 222      *
 223      * @throws IllegalStateException if already set
 224      */
 225     public Builder osName(String name) {
 226         if (osName != null)
 227             throw new IllegalStateException(
 228                 "OS name already set: " + osName);
 229         this.osName = name;
 230         return this;
 231     }
 232 
 233     /**
 234      * Sets the OS arch.
 235      *
 236      * @throws IllegalStateException if already set
 237      */
 238     public Builder osArch(String arch) {
 239         if (osArch != null)
 240             throw new IllegalStateException(
 241                 "OS arch already set: " + osArch);
 242         this.osArch = arch;
 243         return this;
 244     }
 245 
 246     /**
 247      * Sets the OS version.
 248      *
 249      * @throws IllegalStateException if already set
 250      */
 251     public Builder osVersion(String version) {
 252         if (osVersion != null)
 253             throw new IllegalStateException(
 254                 "OS version already set: " + osVersion);
 255         this.osVersion = version;
 256         return this;
 257     }
 258 
 259     /**
 260      * Returns the set of packages that is the union of the exported and
 261      * concealed packages.
 262      */
 263     private Set<String> computePackages(Set<Exports> exports, Set<String> conceals) {
 264         if (exports.isEmpty())
 265             return conceals;
 266 
 267         Set<String> pkgs = new HashSet<>(numPackages);
 268         pkgs.addAll(conceals);
 269         for (Exports e : exports) {
 270             pkgs.add(e.source());
 271         }
 272         return pkgs;
 273     }
 274 


< prev index next >