Search in sources :

Example 1 with BytesPair

use of suite.text.TextUtil.BytesPair in project suite by stupidsing.

the class Impl method diffMaps.

private Map<String, List<BytesPair>> diffMaps(Map<String, Bytes> map0, Map<String, Bytes> map1) {
    var keys = Union.of(map0.keySet(), map1.keySet());
    var diffMap = new HashMap<String, List<BytesPair>>();
    for (var key : keys) {
        var bytes0 = map0.get(key);
        var bytes1 = map1.get(key);
        if (bytes0 == null || bytes1 == null)
            diffMap.put(key, List.of(new BytesPair(bytes0, bytes1)));
        else {
            var diff = textUtil.diff(bytes0, bytes1);
            if (textUtil.isDiff(diff))
                diffMap.put(key, diff);
        }
    }
    return diffMap;
}
Also used : HashMap(java.util.HashMap) BytesPair(suite.text.TextUtil.BytesPair)

Example 2 with BytesPair

use of suite.text.TextUtil.BytesPair in project suite by stupidsing.

the class Impl method readPatch.

public List<BytesPair> readPatch(InputStream is) {
    var list = new ArrayList<BytesPair>();
    String line;
    while (!Equals.string(line = ReadLine.from(is), "EOF")) list.add(FixieArray.of(line.split(" ")).map((f, s0, s1) -> ex(() -> {
        var size0 = !Equals.string(s0, "N") ? Integer.valueOf(s0) : null;
        var size1 = !Equals.string(s1, "N") ? Integer.valueOf(s1) : null;
        Bytes bs0, bs1;
        if (Equals.string("!", f)) {
            bs0 = readBlock(is, size0, '<');
            bs1 = readBlock(is, size1, '>');
        } else
            bs0 = bs1 = readBlock(is, size0, '=');
        return new BytesPair(bs0, bs1);
    })));
    return list;
}
Also used : Bytes(primal.primitive.adt.Bytes) ArrayList(java.util.ArrayList) BytesPair(suite.text.TextUtil.BytesPair)

Aggregations

BytesPair (suite.text.TextUtil.BytesPair)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Bytes (primal.primitive.adt.Bytes)1