public static CompoundDiff Diff(TagCompound first, TagCompound second) { CompoundDiff diff = new CompoundDiff(); foreach (var kv in first) { Tag firstValue = kv.Value; Tag secondValue = second.ContainsKey(kv.Key) ? second[kv.Key] : null; DiffOperation op = DiffValue(firstValue, secondValue); if (op != null) { diff.Operations[kv.Key] = op; } } foreach (var kv in second) { if (!first.ContainsKey(kv.Key)) { diff.Operations[kv.Key] = new ChangeOperation(kv.Value); } } return(diff); }
public static CompoundDiff IdDiff(TagList a, TagList b) { CompoundDiff diff = new CompoundDiff(); for (int i = 0; i < a.Count; i++) { object id = Id.GetId(a[i]); DiffOperation op = DiffValue(a[i], Id.FindObjectWithId(b, id)); if (op != null) { diff.Operations[id] = op; } } for (int i = 0; i < b.Count; i++) { object id = Id.GetId(b[i]); object aObject = Id.FindObjectWithId(a, id); if (aObject != null) { diff.Operations[id] = new ChangeOperation(b[i]); } } return(diff); }
public static CompoundDiff Merge(CompoundDiff left, CompoundDiff right) { // Find combined key list List <object> keys = left.Operations.Keys.ToList <object>(); foreach (var kv in right.Operations) { if (!left.Operations.ContainsKey(kv.Key)) { keys.Add(kv.Key); } } // Merge the operations for each key. CompoundDiff diff = new CompoundDiff(); foreach (object key in keys) { if (left.Operations.ContainsKey(key) && right.Operations.ContainsKey(key)) { diff.Operations[key] = DiffOperation.Merge(left.Operations[key], right.Operations[key]); } else if (left.Operations.ContainsKey(key)) { diff.Operations[key] = left.Operations[key]; } else if (right.Operations.ContainsKey(key)) { diff.Operations[key] = right.Operations[key]; } } return(diff); }
public static TagCompound Merge(TagCompound parent, TagCompound left, TagCompound right) { CompoundDiff leftDiff = Diff(parent, left); CompoundDiff rightDiff = Diff(parent, right); CompoundDiff diff = CompoundDiff.Merge(leftDiff, rightDiff); TagCompound res = parent.DeepCopy(); diff.Apply(res); return(res); }
private static DiffOperation DiffValue(Tag first, Tag second) { if (first == null && second == null) { return(null); } else if (second == null) { return(new RemoveOperation()); } else if (first == null) { return(new ChangeOperation(second)); } else if (first.TagType != second.TagType) { return(new ChangeOperation(second)); } else { switch (first.TagType) { case TagType.Byte: case TagType.Short: case TagType.Int: case TagType.Long: case TagType.Float: case TagType.Double: case TagType.String: case TagType.ByteArray: case TagType.IntArray: return(first.DataEqual(second) ? null : new ChangeOperation(second)); case TagType.Compound: CompoundDiff compDiff = Diff(first as TagCompound, second as TagCompound); return(compDiff.IsEmpty ? null : new ChangeObjectOperation(compDiff)); case TagType.List: if (AreIdArrays(first as TagList, second as TagList)) { CompoundDiff subDiff = IdDiff(first as TagList, second as TagList); return(subDiff.IsEmpty ? null : new ChangeIdArrayOperation(subDiff)); } else { ListDiff subDiff = PositionDiff(first as TagList, second as TagList); return(subDiff.IsEmpty ? null : new ChangePositionArrayOperation(subDiff)); } default: throw new Exception("Unexpected tag type"); } } }
public static TagCompound MergeDetailed(TagCompound parent, TagCompound left, TagCompound right, out CompoundDiff leftDiff, out CompoundDiff rightDiff, out CompoundDiff mergedDiff) { leftDiff = Diff(parent, left); rightDiff = Diff(parent, right); mergedDiff = CompoundDiff.Merge(leftDiff, rightDiff); TagCompound res = parent.DeepCopy(); mergedDiff.Apply(res); return(res); }
public static CompoundDiff Merge(CompoundDiff left, CompoundDiff right) { // Find combined key list List<object> keys = left.Operations.Keys.ToList<object>(); foreach (var kv in right.Operations) if (!left.Operations.ContainsKey(kv.Key)) keys.Add(kv.Key); // Merge the operations for each key. CompoundDiff diff = new CompoundDiff(); foreach (object key in keys) { if (left.Operations.ContainsKey(key) && right.Operations.ContainsKey(key)) diff.Operations[key] = DiffOperation.Merge(left.Operations[key], right.Operations[key]); else if (left.Operations.ContainsKey(key)) diff.Operations[key] = left.Operations[key]; else if (right.Operations.ContainsKey(key)) diff.Operations[key] = right.Operations[key]; } return diff; }
public static ChangeIdArrayOperation Merge(ChangeObjectOperation left, ChangeObjectOperation right) { return(new ChangeIdArrayOperation(CompoundDiff.Merge(left.Diff, right.Diff))); }
public ChangeIdArrayOperation(CompoundDiff diff) { Diff = diff; }
public ChangeObjectOperation(CompoundDiff diff) { Diff = diff; }
public ChangeObjectOperation(CompoundDiff diff) { Diff = diff; }
public ChangeIdArrayOperation(CompoundDiff diff) { Diff = diff; }
public static TagCompound MergeDetailed(TagCompound parent, TagCompound left, TagCompound right, out CompoundDiff leftDiff, out CompoundDiff rightDiff, out CompoundDiff mergedDiff) { leftDiff = Diff(parent, left); rightDiff = Diff(parent, right); mergedDiff = CompoundDiff.Merge(leftDiff, rightDiff); TagCompound res = parent.DeepCopy(); mergedDiff.Apply(res); return res; }
public static CompoundDiff IdDiff(TagList a, TagList b) { CompoundDiff diff = new CompoundDiff(); for (int i = 0; i < a.Count; i++) { object id = Id.GetId(a[i]); DiffOperation op = DiffValue(a[i], Id.FindObjectWithId(b, id)); if (op != null) diff.Operations[id] = op; } for (int i = 0; i < b.Count; i++) { object id = Id.GetId(b[i]); object aObject = Id.FindObjectWithId(a, id); if (aObject != null) diff.Operations[id] = new ChangeOperation(b[i]); } return diff; }
public static CompoundDiff Diff(TagCompound first, TagCompound second) { CompoundDiff diff = new CompoundDiff(); foreach (var kv in first) { Tag firstValue = kv.Value; Tag secondValue = second.ContainsKey(kv.Key) ? second[kv.Key] : null; DiffOperation op = DiffValue(firstValue, secondValue); if (op != null) diff.Operations[kv.Key] = op; } foreach (var kv in second) { if (!first.ContainsKey(kv.Key)) diff.Operations[kv.Key] = new ChangeOperation(kv.Value); } return diff; }