Class CamelCase

  • All Implemented Interfaces:
    CompoundTokenization, Named<java.lang.String>

    public class CamelCase
    extends java.lang.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:
    Camel case
    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getName()  
      boolean isDromedaryCase​(java.lang.CharSequence token)
      Indicates whether a token is in dromedaryCase (lower camelCase); this, whether its first letter is in lowercase.
      boolean isPascalCase​(java.lang.CharSequence token)
      Indicates whether a token is in PascalCase (upper camelCase); this, whether its first letter is in uppercase.
      java.lang.String join​(java.lang.Iterable<? extends java.lang.CharSequence> components)
      Joins components into a compound token.
      java.util.List<java.lang.String> split​(java.lang.CharSequence token)
      Splits a compound token into its component parts.
      java.lang.String toCamelCase​(java.lang.CharSequence token)
      Converts a token from one tokenization to camelCase, leaving the case of the first component unchanged.
      java.lang.String toDromedaryCase​(java.lang.CharSequence token)
      Converts a token from camelCase to dromedaryCase (lower camelCase) by decapitalizing the initial letter.
      java.lang.String toPascalCase​(java.lang.CharSequence token)
      Converts a token from camelCase to PascalCase (upper camelCase) by capitalizing the initial letter.
      protected java.lang.CharSequence transformJoinComponent​(int componentIndex, java.lang.CharSequence component)
      Determines the component to use before joining.
      protected java.lang.CharSequence transformSplitComponent​(int componentIndex, java.lang.CharSequence component)
      Determines the component to use after splitting.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CamelCase

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

      • getName

        public java.lang.String getName()
        Specified by:
        getName in interface Named<java.lang.String>
        Returns:
        The name of the object, or null if the object has no name.
      • split

        public java.util.List<java.lang.String> split​(java.lang.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 java.lang.String join​(java.lang.Iterable<? extends java.lang.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 java.lang.CharSequence transformSplitComponent​(int componentIndex,
                                                                 @Nonnull
                                                                 java.lang.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:
        java.lang.NullPointerException - if the component is null.
        java.lang.IllegalArgumentException - if the component is the empty string.
        See Also:
        Introspector.decapitalize(String)
      • transformJoinComponent

        protected java.lang.CharSequence transformJoinComponent​(int componentIndex,
                                                                @Nonnull
                                                                java.lang.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:
        java.lang.NullPointerException - if the component is null.
        java.lang.IllegalArgumentException - if the component is the empty string.
      • toCamelCase

        public java.lang.String toCamelCase​(java.lang.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:
        Camel case
      • isDromedaryCase

        public boolean isDromedaryCase​(@Nonnull
                                       java.lang.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:
        java.lang.IllegalArgumentException - if the token is empty.
      • toDromedaryCase

        public java.lang.String toDromedaryCase​(@Nonnull
                                                java.lang.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:
        java.lang.IllegalArgumentException - if the token is empty.
      • isPascalCase

        public boolean isPascalCase​(@Nonnull
                                    java.lang.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:
        java.lang.IllegalArgumentException - if the token is empty.
      • toPascalCase

        public java.lang.String toPascalCase​(@Nonnull
                                             java.lang.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:
        java.lang.IllegalArgumentException - if the token is empty.