/* Fast filtering code which works off the data, rather than the visual elements.
         * Suboptimal due to potential desyncs with normal filter proceedure, but simply required for performance */
        public List <ListElementController_BASE_NotListView> Filter(List <ListElementController_BASE_NotListView> _items)
        {
            var items = Sort(_items);

            var iw = new Traverse(inventoryWidget);
            Func <string, bool> f = (n) => iw.Field(n).GetValue <bool>();
            var filter            = new InventoryFilter(false //this.filteringAll
                                                        , f("filteringWeapons")
                                                        , f("filterEnabledWeaponBallistic")
                                                        , f("filterEnabledWeaponEnergy")
                                                        , f("filterEnabledWeaponMissile")
                                                        , f("filterEnabledWeaponSmall")
                                                        , f("filteringEquipment")
                                                        , f("filterEnabledHeatsink")
                                                        , f("filterEnabledJumpjet")
                                                        , iw.Field("mechTonnage").GetValue <float>()
                                                        , f("filterEnabledUpgrade")
                                                        , false);

            InventoryDataObject_BASE tmpctl = new InventoryDataObject_InventoryWeapon();

            var current = items.Where(item => {
                tmpctl.weaponDef    = null;
                tmpctl.ammoBoxDef   = null;
                tmpctl.componentDef = null;
                var def             = item.componentDef;
                switch (def.ComponentType)
                {
                case ComponentType.Weapon:
                    tmpctl.weaponDef = def as WeaponDef;
                    break;

                case ComponentType.AmmunitionBox:
                    tmpctl.ammoBoxDef = def as AmmunitionBoxDef;
                    break;

                case ComponentType.HeatSink:
                case ComponentType.MechPart:
                case ComponentType.JumpJet:
                case ComponentType.Upgrade:
                    tmpctl.componentDef = def;
                    break;
                }
                Func <string> Summary = () =>
                {
                    var o    = "";
                    o       += "filteringWeapons? " + f("filteringWeapons") + "\n";
                    o       += "filterEnabledWeaponBallistic? " + f("filterEnabledWeaponBallistic") + "\n";
                    o       += "filterEnabledWeaponEnergy? " + f("filterEnabledWeaponEnergy") + "\n";
                    o       += "filterEnabledWeaponMissile? " + f("filterEnabledWeaponMissile") + "\n";
                    o       += "filterEnabledWeaponSmall? " + f("filterEnabledWeaponSmall") + "\n";
                    o       += "filteringEquipment? " + f("filteringEquipment") + "\n";
                    o       += "filterEnabledHeatsink? " + f("filterEnabledHeatsink") + "\n";
                    o       += "filterEnabledJumpjet? " + f("filterEnabledJumpjet") + "\n";
                    o       += "mechTonnage? " + iw.Field("mechTonnage").GetValue <float>() + "\n";
                    o       += "filterEnabledUpgrade? " + f("filterEnabledUpgrade") + "\n";
                    o       += $"weaponDef? {tmpctl.weaponDef}\n";
                    o       += $"ammoboxDef? {tmpctl.ammoBoxDef}\n";
                    o       += $"componentDef? {tmpctl.componentDef}\n";
                    o       += $"ComponentDefType? {tmpctl.componentDef?.ComponentType}\n";
                    o       += $"componentDefCSType? {tmpctl.componentDef?.GetType()?.FullName}\n";
                    var json = Trap(() => new Traverse(tmpctl.componentDef).Method("ToJSON").GetValue <string>());
                    o       += "JSON: " + json;
                    return(o);
                };

                var yes = Trap(() => filter.Execute(Enumerable.Repeat(tmpctl, 1)).Any()
                               , () => { LogError($"Filtering failed\n{Summary()}\n\n"); return(false); });
                if (!yes)
                {
                    LogDebug(string.Format("[Filter] Removing :id {0} :componentType {1} :quantity {2}", def.Description.Id, def.ComponentType, item.quantity));
                }
                return(yes);
            }).ToList();

            return(current);
        }
        /* Fast filtering code which works off the data, rather than the visual elements.
         * Suboptimal due to potential desyncs with normal filter proceedure, but simply required for performance */
        public List <ListElementController_BASE_NotListView> Filter(List <ListElementController_BASE_NotListView> _items)
        {
            var items = Sort(_items);

            var filter = new InventoryFilter(allAllowed: false  //this.filteringAll
                                             , weaponsAllowed: inventoryWidget.filteringWeapons
                                             , weaponsBallisticAllowed: inventoryWidget.filterEnabledWeaponBallistic
                                             , weaponsEnergyAllowed: inventoryWidget.filterEnabledWeaponEnergy
                                             , weaponsMissileAllowed: inventoryWidget.filterEnabledWeaponMissile
                                             , weaponsPersonnelAllowed: inventoryWidget.filterEnabledWeaponSmall
                                             , gearAllowed: inventoryWidget.filteringEquipment
                                             , gearHeatSinksAllowed: inventoryWidget.filterEnabledHeatsink
                                             , gearJumpJetsAllowed: inventoryWidget.filterEnabledJumpjet
                                             , mechTonnageForJumpJets: inventoryWidget.mechTonnage
                                             , gearUpgradesAllowed: inventoryWidget.filterEnabledUpgrade
                                             , mechsAllowed: false
                                             , ammoAllowed: true);

            InventoryDataObject_BASE tmpctl = new InventoryDataObject_InventoryWeapon();

            var current = items.Where(item => {
                tmpctl.weaponDef    = null;
                tmpctl.ammoBoxDef   = null;
                tmpctl.componentDef = null;
                var def             = item.componentDef;
                switch (def.ComponentType)
                {
                case ComponentType.Weapon:
                    tmpctl.weaponDef = def as WeaponDef;
                    break;

                case ComponentType.AmmunitionBox:
                    tmpctl.ammoBoxDef = def as AmmunitionBoxDef;
                    break;

                case ComponentType.HeatSink:
                case ComponentType.MechPart:
                case ComponentType.JumpJet:
                case ComponentType.Upgrade:
                    tmpctl.componentDef = def;
                    break;
                }
                Func <string> Summary = () =>
                {
                    var o    = "";
                    o       += "filteringWeapons? " + inventoryWidget.filteringWeapons + "\n";
                    o       += "filterEnabledWeaponBallistic? " + inventoryWidget.filterEnabledWeaponBallistic + "\n";
                    o       += "filterEnabledWeaponEnergy? " + inventoryWidget.filterEnabledWeaponEnergy + "\n";
                    o       += "filterEnabledWeaponMissile? " + inventoryWidget.filterEnabledWeaponMissile + "\n";
                    o       += "filterEnabledWeaponSmall? " + inventoryWidget.filterEnabledWeaponSmall + "\n";
                    o       += "filteringEquipment? " + inventoryWidget.filteringEquipment + "\n";
                    o       += "filterEnabledHeatsink? " + inventoryWidget.filterEnabledHeatsink + "\n";
                    o       += "filterEnabledJumpjet? " + inventoryWidget.filterEnabledJumpjet + "\n";
                    o       += "mechTonnage? " + inventoryWidget.mechTonnage + "\n";
                    o       += "filterEnabledUpgrade? " + inventoryWidget.filterEnabledUpgrade + "\n";
                    o       += $"weaponDef? {tmpctl.weaponDef}\n";
                    o       += $"ammoboxDef? {tmpctl.ammoBoxDef}\n";
                    o       += $"componentDef? {tmpctl.componentDef}\n";
                    o       += $"ComponentDefType? {tmpctl.componentDef?.ComponentType}\n";
                    o       += $"componentDefCSType? {tmpctl.componentDef?.GetType()?.FullName}\n";
                    var json = Trap(() => tmpctl.componentDef.ToJSON());
                    o       += "JSON: " + json;
                    return(o);
                };

                var yes = Trap(() => filter.Execute(Enumerable.Repeat(tmpctl, 1)).Any()
                               , () => { LogError($"Filtering failed\n{Summary()}\n\n"); return(false); });
                if (!yes)
                {
                    LogDebug(string.Format("[Filter] Removing :id {0} :componentType {1} :quantity {2}", def.Description.Id, def.ComponentType, item.quantity));
                }
                return(yes);
            }).ToList();

            return(current);
        }