/** * Returns the path that points to the least common ancestor of the specified * collection of paths. * * @param paths collection of path * @return path to least common ancestor */ public static DocumentPath leastCommonAncestor(Collection<DocumentPath> paths) { if (paths.isEmpty()) { return null; } return DocumentPath.from(StringUtils.getCommonPrefix(paths.stream() .map(DocumentPath::toString) .toArray(String[]::new))); }
@Test public void testGetCommonPrefix_StringArray() { assertEquals("", StringUtils.getCommonPrefix((String[]) null)); assertEquals("", StringUtils.getCommonPrefix()); assertEquals("abc", StringUtils.getCommonPrefix("abc")); assertEquals("", StringUtils.getCommonPrefix(null, null)); assertEquals("", StringUtils.getCommonPrefix("", "")); assertEquals("", StringUtils.getCommonPrefix("", null)); assertEquals("", StringUtils.getCommonPrefix("abc", null, null)); assertEquals("", StringUtils.getCommonPrefix(null, null, "abc")); assertEquals("", StringUtils.getCommonPrefix("", "abc")); assertEquals("", StringUtils.getCommonPrefix("abc", "")); assertEquals("abc", StringUtils.getCommonPrefix("abc", "abc")); assertEquals("a", StringUtils.getCommonPrefix("abc", "a")); assertEquals("ab", StringUtils.getCommonPrefix("ab", "abxyz")); assertEquals("ab", StringUtils.getCommonPrefix("abcde", "abxyz")); assertEquals("", StringUtils.getCommonPrefix("abcde", "xyz")); assertEquals("", StringUtils.getCommonPrefix("xyz", "abcde")); assertEquals("i am a ", StringUtils.getCommonPrefix("i am a machine", "i am a robot")); }
Collectors.toList()); int prefixLength = StringUtils.getCommonPrefix(normalizedFiles.toArray(new String[] {})).length();
public static String getCommonPrefix(String... strings) { return StringUtils.getCommonPrefix(strings); }
/** * Returns the common prefix of variables for enum naming * * @param vars List of variable names * @return the common prefix for naming */ public String findCommonPrefixOfVars(List<Object> vars) { try { String[] listStr = vars.toArray(new String[vars.size()]); String prefix = StringUtils.getCommonPrefix(listStr); // exclude trailing characters that should be part of a valid variable // e.g. ["status-on", "status-off"] => "status-" (not "status-o") return prefix.replaceAll("[a-zA-Z0-9]+\\z", ""); } catch (ArrayStoreException e) { return ""; } }
/** * Returns the common prefix of variables for enum naming * * @param vars List of variable names * @return the common prefix for naming */ public String findCommonPrefixOfVars(List<Object> vars) { try { String[] listStr = vars.toArray(new String[vars.size()]); String prefix = StringUtils.getCommonPrefix(listStr); // exclude trailing characters that should be part of a valid variable // e.g. ["status-on", "status-off"] => "status-" (not "status-o") return prefix.replaceAll("[a-zA-Z0-9]+\\z", ""); } catch (ArrayStoreException e) { return ""; } }
public int calculateRelevance() { String commonPrefix = getCommonPrefix(subwordsMatchingRegion.toLowerCase(), prefix.toLowerCase()); int score = 0; if (commonPrefix.length() == prefix.length()) { // complete prefix match score += 200; } int relevance = jdtProposal.getRelevance() + score + bestSubsequenceScore; return relevance; }
/** * Returns the common prefix of variables for enum naming if * two or more variables are present * * @param vars List of variable names * @return the common prefix for naming */ public String findCommonPrefixOfVars(List<Object> vars) { if (vars.size() > 1) { try { String[] listStr = vars.toArray(new String[vars.size()]); String prefix = StringUtils.getCommonPrefix(listStr); // exclude trailing characters that should be part of a valid variable // e.g. ["status-on", "status-off"] => "status-" (not "status-o") return prefix.replaceAll("[a-zA-Z0-9]+\\z", ""); } catch (ArrayStoreException e) { // do nothing, just return default value } } return ""; }
/** * Returns the path that points to the least common ancestor of the specified * collection of paths. * * @param paths collection of path * @return path to least common ancestor */ public static DocumentPath leastCommonAncestor(Collection<DocumentPath> paths) { if (paths.isEmpty()) { return null; } return DocumentPath.from(StringUtils.getCommonPrefix(paths.stream() .map(DocumentPath::toString) .toArray(String[]::new))); }
protected String determineCommonAttributePath(final Set<String> attributePathsSet, final String[] attributePaths, int i) { for (final String filterAttributePath : attributePathsSet) { attributePaths[i] = StringEscapeUtils.unescapeXml(filterAttributePath); i++; } final String commonPrefix = StringUtils.getCommonPrefix(attributePaths); if (!commonPrefix.endsWith(DMPStatics.ATTRIBUTE_DELIMITER.toString())) { if (!commonPrefix.contains(DMPStatics.ATTRIBUTE_DELIMITER.toString())) { return commonPrefix; } return commonPrefix.substring(0, commonPrefix.lastIndexOf(DMPStatics.ATTRIBUTE_DELIMITER)); } return commonPrefix.substring(0, commonPrefix.length() - 1); }
/** * Get relative path. * * @param from from path. * @param to to path. * @return relative path. */ public static String relativize(String from, String to) { from = new File(normalize(from)).toURI().toASCIIString(); to = new File(normalize(to)).toURI().toASCIIString(); int prefixLen = StringUtils.getCommonPrefix(from, to).length(); int level = StringUtils.countMatches(from.substring(prefixLen), "/"); return StringUtils.repeat("../", level) + to.substring(prefixLen); } }
public static String getCommonSuffix(String... strs) { if (strs == null || strs.length == 0) { return ""; } String[] reversedStrs = new String[strs.length]; for (int i = 0; i < strs.length; i++) reversedStrs[i] = StringUtils.reverse(strs[i]); return StringUtils.reverse(StringUtils.getCommonPrefix(reversedStrs)); } }
public static String getCommonSuffix(String... strs) { if (strs == null || strs.length == 0) { return ""; } String[] reversedStrs = new String[strs.length]; for (int i = 0; i < strs.length; i++) reversedStrs[i] = StringUtils.reverse(strs[i]); return StringUtils.reverse(StringUtils.getCommonPrefix(reversedStrs)); }
public static String getCommonSuffix(String... strs) { if (strs == null || strs.length == 0) { return ""; } String[] reversedStrs = new String[strs.length]; for (int i = 0; i < strs.length; i++) reversedStrs[i] = StringUtils.reverse(strs[i]); return StringUtils.reverse(StringUtils.getCommonPrefix(reversedStrs)); }
public static String getCommonSuffix(String... strings) { if (strings == null || strings.length == 0) { return ""; } String[] reversedStrs = new String[strings.length]; for (int i = 0; i < strings.length; i++) reversedStrs[i] = StringUtils.reverse(strings[i]); return StringUtils.reverse(StringUtils.getCommonPrefix(reversedStrs)); }
public String relativize(File from, File to) throws IOException { String fromPath = from.getCanonicalPath(); String toPath = to.getCanonicalPath(); String root = StringUtils.getCommonPrefix(fromPath, toPath); StringBuffer result = new StringBuffer(); if (this.fromPathIsNotADirectAncestor(fromPath, root)) { for (@SuppressWarnings("unused") String dir : this.divergentDirectories(root, fromPath)) { result.append("..").append(File.separator); } } result.append(this.pathAfterRoot(toPath, root)); return this.convertSlashes(this.trimLeadingSlashIfNecessary(result)); }
public String relativize(File from, File to) throws IOException { String fromPath = from.getCanonicalPath(); String toPath = to.getCanonicalPath(); String root = StringUtils.getCommonPrefix(new String[]{fromPath, toPath}); StringBuffer result = new StringBuffer(); if (this.fromPathIsNotADirectAncestor(fromPath, root)) { for (@SuppressWarnings("unused") String dir : this.divergentDirectories(root, fromPath)) { result.append("..").append(File.separator); } } result.append(this.pathAfterRoot(toPath, root)); return this.convertSlashes(this.trimLeadingSlashIfNecessary(result)); }
public YoSpatialVector(YoFrameVector yoLinearPart, YoFrameVector yoAngularPart, ReferenceFrame expressedInFrame) { this.namePrefix = StringUtils.getCommonPrefix(yoLinearPart.getNamePrefix(), yoAngularPart.getNamePrefix()); this.nameSuffix = YoFrameVariableNameTools.getCommonSuffix(yoLinearPart.getNameSuffix(), yoAngularPart.getNameSuffix()); this.linearPart = yoLinearPart; this.angularPart = yoAngularPart; this.expressedInFrame = expressedInFrame; }
public YoFrameTuple(DoubleYoVariable xVariable, DoubleYoVariable yVariable, DoubleYoVariable zVariable, ReferenceFrame referenceFrame) { this.namePrefix = StringUtils.getCommonPrefix(xVariable.getName(), yVariable.getName(), zVariable.getName()); this.nameSuffix = YoFrameVariableNameTools.getCommonSuffix(xVariable.getName(), yVariable.getName(), zVariable.getName()); this.x = xVariable; this.y = yVariable; this.z = zVariable; this.referenceFrame = referenceFrame; this.frameTuple = createEmptyFrameTuple(); }
public YoFrameQuaternion(DoubleYoVariable qx, DoubleYoVariable qy, DoubleYoVariable qz, DoubleYoVariable qs, ReferenceFrame referenceFrame) { this.namePrefix = StringUtils.getCommonPrefix(qx.getName(), qy.getName(), qz.getName(), qs.getName()); this.nameSuffix = YoFrameVariableNameTools.getCommonSuffix(qx.getName(), qy.getName(), qz.getName(), qs.getName()); this.qx = qx; this.qy = qy; this.qz = qz; this.qs = qs; this.referenceFrame = referenceFrame; }