简体   繁体   English

比较两个嵌套的哈希图

[英]Comparing two nested hashmaps

I have two nested hashmaps of the following structure(levels of nesting can vary) The nested values can be instances of maps or arrays of maps. 我有以下结构的两个嵌套哈希图(嵌套的级别可以变化)嵌套的值可以是map的实例或map的数组。

{

  key1:[

    {

      nkey1:[

        nval1,
        nval2
      ]
    },
    {

      nkey2:[

        nval3,
        nval4
      ]
    }
  ]
}

Currently I am doing an equals operation on two maps, which expects all keys to be identical. 目前,我正在两张地图上执行相等操作,期望所有键都相同。 I want to exclude certain keys while comparison. 我想在比较时排除某些键。

Say I should say I want to exclude key1::nkey2. 说我应该说要排除key1 :: nkey2。 How Do I accomplish this? 我该如何完成? A map.keySet() does not help with nested maps. map.keySet()不适用于嵌套地图。 How do I efficiently do a key by key comparison walking over this nested map? 如何在此嵌套地图上进行逐个键比较的有效操作?

You can flatten your map, ie include folded keys into main map. 您可以展平地图,即在主地图中包含折叠键。 For your example you would have keys: 对于您的示例,您将具有以下密钥:

"key1"
"key1:nkey1"
"key1:nkey2"

In this case you won't need to use deep equals on each key, since all the levels would be eventually checked anyway. 在这种情况下,您无需在每个键上使用深等于,因为无论如何最终都会检查所有级别。 And you could remove any keys you want while traversing a single keySet(). 您可以在遍历单个keySet()时删除所需的任何键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM