com.google.common.base.Strings#commonSuffix ( )源码实例Demo

下面列出了com.google.common.base.Strings#commonSuffix ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: unleash-maven-plugin   文件: MavenVersionUtil.java
/**
 * Checks whether version1 is newer than version 2.
 *
 * @param version1 the first version to check
 * @param version2 the second version to check (the anchestor)
 * @return {@code true} if version1 is newer than version2.
 */
public static boolean isNewerVersion(String version1, String version2) {
  String v1 = Strings.emptyToNull(version1);
  String v2 = Strings.emptyToNull(version2);

  if (Objects.equal(v1, v2)) {
    return false;
  } else if (v1 == null) {
    return false;
  } else if (v2 == null) {
    return true;
  } else if (Objects.equal(VERSION_LATEST, v1)) {
    return true;
  } else if (Objects.equal(VERSION_LATEST, v2)) {
    return false;
  }

  String commonPrefix = Strings.commonPrefix(v1, v2);
  v1 = v1.substring(commonPrefix.length());
  v2 = v2.substring(commonPrefix.length());
  String commonSuffix = Strings.commonSuffix(v1, v2);
  v1 = v1.substring(0, v1.length() - commonSuffix.length());
  v2 = v2.substring(0, v2.length() - commonSuffix.length());

  if (v1.isEmpty()) {
    if (Objects.equal(VERSION_QUALIFIER_SNAPSHOT, v2.toUpperCase())) {
      return true;
    } else {
      return false;
    }
  } else if (Objects.equal(VERSION_QUALIFIER_SNAPSHOT, v1.toUpperCase())) {
    return false;
  } else {
    if (Objects.equal(VERSION_QUALIFIER_SNAPSHOT, v2.toUpperCase())) {
      return true;
    } else {
      return v1.compareTo(v2) > 0;
    }
  }
}
 
源代码2 项目: levelup-java-examples   文件: StringsExample.java
/**
 * Common suffix
 */
@Test
public void common_suffix (){
	
	String phrase1 = "fix";
	String phrase2 = "six";
	
	String suffix = Strings.commonSuffix(phrase1, phrase2); 
	
	assertEquals("ix", suffix);
}
 
@Test
public void find_common_suffix_between_strings_guava (){
	
	String phrase1 = "fix";
	String phrase2 = "six";
	
	String suffix = Strings.commonSuffix(phrase1, phrase2); 
	
	assertEquals("ix", suffix);
}