Top Description Inners Fields Constructors Methods
com.google.common.base

public sealed Enum CaseFormat

extends Enum<CaseFormat>
Class Inheritance
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull, java.util.Objects.requireNonNull

Utility class for converting between various ASCII case formats. Behavior is undefined for non-ASCII input.
Author
Mike Bostock
Since
1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
public static final CaseFormat
LOWER_CAMEL

Java variable naming convention, e.g., "lowerCamel".

public static final CaseFormat
LOWER_HYPHEN

Hyphenated variable naming convention, e.g., "lower-hyphen".

public static final CaseFormat
LOWER_UNDERSCORE

C++ variable naming convention, e.g., "lower_underscore".

public static final CaseFormat
UPPER_CAMEL

Java and C++ class naming convention, e.g., "UpperCamel".

public static final CaseFormat
UPPER_UNDERSCORE

Java and C++ constant naming convention, e.g., "UPPER_UNDERSCORE".

private final CharMatcher
private final String

Constructor Summary

AccessConstructor and Description
private
CaseFormat(CharMatcher wordBoundary, String wordSeparator)

Method Summary

Modifier and TypeMethod and Description
pack-priv String
convert(CaseFormat format, String s)

Enum values can override for performance reasons.

public Converter<String, String>
converterTo(CaseFormat targetFormat)

Returns a serializable Converter that converts strings from this format to targetFormat.

private static String
pack-priv String
pack-priv abstract String
public final String
to(CaseFormat format, String str)

Converts the specified String str from this format to the specified format.

public static CaseFormat
public static CaseFormat[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

LOWER_CAMELback to summary
public static final CaseFormat LOWER_CAMEL

Java variable naming convention, e.g., "lowerCamel".

LOWER_HYPHENback to summary
public static final CaseFormat LOWER_HYPHEN

Hyphenated variable naming convention, e.g., "lower-hyphen".

LOWER_UNDERSCOREback to summary
public static final CaseFormat LOWER_UNDERSCORE

C++ variable naming convention, e.g., "lower_underscore".

UPPER_CAMELback to summary
public static final CaseFormat UPPER_CAMEL

Java and C++ class naming convention, e.g., "UpperCamel".

UPPER_UNDERSCOREback to summary
public static final CaseFormat UPPER_UNDERSCORE

Java and C++ constant naming convention, e.g., "UPPER_UNDERSCORE".

wordBoundaryback to summary
private final CharMatcher wordBoundary
wordSeparatorback to summary
private final String wordSeparator

Constructor Detail

CaseFormatback to summary
private CaseFormat(CharMatcher wordBoundary, String wordSeparator)

Method Detail

convertback to summary
pack-priv String convert(CaseFormat format, String s)

Enum values can override for performance reasons.

converterToback to summary
public Converter<String, String> converterTo(CaseFormat targetFormat)

Returns a serializable Converter that converts strings from this format to targetFormat.

Since
16.0
firstCharOnlyToUpperback to summary
private static String firstCharOnlyToUpper(String word)
normalizeFirstWordback to summary
pack-priv String normalizeFirstWord(String word)
normalizeWordback to summary
pack-priv abstract String normalizeWord(String word)
toback to summary
public final String to(CaseFormat format, String str)

Converts the specified String str from this format to the specified format. A "best effort" approach is taken; if str does not conform to the assumed format, then the behavior of this method is undefined but we make a reasonable effort at converting anyway.

valueOfback to summary
public static CaseFormat valueOf(String name)
valuesback to summary
public static CaseFormat[] values()
com.google.common.base back to summary

private final Class CaseFormat.StringConverter

extends Converter<String, String>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
private static final long
private final CaseFormat
private final CaseFormat

Constructor Summary

AccessConstructor and Description
pack-priv
StringConverter(CaseFormat sourceFormat, CaseFormat targetFormat)

Method Summary

Modifier and TypeMethod and Description
protected String
doBackward(String
the instance to convert; will never be null
s
)

Implements abstract com.google.common.base.Converter.doBackward.

Returns a representation of b as an instance of type A.
protected String
doForward(String
the instance to convert; will never be null
s
)

Implements abstract com.google.common.base.Converter.doForward.

Returns a representation of a as an instance of type B.
public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides com.google.common.base.Converter.equals.

Implements com.google.common.base.Function.equals.

Indicates whether another object is equal to this converter.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from com.google.common.base.Converter:
andThenapplyconvertconvertAllcorrectedDoBackwardcorrectedDoForwarddoAndThenfromidentityreverse

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID
sourceFormatback to summary
private final CaseFormat sourceFormat
targetFormatback to summary
private final CaseFormat targetFormat

Constructor Detail

StringConverterback to summary
pack-priv StringConverter(CaseFormat sourceFormat, CaseFormat targetFormat)

Method Detail

doBackwardback to summary
protected String doBackward(String s)

Implements abstract com.google.common.base.Converter.doBackward.

Doc from com.google.common.base.Converter.doBackward.

Returns a representation of b as an instance of type A. If b cannot be converted, an unchecked exception (such as IllegalArgumentException) should be thrown.

Parameters
s:String

the instance to convert; will never be null

Returns:String

the converted instance; must not be null

Annotations
@Override
doForwardback to summary
protected String doForward(String s)

Implements abstract com.google.common.base.Converter.doForward.

Doc from com.google.common.base.Converter.doForward.

Returns a representation of a as an instance of type B. If a cannot be converted, an unchecked exception (such as IllegalArgumentException) should be thrown.

Parameters
s:String

the instance to convert; will never be null

Returns:String

the converted instance; must not be null

Annotations
@Override
equalsback to summary
public boolean equals(Object object)

Overrides com.google.common.base.Converter.equals.

Implements com.google.common.base.Function.equals.

Doc from com.google.common.base.Converter.equals.

Indicates whether another object is equal to this converter.

Most implementations will have no reason to override the behavior of Object#equals. However, an implementation may also choose to return true whenever object is a Converter that it considers interchangeable with this one. "Interchangeable" typically means that Objects.equal(this.convert(a), that.convert(a)) is true for all a of type A (and similarly for reverse). Note that a false result from this method does not imply that the converters are known not to be interchangeable.

Parameters
object:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override