映射列表到Map无法正常工作

时间:2014-03-18 13:15:45

标签: groovy

我有一张地图

  

[" name1":[" field1":value1," field2":value2," field3":value3],   " name2":[" field1":value4," field2":value5," field3":value6],   " name3":[" field1":value7," field2":value8," field3":value9]]

和一个清单

  

[name1,name3]

我想要一个结果

  

[" name1":[" field1":value1," field2":value2," field3":value3],   " name3":[" field1":value7," field2":value8," field3":value9]]

使用的代码

result = recomendationOffers.inject( [:] ) { m, v ->
                if( !m[ v ] ) {
                    m[ v ] = []
                }
                m[ v ] << tariffRecMap[ v.toString() ]
                m
                }

现在,name1的数据类型已从Varchar2(35)更改为数字(10)。

我期望同样的逻辑可以工作,但它不起作用,我正在获得价值

  

[&#34; name1&#34;:[null],&#34; name3&#34;:[null]]

1000000959等值也显示为1.000000959E9,这有什么不同吗?

发布原始值

当我使用字符串处理时,它看起来如下

  

[&#34; FBUN-WEB-VIRGIN-08年10月24日&#34;:[&#34; FIXEDLN_ALLOWANCE&#34;:0.0,   &#34; OFFER_VERSION_ID&#34;:1.000013082E9,&#34; OFFER_TYPE_DESC&#34;:&#34;合同&#34;,   &#34; OFFER_NAME&#34;:&#34; PM_V 10 50 + 250 CA&#34;,&#34; SMS_ALLOWANCE&#34;:250.0,   &#34; VM_TARIFF_FLAG&#34;:&#34; N&#34;,&#34; IPHONE_IND&#34;:&#34; N&#34;,&#34; OFFER_MRC&#34;:10.5,   &#34; ALLOWANCE08&#34;:0.0,&#34; DATA_ALLOWANCE&#34;:524288.0,&#34; BB_IND&#34;:&#34; N&#34;,   &#34; CONTRACT_TERM&#34;:24.0,&#34; OFFER_CODE&#34;:&#34; FBUN-WEB-VIRGIN-10-24-08&#34;,   &#34; ONNET_TEXT_ALLOWANCE&#34;:0.0,&#34; VOICE_ALLOWANCE&#34;:50.0,   &#34; MMS_ALLOWANCE&#34;:0.0,&#34; ONNET_ALLOWANCE&#34;:0.0],

现在数据库数据类型从varchar更改为数字后,它看起来如下所示 DB中的值为1000010315

  

[1.000010315E9:[&#34; FIXEDLN_ALLOWANCE&#34;:0.0,   &#34; OFFER_VERSION_ID&#34;:1.000010315E9,&#34; OFFER_TYPE_DESC&#34;:&#34; Sup Voice&#34;,   &#34; OFFER_NAME&#34;:&#34; VIP - 35 c&#34;,&#34; SMS_ALLOWANCE&#34;:60000.0,   &#34; VM_TARIFF_FLAG&#34;:&#34; N&#34;,&#34; IPHONE_IND&#34;:&#34; N&#34;,&#34; OFFER_MRC&#34;:35.0,   &#34; ALLOWANCE08&#34;:45000.0,&#34; DATA_ALLOWANCE&#34;:2.147483648E9,&#34; BB_IND&#34;:&#34; N&#34;,   &#34; CONTRACT_TERM&#34;:24.0,&#34; OFFER_CODE&#34;:&#34; FBUN-MVP-WEB-VIRGIN-35-24-20&#34;,   &#34; ONNET_TEXT_ALLOWANCE&#34;:0.0,&#34; VOICE_ALLOWANCE&#34;:45000.0,   &#34; MMS_ALLOWANCE&#34;:0.0,&#34; ONNET_ALLOWANCE&#34;:0.0]

1 个答案:

答案 0 :(得分:1)

  

现在,name1的数据类型从Varchar2(35)更改为数字(10)...同样,1000000959等值显示为1.000000959E9,这有什么不同?

是的,世界上所有的差异。这意味着您要将Double(最有可能)转换为String,并且因为字符串"1000000959"不等于"1.000000959E9",您就不会将def result = tariffRecMap.subMap( recomendationOffers ) 转换为{{1}}。得到一个匹配。

从问题中不确定哪些位是双打以及哪些位是字符串...也许您可以使用实际示例进行扩展?

此外,您的注入方法可以替换为:

{{1}}