user3433227
user3433227

Reputation: 11

Mapping list to Map not working

I have a map

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

and a list

[name1, name3]

I wanted a result as

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

The code used

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

Now the datatype of the name1 changed from Varchar2(35) to number(10).

I expected the same logic to work but it is not working and I am getting values

["name1":[null], "name3":[null]]

also the value such as 1000000959 is displayed as 1.000000959E9, is this making any difference ?

posting the original values

When I was handling with string, it looked as below

["FBUN-WEB-VIRGIN-10-24-08":["FIXEDLN_ALLOWANCE":0.0, "OFFER_VERSION_ID":1.000013082E9, "OFFER_TYPE_DESC":"Contract", "OFFER_NAME":"PM_V 10 50+250 CA", "SMS_ALLOWANCE":250.0, "VM_TARIFF_FLAG":"N", "IPHONE_IND":"N", "OFFER_MRC":10.5, "ALLOWANCE08":0.0, "DATA_ALLOWANCE":524288.0, "BB_IND":"N", "CONTRACT_TERM":24.0, "OFFER_CODE":"FBUN-WEB-VIRGIN-10-24-08", "ONNET_TEXT_ALLOWANCE":0.0, "VOICE_ALLOWANCE":50.0, "MMS_ALLOWANCE":0.0, "ONNET_ALLOWANCE":0.0],

Now after the database datatype changed to number from varchar it looks as below where the value in DB is 1000010315

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

Upvotes: 0

Views: 77

Answers (1)

tim_yates
tim_yates

Reputation: 171084

Now the datatype of the name1 changed from Varchar2(35) to number(10) ... also the value such as 1000000959 is displayed as 1.000000959E9, is this making any difference ?

Yes, all the difference in the world. That means you're converting a Double (most likely) to a String, and as the String "1000000959" is not equal to "1.000000959E9", you don't get a match.

Not sure from the question which bits are doubles and which bits are Strings... Maybe you could expand with an actual example?

Also, your inject method can be replaced with:

def result = tariffRecMap.subMap( recomendationOffers )

Upvotes: 1

Related Questions