Interface NamespacedId

All Known Implementing Classes:
ComponentId, FontId, SpriteId, ThemeId

public interface NamespacedId
An id written as namespace:path: a ComponentId, a ThemeId, a SpriteId or a FontId.

All four follow one grammar, which check(String, String, String) enforces and parse(String, String, BiFunction) reads. The namespace is one or more characters with no colon, and the path one or more characters of any kind, colons included. Parsing splits at the first colon, so an id's toString(), which is namespace:path, parses back to an equal id.

Do not implement this interface. The four records are the only kinds of id. It is not sealed because a sealed type in a jar without a module descriptor must keep its subtypes in its own package.

  • Method Details

    • namespace

      String namespace()
      Returns the namespace.
      Returns:
      the owner, usually the id of the application or library; not empty, and without a colon
    • path

      String path()
      Returns the path.
      Returns:
      the name within the namespace; not empty, and may hold colons
    • check

      static void check(String kind, String namespace, String path)
      Checks the parts of an id against the grammar. The records call it from their constructors.
      Parameters:
      kind - what is named, such as "Sprite", for the message
      namespace - the namespace
      path - the path
      Throws:
      IllegalArgumentException - if either part is empty, or the namespace holds a colon
    • parse

      static <I extends NamespacedId> I parse(String kind, String id, BiFunction<String,String,I> maker)
      Parses namespace:path, splitting at the first colon, and makes the id from the two parts. A missing namespace is an error, so an id never lands in another namespace by accident.
      Type Parameters:
      I - the kind of id
      Parameters:
      kind - what is named, such as "Sprite", for the message
      id - the text to parse
      maker - makes the id from its namespace and path, checking them
      Returns:
      the id
      Throws:
      IllegalArgumentException - if there is no colon, or either side of it is empty