Class AbstractDelimiterCompoundTokenization

java.lang.Object
com.globalmentor.lex.AbstractDelimiterCompoundTokenization
All Implemented Interfaces:
CompoundTokenization, Named<String>

public abstract class AbstractDelimiterCompoundTokenization extends Object implements CompoundTokenization
A base compound tokenization strategy that relies on a delimiter between components.
Author:
Garret Wilson
  • Constructor Details

    • AbstractDelimiterCompoundTokenization

      public AbstractDelimiterCompoundTokenization(char delimiter)
      Delimiters constructor.
      Parameters:
      delimiter - The delimiter for splitting and joining a component token.
  • Method Details

    • getDelimiter

      public char getDelimiter()
      Returns:
      The delimiter used by this tokenization.
    • split

      public List<String> split(CharSequence token)
      Description copied from interface: CompoundTokenization
      Splits a compound token into its component parts.
      Specified by:
      split in interface CompoundTokenization
      Parameters:
      token - The compound token to split.
      Returns:
      The components of the compound token.
    • join

      public String join(Iterable<? extends CharSequence> components)
      Joins components into a compound token.
      Specified by:
      join in interface CompoundTokenization
      Implementation Note:
      This implementation performs joining manually rather than calling String.join(CharSequence, Iterable) for efficiency and to check each component.
      Parameters:
      components - The components to join.
      Returns:
      The compound token resulting from joining the given components.
      Throws:
      IllegalArgumentException - if one of the components already contains the tokenization delimiter.
    • toKebabCase

      public String toKebabCase(CharSequence token)
      Converts a token from one tokenization to kebab-case.
      Specified by:
      toKebabCase in interface CompoundTokenization
      Implementation Specification:
      This implementation does a simple delimiter replacement, which is more efficient than splitting and joining.
      Parameters:
      token - The compound token.
      Returns:
      The same compound token using the kebab-case tokenization.
      See Also:
    • toSnakeCase

      public String toSnakeCase(CharSequence token)
      Converts a token from one tokenization to snake_case.
      Specified by:
      toSnakeCase in interface CompoundTokenization
      Implementation Specification:
      This implementation does a simple delimiter replacement, which is more efficient than splitting and joining.
      Parameters:
      token - The compound token.
      Returns:
      The same compound token using the snake_case tokenization.
      See Also: