import com.google.common.base.CharMatcher;
/**
* @author Andypan
* @CharMatcherTest.java
* @{describe}
* @date 2017年7月26日 上午11:48:52
*/
public class CharMatcherTest
{
public static void testCharMatchers()
{
// removerFrom
String removeFromResult = CharMatcher.isNot('a').removeFrom("abacd");
System.out.println("removeForm:" + removeFromResult);
// retainFrom method
String retainFormResult = CharMatcher.is('a').retainFrom("abacd");
System.out.println("retainForm:" + retainFormResult);
// replaceFrom method
String replaceFormResult1 = CharMatcher.WHITESPACE.replaceFrom("a bcd", 'f');
System.out.println("replaceFrom_1:" + replaceFormResult1);
String replaceFormResult2 = CharMatcher.DIGIT.replaceFrom("a3bcd", "Three");
System.out.println("replaceFrom_2:" + replaceFormResult2);
// trimFrom
String trimFromResult = CharMatcher.anyOf("ab").trimFrom("abacatabb");
System.out.println("trimFrom:" + trimFromResult);
// trimLeadingFrom
String trimLeadingFromResult = CharMatcher.anyOf("ab").trimLeadingFrom("abacatabb");
System.out.println("trimLeadingFrom:" + trimLeadingFromResult);
// trimTrailingFrom
String trimTrailingFromResult = CharMatcher.anyOf("ab").trimTrailingFrom("abacatabb");
System.out.println("trimTrailingFrom:" + trimTrailingFromResult);
// collapseFrom
String collapseFromResult = CharMatcher.anyOf("bre").collapseFrom("bookkeeper", '-');
System.out.println("collapseFrom:" + collapseFromResult);
// trimAndCollapseFrom
String trimAndCollapseFromResult = CharMatcher.anyOf("bre").trimAndCollapseFrom("bookkeeper", '-');
System.out.println("trimAndCollapseFrom:" + trimAndCollapseFromResult);
// matchesAllOf
boolean matchesAllOfResult = CharMatcher.JAVA_UPPER_CASE.matchesAnyOf("hcd");
System.out.println("matchesAnyOf:" + matchesAllOfResult);
// or and negate
String orResult = CharMatcher.JAVA_DIGIT.or(CharMatcher.JAVA_UPPER_CASE).retainFrom("dd59cF");
System.out.println("or:" + orResult);
// negate
String negateResult = CharMatcher.JAVA_DIGIT.negate().retainFrom("dd59cF");
System.out.println("negate:" + negateResult);
}
public static void main(String[] args)
{
testCharMatchers();
}
}