Christopher: Mit welcher programmiersprache/technik werde ich hier schneller

Beitrag lesen

Hi,

  

> for(int i=0;i<Controller.stations.size();i++)  
> {  
>     Tripel t=Controller.stations.get(i).tripel;  
>     if (t.n) {  
>         if (t.a!=-1 || t.b!=-1) {  
>             listNs.add(i);  
>         }  
>     } else {  
>         listOhneNs.add(i);  
>     }  
> }  

Sehr schön. Und dem Clean-Code-Pattern folgend, hier eine Lösung ohne verschachtelte Anweisungen und mit einem klareren Kontrollfluss (*):

  
for(int i=0;i<Controller.stations.size();i++)  
{  
    Tripel t=Controller.stations.get(i).tripel;  
  
    if (!t.n) {  
        listOhneNs.add(i);  
	continue;  
    }  
  
    if (t.a!=-1 || t.b!=-1) {  
        listNs.add(i);  
    }  
}  

Und als Einzeiler mittels Ternary-Operation, aber in der Tat schlechter lesbar (*):

  
for(int i=0;i<Controller.stations.size();i++)  
{  
    Tripel t=Controller.stations.get(i).tripel;  
    (!t.n) ? listOhneNs.add(i) : (t.a!=-1 || t.b!=-1) ? listNs.add(i) : continue;  
}  

MfG
Christopher

* uncompiled, untested