Java Code Examples for com.google.common.base.Strings#commonSuffix()
The following examples show how to use
com.google.common.base.Strings#commonSuffix() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenVersionUtil.java From unleash-maven-plugin with Eclipse Public License 1.0 | 5 votes |
/** * 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; } } }
Example 2
Source File: StringsExample.java From levelup-java-examples with Apache License 2.0 | 5 votes |
/** * Common suffix */ @Test public void common_suffix (){ String phrase1 = "fix"; String phrase2 = "six"; String suffix = Strings.commonSuffix(phrase1, phrase2); assertEquals("ix", suffix); }
Example 3
Source File: CommonSuffixStrings.java From levelup-java-examples with Apache License 2.0 | 3 votes |
@Test public void find_common_suffix_between_strings_guava (){ String phrase1 = "fix"; String phrase2 = "six"; String suffix = Strings.commonSuffix(phrase1, phrase2); assertEquals("ix", suffix); }