Package difflib

Examples of difflib.Patch


        if (orig == null)
            throw new IllegalArgumentException("original sequence is null");
        if (rev == null)
            throw new IllegalArgumentException("revised sequence is null");
       
        Patch patch = new Patch();
        if (path.isSnake())
            path = path.prev;
        while (path != null && path.prev != null && path.prev.j >= 0) {
            if (path.isSnake())
                throw new IllegalStateException("bad diffpath: found snake when looking for diff");
            int i = path.i;
            int j = path.j;
           
            path = path.prev;
            int ianchor = path.i;
            int janchor = path.j;
           
            Chunk original = new Chunk(ianchor, i - ianchor, copyOfRange(orig, ianchor, i));
            Chunk revised = new Chunk(janchor, j - janchor, copyOfRange(rev, janchor, j));
            Delta delta = null;
            if (original.getSize() == 0 && revised.getSize() != 0) {
                delta = new InsertDelta(original, revised);
            } else if (original.getSize() > 0 && revised.getSize() == 0) {
                delta = new DeleteDelta(original, revised);
            } else {
                delta = new ChangeDelta(original, revised);
            }
           
            patch.addDelta(delta);
            if (path.isSnake())
                path = path.prev;
        }
        return patch;
    }
View Full Code Here


    public static int getDiffScore(String one, String two) {
        List<String> first = Arrays.asList(one.split("[\\n\\ ]+"));
        List<String> second = Arrays.asList(two.split("[\\n\\ ]+"));

        Patch p = DiffUtils.diff(first, second);
        return p.getDeltas().size();
    }
View Full Code Here

TOP

Related Classes of difflib.Patch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.