Package com.globalmentor.lex
Class CamelCase
- java.lang.Object
-
- com.globalmentor.lex.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
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:
- Camel case
-
-
Field Summary
-
Fields inherited from interface com.globalmentor.lex.CompoundTokenization
CAMEL_CASE, KEBAB_CASE, KEBAB_CASE_DELIMITER, SNAKE_CASE, SNAKE_CASE_DELIMITER
-
-
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 indromedaryCase
(lowercamelCase
); this, whether its first letter is in lowercase.boolean
isPascalCase(java.lang.CharSequence token)
Indicates whether a token is inPascalCase
(uppercamelCase
); 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 tocamelCase
, leaving the case of the first component unchanged.java.lang.String
toDromedaryCase(java.lang.CharSequence token)
Converts a token fromcamelCase
todromedaryCase
(lowercamelCase
) by decapitalizing the initial letter.java.lang.String
toPascalCase(java.lang.CharSequence token)
Converts a token fromcamelCase
toPascalCase
(uppercamelCase
) 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
-
Methods inherited from interface com.globalmentor.lex.CompoundTokenization
toKebabCase, toSnakeCase
-
-
-
-
Method Detail
-
getName
public java.lang.String getName()
-
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 interfaceCompoundTokenization
- 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 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
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 isnull
.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 isnull
.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 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:
- Camel case
-
isDromedaryCase
public boolean isDromedaryCase(@Nonnull java.lang.CharSequence token)
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:
java.lang.IllegalArgumentException
- if the token is empty.
-
toDromedaryCase
public java.lang.String toDromedaryCase(@Nonnull java.lang.CharSequence token)
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:
java.lang.IllegalArgumentException
- if the token is empty.
-
isPascalCase
public boolean isPascalCase(@Nonnull java.lang.CharSequence token)
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:
java.lang.IllegalArgumentException
- if the token is empty.
-
toPascalCase
public java.lang.String toPascalCase(@Nonnull java.lang.CharSequence token)
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:
java.lang.IllegalArgumentException
- if the token is empty.
-
-