Add and get from ArrayList

  • Platform information: OH 2.5
    Dear community, my head will probably explode from the results of the rule. After initializing the array with values 1.1 (or any other), I read the floor temperature value from the rrd4j.persist database and write it to the array with the index of the corresponding minute (1200 is the number of minutes from midnight). In the same loop, I output the array value to the log. Then I just repeat reading the array into the log and get something completely different! How is this possible? Please help me!
    My code:
rule "TestTest1" 
when
    Item Niz_tochka1 received command ON
then
    var List<Double> theArrayX = newArrayList
    var int ii = 0
    while(ii <= 1441) {
        theArrayX.add(ii, 1.1)
        ii = ii + 1
    }

    var int NewIndA = 1
    var int NewIndB = 1200
    var Number TempProxy = 0.0
    var int ErrBASE = 0 

    while (NewIndB >= 0) {
        if (Temper_pol.historicState(now().minusMinutes(NewIndA)) !== null){
            TempProxy = Temper_pol.historicState(now().minusMinutes(NewIndA)).state as Number
                        
            theArrayX.add(NewIndB, TempProxy.doubleValue)
            logInfo("Minutes ", NewIndB.toString() + "; temperature from Array " + theArrayX.get(NewIndB).toString())
                        
            NewIndA = NewIndA + 1
            NewIndB = NewIndB - 1
            ErrBASE = 0
                    }
            else {
            theArrayX.add(NewIndB, TempProxy.doubleValue)
                NewIndA = NewIndA + 1
                NewIndB = NewIndB - 1
                logInfo("Err after evention else ", NewIndB.toString() + "; temperature from Array " + TtheArrayX.get(NewIndB).toString())
                ErrBASE = ErrBASE + 1
                if (ErrBASE >= 5) return;
            }
    } 

    ii = 1200
    while (ii >= 0) {
        logInfo("Minutes second read ", ii.toString() + "; temperature from Array " + theArrayX.get(ii).toString())
        ii = ii - 1
    }
end

My log:

2024-12-24 22:41:42.234 [INFO ] [ipse.smarthome.model.script.Minutes ] - 1200; temperature from Array 26.72949956258138
2024-12-24 22:41:42.235 [INFO ] [ipse.smarthome.model.script.Minutes ] - 1199; temperature from Array 26.69950075149536
2024-12-24 22:41:42.236 [INFO ] [ipse.smarthome.model.script.Minutes ] - 1198; temperature from Array 26.670000076293945
2024-12-24 22:41:42.236 [INFO ] [ipse.smarthome.model.script.Minutes ] - 1197; temperature from Array 26.669666735331216
2024-12-24 22:41:42.237 [INFO ] [ipse.smarthome.model.script.Minutes ] - 1196; temperature from Array 26.650332959493003
2024-12-24 22:41:42.238 [INFO ] [ipse.smarthome.model.script.Minutes ] - 1195; temperature from Array 26.669666735331216
...
2024-12-24 22:41:42.940 [INFO ] [me.model.script.Minutes second read ] - 1200; temperature from Array 26.930083640416463
2024-12-24 22:41:42.940 [INFO ] [me.model.script.Minutes second read ] - 1199; temperature from Array 1.1
2024-12-24 22:41:42.940 [INFO ] [me.model.script.Minutes second read ] - 1198; temperature from Array 26.9350004196167
2024-12-24 22:41:42.941 [INFO ] [me.model.script.Minutes second read ] - 1197; temperature from Array 1.1
2024-12-24 22:41:42.941 [INFO ] [me.model.script.Minutes second read ] - 1196; temperature from Array 26.9350004196167
2024-12-24 22:41:42.941 [INFO ] [me.model.script.Minutes second read ] - 1195; temperature from Array 1.1
2024-12-24 22:41:42.941 [INFO ] [me.model.script.Minutes second read ] - 1194; temperature from Array 26.9350004196167
2024-12-24 22:41:42.942 [INFO ] [me.model.script.Minutes second read ] - 1193; temperature from Array 1.1
2024-12-24 22:41:42.942 [INFO ] [me.model.script.Minutes second read ] - 1192; temperature from Array 26.9350004196167
2024-12-24 22:41:42.942 [INFO ] [me.model.script.Minutes second read ] - 1191; temperature from Array 1.1
2024-12-24 22:41:42.942 [INFO ] [me.model.script.Minutes second read ] - 1190; temperature from Array 26.95741712252299
2024-12-24 22:41:42.942 [INFO ] [me.model.script.Minutes second read ] - 1189; temperature from Array 1.1

I figured it out myself! It appears after initialization using the method .add to assign values to an array, use the .set method.