Android Question IndexOf with Map as Argument

Discussion in 'Android Questions' started by lip, May 6, 2015.

  1. lip

    lip Active Member Licensed User

    I have a List of Maps (the result of parsing a JSON String).

    The Maps represent the two elements of the Primary Key of a SQLITE table eg:-

    List = (PKMap1, PKMap2, PKMap3, PKMap4)

    Where
    PKMap1: (ID=1, DeviceNo=6789)
    PKMap2: (ID=2, DeviceNo=6789)
    PKMap3: (ID=1, DeviceNo=7123)
    PKMap4: (ID=2,DeviceNo=7123)


    I want to check if another record exists in the List, say
    PKMap5: (ID=3, DeviceNo=6789)

    Q1) Can I use:-

    if List.IndexOf(PKMap5) = -1 then
    'UpLoad PKMap5

    Q2) If so, will the Map have to be in the same order?
    ie will (ID=3, DeviceNo=6789) Match (DeviceNo=6789, ID=3)

    Q3) If this stands a chance of working then I guess I will have to be careful how the various bits are Dim'ed to make sure that I am comparing Maps, and not pointers to Maps?
     
  2. LucaMs

    LucaMs Expert Licensed User

    Code:
    Dim m, m1 As Map
    m.Initialize
    m1.Initialize

    Dim lst As List : lst.Initialize

    m.Put(
    1"one")
    m.Put(
    2"two")
    lst.Add(m)

    m1.Put(
    3"three")
    m1.Put(
    4"four")
    lst.Add(m1)

    Log(lst.IndexOf(m1))

    m1.Put(
    "twenty"6)

    Log(lst.IndexOf(m1))
    logs:
    1
    1
     
  3. lip

    lip Active Member Licensed User

    BUT...

    m2.Put(2,"two")
    m2.Put(1,"one")

    Log(lst.IndexOf(m2) = -1

    The Order in which the Map Elements are added to the Map seem to affect whether the Map is found in the List?
     
  4. lip

    lip Active Member Licensed User


    BUT...

    m2.Put(2,"two")
    m2.Put(1,"one")

    Log(lst.IndexOf(m2) = -1

    The Order in which the Map Elements are added to the Map seem to affect whether the Map is found in the List?
     
  5. LucaMs

    LucaMs Expert Licensed User


    Have you forgotten to add m2 to the List?
    Code:
    Dim m, m1, m2 As Map
    m.Initialize
    m1.Initialize
    m2.Initialize

    Dim lst As List : lst.Initialize

    m.Put(
    1"one")
    m.Put(
    2"two")
    lst.Add(m)

    m1.Put(
    3"three")
    m1.Put(
    4"four")
    lst.Add(m1)

    Log("index of m1:" & lst.IndexOf(m1))

    m1.Put(
    "twenty"6)

    Log("index of m1:" & lst.IndexOf(m1))

    m2.Put(
    2,"two")
    m2.Put(
    1,"one")
    lst.Add(m2)

    Log("index of m2:" & lst.IndexOf(m2))
     
    DonManfred likes this.
  6. DonManfred

    DonManfred Expert Licensed User

    :D
     
    LucaMs likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice