package org.ovirt.engine.core.bll;

import java.util.List;

import org.ovirt.engine.core.common.businessentities.VdsNetworkInterface;
import org.ovirt.engine.core.common.queries.GetVdsByVdsIdParameters;
import org.ovirt.engine.core.compat.StringHelper;
import org.ovirt.engine.core.utils.linq.LinqUtils;
import org.ovirt.engine.core.utils.linq.Predicate;

public class GetVdsInterfacesByVdsIdQuery<P extends GetVdsByVdsIdParameters> extends QueriesCommandBase<P> {
    public GetVdsInterfacesByVdsIdQuery(P parameters) {
        super(parameters);
    }

    @Override
    protected void executeQueryCommand() {
        final List<VdsNetworkInterface> list = getDbFacade().getInterfaceDAO()
                .getAllInterfacesForVds(getParameters().getVdsId(), getUserID(), getParameters().isFiltered());

        // 1. here we return all interfaces (eth0, eth1, eth2) - the first
        // condition
        // 2. we also return bonds that connected to network and has interfaces
        // - the second condition
        // i.e.
        // we have:
        // Network | Interface
        // -------------------
        // red-> |->eth0
        // |->eth1
        // | |->eth2
        // blue-> |->bond0->|->eth3
        // |->bond1
        //
        // we return: eth0, eth1, eth2, eth3, bond0
        // we don't return bond1 because he is not connected to network and has
        // no child interfaces

        List<VdsNetworkInterface> interfaces = LinqUtils.filter(list, new Predicate<VdsNetworkInterface>() {
            @Override
            public boolean eval(final VdsNetworkInterface i) {
                return (i.getBonded() == null || (i.getBonded() != null && i.getBonded())
                        && LinqUtils.filter(list, new Predicate<VdsNetworkInterface>() {
                            @Override
                            public boolean eval(VdsNetworkInterface bond) {
                                return StringHelper.EqOp(bond.getBondName(), i.getName());
                            }
                        }).size() > 0);

            }
        });

        getQueryReturnValue().setReturnValue(interfaces);
    }
}

@@ -29,16 +29,44 @@
 e.bll;%0A%0A
+import java.util.ArrayList;%0A
 import j
@@ -1480,123 +1480,69 @@
 s = 
-LinqUtils.filter(list, new Predicate%3CVdsNetworkInterface%3E() %7B%0A            @Override%0A            public boolean eval
+new ArrayList%3CVdsNetworkInterface%3E(list.size());%0A        for 
 (fin
@@ -1565,16 +1565,23 @@
 erface i
+ : list
 ) %7B%0A    
@@ -1588,26 +1588,18 @@
         
-    return
+if
  (i.getB
@@ -2020,18 +2020,53 @@
 e() %3E 0)
+ %7B%0A                interfaces.add(i)
 ;
-%0A
 %0A       
@@ -2081,18 +2081,16 @@
        %7D
-);
 %0A%0A      

Change query to iterate using foreach