Example usage for org.apache.commons.lang StringUtils indexOfDifference

List of usage examples for org.apache.commons.lang StringUtils indexOfDifference

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils indexOfDifference.

Prototype

public static int indexOfDifference(String str1, String str2) 

Source Link

Document

Compares two Strings, and returns the index at which the Strings begin to differ.

Usage

From source file:org.archive.util.PrefixFinder.java

public static List<String> findKeys(SortedMap<String, ?> map, String input) {
    LinkedList<String> result = new LinkedList<String>();
    map = headMapInclusive(map, input);//from  w  w w.  java2  s.  com
    for (String last = last(map); last != null; last = last(map)) {
        if (input.startsWith(last)) {
            result.push(last);
            map = map.headMap(last);
        } else {
            // Find the longest common prefix.
            int p = StringUtils.indexOfDifference(input, last);
            if (p <= 0) {
                return result;
            }
            last = input.substring(0, p);
            map = headMapInclusive(map, last);
        }
    }
    return result;
}

From source file:org.sventon.model.LogEntry.java

/**
 * Iterate through (and modify!) the log entries and set the pathAtRevision for each entry.
 *
 * @param logEntries the entries to set pathAtRevision for
 * @param path       the starting path//from ww w . java  2 s . c o m
 */
public static void setPathAtRevisionInLogEntries(final List<LogEntry> logEntries, final String path) {
    String pathAtRevision = path;

    for (final LogEntry logEntry : logEntries) {
        logEntry.setPathAtRevision(pathAtRevision);

        //noinspection unchecked
        final SortedSet<ChangedPath> allChangedPaths = logEntry.getChangedPaths();
        if (allChangedPaths != null) {
            for (ChangedPath entryPath : allChangedPaths) {
                if (entryPath.getCopyPath() != null) {
                    int i = StringUtils.indexOfDifference(entryPath.getPath(), pathAtRevision);
                    if (i == -1) { // Same path
                        pathAtRevision = entryPath.getCopyPath();
                    } else if (entryPath.getPath().length() == i) { // Part path, can be a branch
                        pathAtRevision = entryPath.getCopyPath() + pathAtRevision.substring(i);
                    } else {
                        // TODO: else what? Is this OK to let the path be the previous?
                    }
                }
            }
        }
    }
}

From source file:org.sventon.web.ctrl.template.ShowLogController.java

/**
 * {@inheritDoc}//from www. j  a  v a  2 s .  c om
 */
protected ModelAndView svnHandle(final SVNRepository repository, final BaseCommand command,
        final long headRevision, final UserRepositoryContext userRepositoryContext,
        final HttpServletRequest request, final HttpServletResponse response, final BindException exception)
        throws Exception {

    final String nextPathParam = ServletRequestUtils.getStringParameter(request, "nextPath", command.getPath());
    final SVNRevision nextRevParam = SVNRevision
            .parse(ServletRequestUtils.getStringParameter(request, "nextRevision", "head"));
    final boolean stopOnCopy = ServletRequestUtils.getBooleanParameter(request, "stopOnCopy", true);

    final long revNumber;
    if (SVNRevision.HEAD.equals(nextRevParam)) {
        revNumber = headRevision;
    } else {
        revNumber = nextRevParam.getNumber();
    }

    final List<LogEntryWrapper> logEntryWrappers = new ArrayList<LogEntryWrapper>();

    try {
        final List<SVNLogEntry> logEntries = getRepositoryService().getRevisions(command.getName(), repository,
                revNumber, FIRST_REVISION, nextPathParam, pageSize, stopOnCopy);

        String pathAtRevision = nextPathParam;

        for (final SVNLogEntry logEntry : logEntries) {
            logEntryWrappers.add(new LogEntryWrapper(logEntry, pathAtRevision));

            //noinspection unchecked
            final Map<String, SVNLogEntryPath> allChangedPaths = logEntry.getChangedPaths();
            final Set<String> changedPaths = allChangedPaths.keySet();

            for (String entryPath : changedPaths) {
                int i = StringUtils.indexOfDifference(entryPath, pathAtRevision);
                if (i == -1) { // Same path
                    final SVNLogEntryPath logEntryPath = allChangedPaths.get(entryPath);
                    if (logEntryPath.getCopyPath() != null) {
                        pathAtRevision = logEntryPath.getCopyPath();
                    }
                } else if (entryPath.length() == i) { // Part path, can be a branch
                    final SVNLogEntryPath logEntryPath = allChangedPaths.get(entryPath);
                    if (logEntryPath.getCopyPath() != null) {
                        pathAtRevision = logEntryPath.getCopyPath() + pathAtRevision.substring(i);
                    }
                }
            }
        }
    } catch (SVNException svnex) {
        if (SVNErrorCode.FS_NO_SUCH_REVISION == svnex.getErrorMessage().getErrorCode()) {
            logger.info(svnex.getMessage());
        } else {
            logger.error(svnex.getMessage());
        }
    }

    final Map<String, Object> model = new HashMap<String, Object>();

    model.put("stopOnCopy", stopOnCopy);
    model.put("logEntriesPage", logEntryWrappers);
    model.put("pageSize", pageSize);
    model.put("isFile", getRepositoryService().getNodeKind(repository, command.getPath(),
            command.getRevisionNumber()) == SVNNodeKind.FILE);
    model.put("morePages", logEntryWrappers.size() == pageSize);
    model.put("nextPath", nextPathParam);
    model.put("nextRevision", revNumber);
    return new ModelAndView(getViewName(), model);
}