Guava base -- CaseFormat

来源:互联网 发布:java获取指定cookie 编辑:程序博客网 时间:2024/05/17 12:53
Guava全文介绍地址:Google Guava
这次主要介绍是的是com.google.common.base.CaseFormat,官网是对它的介绍就一句话。Utility class for converting between various ASCII case formats. Behavior is undefined for non-ASCII input.实用程序类各种ASCII案例格式之间的转换。非ascii输入行为是未定义的。

它的包含的方法如下:

Converter<String,String>converterTo(CaseFormat targetFormat)返回一个Converter ,转换字符串通过targetFormat这种格式。Stringto(CaseFormat format, String str)返回一个String对象,指定String类型的str通过指定的CaseFormat格式。static CaseFormatvalueOf(String name)根据指定的名字返回enum实例static CaseFormat[]values()返回一个数据对象,包含这个这个enum类的所有实例,且返回格式是按照声明顺序的
然后大家就可以对照下面的例子来理解这个类的用法了。

public class CaseFormatTest {    @Test    public void testToLowerCamelCaseFromLowerHyphen(){        assertThat(CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,"foo-bar"),is("fooBar"));    }    @Test    public void testToUpperCamelCaseFromLowerUnderScore(){        assertThat(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL,"foo_bar"),is("FooBar"));    }    @Test    public void testToUpperUnderScoreFromLowerCamelCase(){        assertThat(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE,"fooBar"),is("FOO_BAR"));    }}



0 0
原创粉丝点击