Package com.globalmentor.lex
Class CamelCase
java.lang.Object
com.globalmentor.lex.CamelCase
- All Implemented Interfaces:
CompoundTokenization
,Named<String>
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
andPascalCase
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 instanceCompoundTokenization.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:
-
Field Summary
Fields inherited from interface com.globalmentor.lex.CompoundTokenization
CAMEL_CASE, KEBAB_CASE, KEBAB_CASE_DELIMITER, SNAKE_CASE, SNAKE_CASE_DELIMITER
-
Constructor Summary
ModifierConstructorDescriptionprotected
This class cannot be publicly instantiated, but may be subclassed and instantiated from other classes in the package. -
Method Summary
Modifier and TypeMethodDescriptiongetName()
boolean
isDromedaryCase
(CharSequence token) Indicates whether a token is indromedaryCase
(lowercamelCase
); this, whether its first letter is in lowercase.boolean
isPascalCase
(CharSequence token) Indicates whether a token is inPascalCase
(uppercamelCase
); this, whether its first letter is in uppercase.join
(Iterable<? extends CharSequence> components) Joins components into a compound token.split
(CharSequence token) Splits a compound token into its component parts.toCamelCase
(CharSequence token) Converts a token from one tokenization tocamelCase
, leaving the case of the first component unchanged.toDromedaryCase
(CharSequence token) Converts a token fromcamelCase
todromedaryCase
(lowercamelCase
) by decapitalizing the initial letter.toPascalCase
(CharSequence token) Converts a token fromcamelCase
toPascalCase
(uppercamelCase
) by capitalizing the initial letter.protected CharSequence
transformJoinComponent
(int componentIndex, CharSequence component) Determines the component to use before joining.protected CharSequence
transformSplitComponent
(int componentIndex, 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
Methods inherited from interface com.globalmentor.lex.CompoundTokenization
toKebabCase, toSnakeCase
-
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
-
split
Description copied from interface:CompoundTokenization
Splits a compound token into its component parts.- Specified by:
split
in interfaceCompoundTokenization
- Parameters:
token
- The compound token to split.- Returns:
- The components of the compound token.
-
join
Joins components into a compound token.- Specified by:
join
in interfaceCompoundTokenization
- 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
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 isnull
.IllegalArgumentException
- if the component is the empty string.- See Also:
-
transformJoinComponent
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 isnull
.IllegalArgumentException
- if the component is the empty string.
-
toCamelCase
Description copied from interface:CompoundTokenization
Converts a token from one tokenization tocamelCase
, leaving the case of the first component unchanged.- Specified by:
toCamelCase
in interfaceCompoundTokenization
- Parameters:
token
- The compound token.- Returns:
- The same compound token using the
camelCase
tokenization. - See Also:
-
isDromedaryCase
Indicates whether a token is indromedaryCase
(lowercamelCase
); this, whether its first letter is in lowercase.- API Note:
- It is possible for a token in
camelCase
to be neither indromedaryCase
nor inPascalCase
, e.g. if the first character is a symbol. - Parameters:
token
- The compound token incamelCase
.- Returns:
true
if the first character is in lowercase.- Throws:
IllegalArgumentException
- if the token is empty.
-
toDromedaryCase
Converts a token fromcamelCase
todromedaryCase
(lowercamelCase
) by decapitalizing the initial letter.- API Note:
- The resulting token will not necessarily be in
dromedaryCase
(that is,isDromedaryCase(CharSequence)
may not returntrue
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 incamelCase
.- Returns:
- The same compound token using the
PascalCase
tokenization. - Throws:
IllegalArgumentException
- if the token is empty.
-
isPascalCase
Indicates whether a token is inPascalCase
(uppercamelCase
); this, whether its first letter is in uppercase.- API Note:
- It is possible for a token in
camelCase
to be neither indromedaryCase
nor inPascalCase
, e.g. if the first character is a symbol. - Parameters:
token
- The compound token incamelCase
.- Returns:
true
if the first character is in uppercase.- Throws:
IllegalArgumentException
- if the token is empty.
-
toPascalCase
Converts a token fromcamelCase
toPascalCase
(uppercamelCase
) by capitalizing the initial letter.- API Note:
- The resulting token will not necessarily be in
PascalCase
(that is,isPascalCase(CharSequence)
may not returntrue
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 incamelCase
.- Returns:
- The same compound token using the
PascalCase
tokenization. - Throws:
IllegalArgumentException
- if the token is empty.
-