Java Code Examples for org.apache.commons.lang.StringUtils#getCommonPrefix()
The following examples show how to use
org.apache.commons.lang.StringUtils#getCommonPrefix() .
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: AnsiConsole.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public void draw(Ansi ansi) { String prefix = StringUtils.getCommonPrefix(new String[]{text, displayedText}); if (prefix.length() < displayedText.length()) { ansi.cursorLeft(displayedText.length() - prefix.length()); } if (prefix.length() < text.length()) { ColorMap.Color color = colorMap.getStatusBarColor(); color.on(ansi); ansi.a(text.substring(prefix.length())); color.off(ansi); } if (displayedText.length() > text.length()) { ansi.eraseLine(Ansi.Erase.FORWARD); } displayedText = text; }
Example 2
Source File: AnsiConsole.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public void draw(Ansi ansi) { String prefix = StringUtils.getCommonPrefix(new String[]{text, displayedText}); if (prefix.length() < displayedText.length()) { ansi.cursorLeft(displayedText.length() - prefix.length()); } if (prefix.length() < text.length()) { ColorMap.Color color = colorMap.getStatusBarColor(); color.on(ansi); ansi.a(text.substring(prefix.length())); color.off(ansi); } if (displayedText.length() > text.length()) { ansi.eraseLine(Ansi.Erase.FORWARD); } displayedText = text; }
Example 3
Source File: AnsiConsole.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public void draw(Ansi ansi) { String prefix = StringUtils.getCommonPrefix(new String[]{text, displayedText}); if (prefix.length() < displayedText.length()) { ansi.cursorLeft(displayedText.length() - prefix.length()); } if (prefix.length() < text.length()) { ColorMap.Color color = colorMap.getStatusBarColor(); color.on(ansi); ansi.a(text.substring(prefix.length())); color.off(ansi); } if (displayedText.length() > text.length()) { ansi.eraseLine(Ansi.Erase.FORWARD); } displayedText = text; }
Example 4
Source File: AnsiConsole.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public void draw(Ansi ansi) { String prefix = StringUtils.getCommonPrefix(new String[]{text, displayedText}); if (prefix.length() < displayedText.length()) { ansi.cursorLeft(displayedText.length() - prefix.length()); } if (prefix.length() < text.length()) { ColorMap.Color color = colorMap.getStatusBarColor(); color.on(ansi); ansi.a(text.substring(prefix.length())); color.off(ansi); } if (displayedText.length() > text.length()) { ansi.eraseLine(Ansi.Erase.FORWARD); } displayedText = text; }
Example 5
Source File: PathCompleter.java From hdfs-shell with Apache License 2.0 | 4 votes |
@SuppressWarnings({"rawtypes", "unchecked"}) private int analyzePossibilities(String buffer, int cursor, List<String> candidates) throws IOException { if (cursor == 0) { return -1; } final String[] args = buffer.substring(0, Math.min(cursor, buffer.length())).split(" |,", 1000); if (args.length <= 1) { return -1; } String val = args[args.length - 1]; if ("".equals(val) || " ".equals(val) || ",".equals(val)) { val = "."; } boolean isAbsolute = val.startsWith("/"); if (val.startsWith("-")) { return -1; } final int found = val.lastIndexOf('/'); final String core; final String rest; if (found == -1) { //it's relative core = contextCommands.getCurrentDir(); rest = val; } else { final String firstPart = val.substring(0, found + 1); core = (isAbsolute) ? firstPart : new Path(contextCommands.getCurrentDir(), firstPart).toUri().getPath(); rest = val.length() == 1 ? "" : val.substring(found + 1); } final FileSystem fs = FileSystem.get(contextCommands.getConfiguration()); final Path f = new Path(val); boolean folderFound = false; if (fs.exists(f) && fs.getFileStatus(f).isDirectory() && !val.endsWith("/") && !val.equals(".")) { folderFound = true; } final Path pathCore = new Path(core); if (!fs.exists(pathCore)) { return -1; } final String[] suggestions = getSuggestions(rest, fs, pathCore); String commonPrefix = StringUtils.getCommonPrefix(suggestions); if (StringUtils.isNotEmpty(commonPrefix) && !commonPrefix.equals(rest)) { commonPrefix = rest.isEmpty() || rest.equals(".") ? commonPrefix : commonPrefix.substring(rest.length()); candidates.add(commonPrefix); return cursor; } else { if (suggestions.length > 1) { if (StringUtils.isNotEmpty(commonPrefix) && commonPrefix.equals(rest)) { //problem candidatelistcompletionhandler for (int i = 0; i < suggestions.length; i++) { suggestions[i] = StringUtils.repeat(" ", i) + suggestions[i]; } } candidates.addAll(removeSlash(suggestions)); } else { if (folderFound) { candidates.add("/"); return cursor; } else { if (suggestions.length > 0) { suggestions[0] = rest.isEmpty() || rest.equals(".") ? suggestions[0] : suggestions[0].substring(rest.length()); candidates.addAll(Arrays.asList(suggestions)); } } } } return suggestions.length == 0 ? -1 : cursor; }