List of usage examples for org.apache.commons.lang3 StringUtils difference
public static String difference(final String str1, final String str2)
Compares two Strings, and returns the portion where they differ.
From source file:me.hurel.hqlbuilder.builder.HQBQueryStringVisitor.java
private String getReducedPath(Object entity, boolean shortest) { String result;/*www . j a va 2s .c om*/ if (shortest && joinedEntities.contains(entity)) { return aliases.get(entity); } result = paths.get(entity); Object knownJoinParent = parentEntities.get(entity); Object previousKnownParent = null; while (knownJoinParent != null && previousKnownParent == null) { if (joinedEntities.contains(knownJoinParent)) { previousKnownParent = knownJoinParent; } knownJoinParent = parentEntities.get(knownJoinParent); } if (previousKnownParent != null) { String parentPath = paths.get(previousKnownParent); String end = StringUtils.difference(parentPath, result); result = new StringBuilder(aliases.get(previousKnownParent)).append(end).toString(); } return result; }
From source file:org.apache.servicecomb.serviceregistry.task.MicroserviceRegisterTask.java
/** * Compare schema summary and determine whether to re-register schema or throw exception. * @param localSchemaEntry local schema/*from ww w .j a v a2s . com*/ * @param scSchema schema in service center * @return true if the two copies of schema are the same, or local schema is re-registered successfully, * false if the local schema is re-registered to service center but failed. * @throws IllegalStateException The two copies of schema are different and the environment is not modifiable. */ private boolean compareAndReRegisterSchema(Entry<String, String> localSchemaEntry, GetSchemaResponse scSchema) { String scSchemaSummary = getScSchemaSummary(scSchema); if (null == scSchemaSummary) { // cannot get scSchemaSummary, which means there is no schema content in sc, register schema directly return registerSingleSchema(localSchemaEntry.getKey(), localSchemaEntry.getValue()); } String localSchemaSummary = RegistryUtils.calcSchemaSummary(localSchemaEntry.getValue()); if (!localSchemaSummary.equals(scSchemaSummary)) { if (onlineSchemaIsModifiable()) { LOGGER.info( "schema[{}]'s content is changed and the current environment is [{}], so re-register it!", localSchemaEntry.getKey(), ServiceCombConstants.DEVELOPMENT_SERVICECOMB_ENV); return registerSingleSchema(localSchemaEntry.getKey(), localSchemaEntry.getValue()); } //if local schema and service center schema is different then print the both schemas and print difference in local schema. String scSchemaContent = srClient.getSchema(microservice.getServiceId(), scSchema.getSchemaId()); String localSchemaContent = localSchemaEntry.getValue(); LOGGER.warn( "service center schema and local schema both are different:\n service center schema:\n[{}\n local schema:\n[{}]", scSchemaContent, localSchemaContent); String diffStringLocal = StringUtils.difference(scSchemaContent, localSchemaContent); if (diffStringLocal.equals("")) { LOGGER.warn("Some APIs are deleted in local schema which are present in service center schema \n"); } else { LOGGER.warn("The difference in local schema:\n[{}]", diffStringLocal); } // env is not development, throw an exception and break the init procedure throw new IllegalStateException("The schema(id=[" + localSchemaEntry.getKey() + "]) content held by this instance and the service center is different. " + "You need to increment microservice version before deploying. " + "Or you can configure service_description.environment=" + ServiceCombConstants.DEVELOPMENT_SERVICECOMB_ENV + " to work in development environment and ignore this error"); } // summaries are the same return true; }
From source file:org.eclipse.php.composer.test.ComposerCoreTestPlugin.java
/** * Compares expected result with the actual ingoring whitespace characters * //www .j a v a 2s . co m * @param expected * @param actual * @return difference string or <code>null</code> in case expected result is * equal to the actual. */ public static String compareContentsIgnoreWhitespace(String expected, String actual) { String tmpExpected = expected; String tmpActual = actual; String diff = StringUtils.difference(tmpExpected, tmpActual); while (diff.length() > 0) { String diff2 = StringUtils.difference(tmpActual, tmpExpected); if (!Character.isWhitespace(diff.charAt(0)) && !Character.isWhitespace(diff2.charAt(0))) { int expectedDiff = StringUtils.indexOfDifference(tmpActual, tmpExpected) + (expected.length() - tmpExpected.length()); int actualDiff = StringUtils.indexOfDifference(tmpExpected, tmpActual) + (actual.length() - tmpActual.length()); return getDiffError(expected, actual, expectedDiff, actualDiff); } tmpActual = diff.trim(); tmpExpected = diff2.trim(); diff = StringUtils.difference(tmpExpected, tmpActual); } return null; }
From source file:org.kalypso.commons.java.io.FileUtilities.java
public static String getRelativePathTo(final String base, final String absolute) { final String separator = "/"; //$NON-NLS-1$ String basePath = base.replaceAll("\\\\", separator); //$NON-NLS-1$ final String absolutePath = absolute.replaceAll("\\\\", separator); //$NON-NLS-1$ if (!absolutePath.startsWith(basePath)) { if (basePath.lastIndexOf(separator) > -1) basePath = basePath.substring(0, basePath.lastIndexOf(separator) + 1); final String difference = StringUtils.difference(basePath, absolutePath); if (difference == null || "".equals(difference)) //$NON-NLS-1$ return null; final int index = absolutePath.indexOf(difference); if (index < 5) return null; final String back = basePath.substring(index); // TODO change regExp to "everything except fileseparator" final String x = back.replaceAll("([a-zA-Z0-9_-]|\\.)+", ".."); //$NON-NLS-1$ //$NON-NLS-2$ if (x.length() > 0) // return x + "/" + difference; //$NON-NLS-1$ return x + difference; return difference; }/*from w w w . j av a 2 s.c o m*/ if (absolutePath.equalsIgnoreCase(basePath)) return ""; //$NON-NLS-1$ if (basePath.endsWith(separator)) return absolutePath.substring(basePath.length()); else return absolutePath.substring(basePath.length() + 1); }
From source file:org.norvelle.addressdiscoverer.model.KnownLastName.java
private static boolean hasLastName(String name) { for (String currName : lastNames.keySet()) { String diff = StringUtils.difference(name, currName); String diff2 = StringUtils.difference(currName, name); if (diff.isEmpty() && diff2.isEmpty()) return true; }//from w w w .j a v a 2 s.c o m return false; }
From source file:org.norvelle.addressdiscoverer.model.KnownLastNameTest.java
@Test public void testLizasoain() { //List<String> lastNames = new ArrayList<>(); boolean found = false; for (String name : lastNames.keySet()) { if (name.startsWith("Lizas")) { String difference = StringUtils.difference(name, "Lizasoain"); if (difference.isEmpty()) { found = true;// ww w .j a v a 2s . co m break; } if (name.equals("Lizasoain")) { found = true; break; } } } Assert.assertTrue(found); boolean isLastName = KnownLastName.isLastName("Lizasoain"); Assert.assertTrue("Lizasoain should be a last name", isLastName); }
From source file:org.norvelle.addressdiscoverer.model.KnownSpanishWord.java
public static boolean isWord(String word) { word = word.toLowerCase();/*from w w w . j a v a 2 s . c om*/ boolean isMatch = false; for (String currName : lastNames.keySet()) { String diff = StringUtils.difference(word, currName); String diff2 = StringUtils.difference(currName, word); if (diff.isEmpty() && diff2.isEmpty()) isMatch = true; } if (isMatch) logger.log(Level.FINE, String.format("%s is a word", word)); else logger.log(Level.FINE, String.format("%s is NOT a word", word)); return isMatch; }
From source file:org.norvelle.addressdiscoverer.model.KnownSpanishWordTest.java
@Test public void testFlamarique() { //List<String> lastNames = new ArrayList<>(); boolean found = false; for (String word : spanishWords.keySet()) { if (word.startsWith("Flam")) { String difference = StringUtils.difference(word, "Flamarique"); if (difference.isEmpty()) { found = true;/* w w w. j a v a2s .c om*/ break; } if (word.equals("Flamarique")) { found = true; break; } } } Assert.assertFalse(found); boolean isWord = KnownSpanishWord.isWord("Flamarique"); Assert.assertFalse("Flamarique should NOT be a word", isWord); boolean isWord2 = KnownSpanishWord.isWord("catedrtico"); Assert.assertTrue("catedrtico should be a word", isWord2); }
From source file:org.structr.web.advanced.DeploymentTest.java
private void compare(final String sourceHash, final boolean deleteTestDirectory, final boolean cleanDatabase) { doImportExportRoundtrip(deleteTestDirectory, cleanDatabase, null); final String roundtripHash = calculateHash(); System.out.println("Expected: " + sourceHash); System.out.println("Actual: " + roundtripHash); System.out.println(StringUtils.difference(sourceHash, roundtripHash)); if (!sourceHash.equals(roundtripHash)) { System.out.println("Expected: " + sourceHash); System.out.println("Actual: " + roundtripHash); System.out.println(StringUtils.difference(sourceHash, roundtripHash)); fail("Invalid deployment roundtrip result"); }/*from w w w .j a v a 2s . com*/ }