Android Question Code smells

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Had a look at Erel's posting Code smells:
and looked at GetKeyAt and GetValue at of Map.

I take it that if we are only interested in the key or value at one particular index we have to do something like this (although it looks inefficient):

B4X:
Sub GetMapKeyAt(oMap As Map, iIndex As Int) As Object

Dim i As Int

For Each oKey As Object In oMap.Keys
If i = iIndex Then
Return oKey
End If
i = i + 1
Next

Return Null

End Sub
Sub GetMapValueAt(oMap As Map, iIndex As Int) As Object

Dim i As Int

For Each oValue As Object In oMap.Values
If i = iIndex Then
Return oValue
End If
i = i + 1
Next

Return Null

End Sub
[CODE/]


RBS
 

tchart

Well-Known Member
Licensed User
Longtime User
Yeah I was a bit surprised that Map.GetKeyAt / GetValueAt are to be deprecated.

I use these often, especially for returning chart data (x,y) from the database as a map.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I think that the only reason is:
They are not cross platform

Because (again an Erel' statement):
Note that in most implementations of maps the order is not preserved. In most use cases the order is not important.
The order in B4A and B4J maps is preserved. This is not the case in B4i.


Also, given that:
B4XOrderedMap - Similar to a Map with two advantages:

1. The order of items is preserved. This is the case with regular Maps in B4A and B4J as well, however not the case with B4i regular Maps.

2. You can sort the items based on the keys.
and that it is part of a b4xlib (which means that you have the source code), I think it is a good "practice" to use that library.

Anyway, you can still use those properties (when working with B4A or B4J), of course, "deprecated" does not mean "prohibited".
 
Last edited:
Upvote 0
Top