< prev index next >

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

Print this page

        

*** 33,42 **** --- 33,43 ---- import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Collections; import java.util.HashMap; import java.util.Map; + import java.util.Objects; import java.util.Set; /** * The result of hashing the contents of a number of module artifacts. */
*** 48,58 **** */ public static interface HashSupplier { byte[] generate(String algorithm); } - private final String algorithm; private final Map<String, byte[]> nameToHash; /** * Creates a {@code ModuleHashes}. --- 49,58 ----
*** 140,145 **** --- 140,180 ---- Path path = entry.getValue(); nameToHash.put(name, computeHash(path, algorithm)); } return new ModuleHashes(algorithm, nameToHash); } + + /** + * This is used by jdk.internal.module.SystemModules class + * generated at link time. + */ + public static class Builder { + final String algorithm; + Map<String, byte[]> nameToHash; + + Builder(String algorithm) { + this.algorithm = Objects.requireNonNull(algorithm); + } + + /** + * Sets the module hash for the given module name + */ + public Builder hashForModule(String mn, byte[] hash) { + if (nameToHash == null) + nameToHash = new HashMap<>(); + + nameToHash.put(mn, hash); + return this; + } + + /** + * Builds a {@code ModuleHashes}. + */ + public ModuleHashes build() { + if (nameToHash != null) { + return new ModuleHashes(algorithm, nameToHash); + } else { + return null; + } + } + } }
< prev index next >