Services.Name

This example demonstrates the parsing of a string into name parts and the extension of a name via the name(String) method.

  static void concatenation () {

    final Name prefix =
      Services.name (
        "io.opensignals"
      );

    final Name one =
      prefix.name (
        "one"
      );

    assert
      one
        .getPrefix ()
        .isPresent ();

    assert
      one
        .getPrefix ()
        .map ( Name::getValue )
        .filter ( "opensignals"::equals )
        .isPresent ();

    assert
      prefix ==
        one
          .getPrefix ()
          .orElse (
            null
          );

  }

This example demonstrates the interning of names created via different parsing and concatenation name(String) call sequences.

  static void equality () {

    final Name name =
      Services.name (
        "io.opensignals.one"
      );

    assert
      name.equals (
        Services
          .name ( "io" )
          .name ( "opensignals" )
          .name ( "one" )
      );

    assert
      name ==
        Services
          .name ( "io" )
          .name ( "opensignals" )
          .name ( "one" );

    assert
      name ==
        Services
          .name ( "io.opensignals" )
          .name ( "one" );

  }

This example demonstrates how to navigate over the name parts in different directions via foldTo and foldFrom methods.

  static void iteration () {

    final Name name =
      Services.name (
        "io.opensignals.one"
      );

    assert
      name
        .toString ()
        .equals (
          "io.opensignals.one"
        );

    assert
      "one -> opensignals -> io"
        .equals (
          name
            .stream ()
            .map ( Name::getValue )
            .collect ( Collectors.joining ( " -> " ) )
        );

    assert
      "one -> opensignals -> io"
        .equals (
          name
            .foldFrom (
              n ->
                new StringBuilder (
                  n.getValue ()
                ),
              ( sb, n ) ->
                sb.append (
                  " -> "
                ).append (
                  n.getValue ()
                )
            ).toString ()
        );

    assert
      "io -> opensignals -> one"
        .equals (
          name
            .foldTo (
              n ->
                new StringBuilder (
                  n.getValue ()
                ),
              ( sb, n ) ->
                sb.append (
                  " -> "
                ).append (
                  n.getValue ()
                )
            ).toString ()
        );

  }

This example demonstrates the use of the toString method to return a namespace-like path string value.

  static void path () {

    assert
      "io.opensignals.one"
        .equals (
          Services.name (
            "io.opensignals"
          ).name (
            "one"
          ).toString ()
        );

  }