Class CamelCase

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

public class CamelCase extends Object implements CompoundTokenization
A compound tokenization strategy that relies a change from non-uppercase to uppercase to delimit tokens.
Author:
Garret Wilson
API Note:
This tokenization supports both dromedaryCase and PascalCase variations. That is, this tokenization is agnostic to whether the first component is capitalized, and thus supports round-trip split+join., This class normally need not be instantiated. Instead use the constant singleton instance CompoundTokenization.CAMEL_CASE.
Implementation Specification:
This implementation does not recognize delimiters whose code points lie outside the BMP (i.e. that depend on surrogate pairs).
See Also:
  • Constructor Details

    • CamelCase

      protected CamelCase()
      This class cannot be publicly instantiated, but may be subclassed and instantiated from other classes in the package.
  • Method Details

    • getName

      public String getName()
      Specified by:
      getName in interface Named<String>
      Returns:
      The name of the object, or null if the object has no name.
    • 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 Specification:
      This implementation calls transformJoinComponent(int, CharSequence) to transform each component as needed.
      Parameters:
      components - The components to join.
      Returns:
      The compound token resulting from joining the given components.
    • transformSplitComponent

      protected CharSequence transformSplitComponent(int componentIndex, @Nonnull CharSequence component)
      Determines the component to use after splitting. The first component is unchanged, as the capitalization of the first component is irrelevant to the compound tokenization.
      Implementation Specification:
      The default implementation changes the first character to lowercase if the first character is uppercase but not followed by another uppercase character.
      Parameters:
      componentIndex - The index of the component being split.
      component - The non-empty component being split.
      Returns:
      The component after splitting.
      Throws:
      NullPointerException - if the component is null.
      IllegalArgumentException - if the component is the empty string.
      See Also:
    • transformJoinComponent

      protected CharSequence transformJoinComponent(int componentIndex, @Nonnull CharSequence component)
      Determines the component to use before joining. The first component is unchanged, as the capitalization of the first component is irrelevant to the compound tokenization.
      Implementation Specification:
      The default implementation changes the first character to uppercase.
      Parameters:
      componentIndex - The index of the component being joined.
      component - The non-empty component being joined.
      Returns:
      The component to use for joining.
      Throws:
      NullPointerException - if the component is null.
      IllegalArgumentException - if the component is the empty string.
    • toCamelCase

      public String toCamelCase(CharSequence token)
      Description copied from interface: CompoundTokenization
      Converts a token from one tokenization to camelCase, leaving the case of the first component unchanged.
      Specified by:
      toCamelCase in interface CompoundTokenization
      Parameters:
      token - The compound token.
      Returns:
      The same compound token using the camelCase tokenization.
      See Also:
    • isDromedaryCase

      public boolean isDromedaryCase(@Nonnull CharSequence token)
      Indicates whether a token is in dromedaryCase (lower camelCase); this, whether its first letter is in lowercase.
      API Note:
      It is possible for a token in camelCase to be neither in dromedaryCase nor in PascalCase, e.g. if the first character is a symbol.
      Parameters:
      token - The compound token in camelCase.
      Returns:
      true if the first character is in lowercase.
      Throws:
      IllegalArgumentException - if the token is empty.
    • toDromedaryCase

      public String toDromedaryCase(@Nonnull CharSequence token)
      Converts a token from camelCase to dromedaryCase (lower camelCase) by decapitalizing the initial letter.
      API Note:
      The resulting token will not necessarily be in dromedaryCase (that is, isDromedaryCase(CharSequence) may not return true for the resulting token), e.g. if the first character is a symbol., This is a one-way conversion; it will not be possible to return to the previous tokenization unless the previous capitalization was known.
      Parameters:
      token - The compound token in camelCase.
      Returns:
      The same compound token using the PascalCase tokenization.
      Throws:
      IllegalArgumentException - if the token is empty.
    • isPascalCase

      public boolean isPascalCase(@Nonnull CharSequence token)
      Indicates whether a token is in PascalCase (upper camelCase); this, whether its first letter is in uppercase.
      API Note:
      It is possible for a token in camelCase to be neither in dromedaryCase nor in PascalCase, e.g. if the first character is a symbol.
      Parameters:
      token - The compound token in camelCase.
      Returns:
      true if the first character is in uppercase.
      Throws:
      IllegalArgumentException - if the token is empty.
    • toPascalCase

      public String toPascalCase(@Nonnull CharSequence token)
      Converts a token from camelCase to PascalCase (upper camelCase) by capitalizing the initial letter.
      API Note:
      The resulting token will not necessarily be in PascalCase (that is, isPascalCase(CharSequence) may not return true for the resulting token), e.g. if the first character is a symbol., This is a one-way conversion; it will not be possible to return to the previous tokenization unless the previous capitalization was known.
      Parameters:
      token - The compound token in camelCase.
      Returns:
      The same compound token using the PascalCase tokenization.
      Throws:
      IllegalArgumentException - if the token is empty.