package com.github.sormuras.bach.internal;

import com.github.sormuras.bach.ModuleLookup;
import java.lang.module.ModuleDescriptor;
import java.net.URI;
import java.util.Optional;

/**
 * A module lookup for an external module.
 *
 * @param module the name of the external module
 * @param uri the uri of the external module
 */
public record ExternalModuleLookup(String module, String uri) implements ModuleLookup {
  /**
   * @throws IllegalArgumentException if the given module is {@code null} or is not a legal name
   * @throws IllegalArgumentException if the given uri string violates RFC&nbsp;2396
   */
  public ExternalModuleLookup {
    ModuleDescriptor.newModule(module);
    URI.create(uri);
  }

  @Override
  public Optional<String> lookupModule(String module) {
    return this.module.equals(module) ? Optional.of(uri) : Optional.empty();
  }

  @Override
  public String toString() {
    return module + " -> " + uri;
  }
}

@@ -146,16 +146,74 @@
 et.URI;%0A
+import java.util.Formattable;%0Aimport java.util.Formatter;%0A
 import j
@@ -231,16 +231,16 @@
 tional;%0A
-
 %0A/**%0A * 
@@ -461,24 +461,37 @@
 ModuleLookup
+, Formattable
  %7B%0A  /**%0A   
@@ -837,24 +837,24 @@
 g module) %7B%0A
-
     return t
@@ -915,32 +915,724 @@
 l.empty();%0A  %7D%0A%0A
+  @Override%0A  public void formatTo(Formatter formatter, int flags, int width, int precision) %7B%0A    if (precision %3C 0) %7B%0A      formatter.format(%22%25s -%3E %25s%22, module, uri);%0A      return;%0A    %7D%0A    if (precision == 0) return;%0A    var builder = new StringBuilder(precision).append(module).append(%22 -%3E %22);%0A    var available = precision - builder.length();%0A    if (available %3E= uri.length()) %7B%0A      builder.append(uri);%0A    %7D else %7B%0A      var head = available / 2;%0A      var tail = available %25 2 == 0 ? head - 3 : head - 2;%0A      builder.append(uri, 0, head);%0A      builder.append(%22...%22);%0A      builder.append(uri, uri.length() - tail, uri.length());%0A    %7D%0A    formatter.format(%22%25s%22, builder);%0A  %7D%0A%0A
   @Override%0A  pu

Implement Formattable interface