From 487b66dfa1ff87a517d3a7a14b01e8121475ff2c Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 7 Jul 2022 14:23:31 +0900 Subject: [PATCH] remove unused JsonDiff --- .../UniGLTF/Runtime/UniJSON/Json/JsonDiff.cs | 43 --------- .../Runtime/UniJSON/Json/JsonDiff.cs.meta | 12 --- .../UniJSON/ListTreeNode/ListTreeNode.cs | 90 ------------------- .../Tests/UniJSON/Json/JsonDiffTests.cs | 14 --- 4 files changed, 159 deletions(-) delete mode 100644 Assets/UniGLTF/Runtime/UniJSON/Json/JsonDiff.cs delete mode 100644 Assets/UniGLTF/Runtime/UniJSON/Json/JsonDiff.cs.meta diff --git a/Assets/UniGLTF/Runtime/UniJSON/Json/JsonDiff.cs b/Assets/UniGLTF/Runtime/UniJSON/Json/JsonDiff.cs deleted file mode 100644 index 20969c628..000000000 --- a/Assets/UniGLTF/Runtime/UniJSON/Json/JsonDiff.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; - -namespace UniJSON -{ - public enum JsonDiffType - { - KeyAdded, - KeyRemoved, - ValueChanged, - } - - public struct JsonDiff - { - public JsonPointer Path; - public JsonDiffType DiffType; - public string Msg; - - public static JsonDiff Create(JsonNode node, JsonDiffType diffType, string msg) - { - return new JsonDiff - { - Path = JsonPointer.Create(node), - DiffType = diffType, - Msg = msg, - }; - } - - public override string ToString() - { - switch (DiffType) - { - case JsonDiffType.KeyAdded: - return string.Format("+ {0}: {1}", Path, Msg); - case JsonDiffType.KeyRemoved: - return string.Format("- {0}: {1}", Path, Msg); - case JsonDiffType.ValueChanged: - return string.Format("= {0}: {1}", Path, Msg); - default: - throw new NotImplementedException(); - } - } - } -} diff --git a/Assets/UniGLTF/Runtime/UniJSON/Json/JsonDiff.cs.meta b/Assets/UniGLTF/Runtime/UniJSON/Json/JsonDiff.cs.meta deleted file mode 100644 index 3c221f2f4..000000000 --- a/Assets/UniGLTF/Runtime/UniJSON/Json/JsonDiff.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 97356eb7e23aca64c84f836d6c298f43 -timeCreated: 1543427903 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniGLTF/Runtime/UniJSON/ListTreeNode/ListTreeNode.cs b/Assets/UniGLTF/Runtime/UniJSON/ListTreeNode/ListTreeNode.cs index 9ce9d1892..fffb72146 100644 --- a/Assets/UniGLTF/Runtime/UniJSON/ListTreeNode/ListTreeNode.cs +++ b/Assets/UniGLTF/Runtime/UniJSON/ListTreeNode/ListTreeNode.cs @@ -197,96 +197,6 @@ namespace UniJSON return string.Join("", ToString(indent, 0).ToArray()); } - public IEnumerable Diff(JsonNode rhs, JsonPointer path = default(JsonPointer)) - { - switch (Value.ValueType) - { - case ValueNodeType.Null: - case ValueNodeType.Boolean: - case ValueNodeType.Number: - case ValueNodeType.Integer: - case ValueNodeType.String: - if (!Equals(rhs)) - { - yield return JsonDiff.Create(this, JsonDiffType.ValueChanged, string.Format("{0} => {1}", Value, rhs.Value)); - } - yield break; - } - - if (Value.ValueType != rhs.Value.ValueType) - { - yield return JsonDiff.Create(this, JsonDiffType.ValueChanged, string.Format("{0} => {1}", Value.ValueType, rhs.Value)); - yield break; - } - - if (Value.ValueType == ValueNodeType.Object) - { - - var l = this.ObjectItems().ToDictionary(x => x.Key, x => x.Value); - var r = rhs.ObjectItems().ToDictionary(x => x.Key, x => x.Value); - - foreach (var kv in l) - { - JsonNode x; - if (r.TryGetValue(kv.Key, out x)) - { - r.Remove(kv.Key); - // Found - foreach (var y in kv.Value.Diff(x)) - { - yield return y; - } - } - else - { - // Removed - yield return JsonDiff.Create(kv.Value, JsonDiffType.KeyRemoved, kv.Value.Value.ToString()); - } - } - - foreach (var kv in r) - { - // Added - yield return JsonDiff.Create(kv.Value, JsonDiffType.KeyAdded, kv.Value.Value.ToString()); - } - } - else if (Value.ValueType == ValueNodeType.Array) - { - var ll = this.ArrayItems().GetEnumerator(); - var rr = rhs.ArrayItems().GetEnumerator(); - while (true) - { - var lll = ll.MoveNext(); - var rrr = rr.MoveNext(); - if (lll && rrr) - { - // found - foreach (var y in ll.Current.Diff(rr.Current)) - { - yield return y; - } - } - else if (lll) - { - yield return JsonDiff.Create(ll.Current, JsonDiffType.KeyRemoved, ll.Current.Value.ToString()); - } - else if (rrr) - { - yield return JsonDiff.Create(rr.Current, JsonDiffType.KeyAdded, rr.Current.Value.ToString()); - } - else - { - // end - break; - } - } - } - else - { - throw new NotImplementedException(); - } - } - /// /// Whole tree nodes /// diff --git a/Assets/UniGLTF/Tests/UniJSON/Json/JsonDiffTests.cs b/Assets/UniGLTF/Tests/UniJSON/Json/JsonDiffTests.cs index 87cac1906..f36542f5d 100644 --- a/Assets/UniGLTF/Tests/UniJSON/Json/JsonDiffTests.cs +++ b/Assets/UniGLTF/Tests/UniJSON/Json/JsonDiffTests.cs @@ -42,20 +42,6 @@ namespace UniJSON } } - [Test] - public void DiffTest() - { - var a = @"{ -""a"": 1 -}"; - - var b = @"{ -}"; - - var diff = JsonParser.Parse(a).Diff(JsonParser.Parse(b)).ToArray(); - Assert.AreEqual(1, diff.Length); - } - #if UNITY_EDITOR [Test] public void Vector3()