public EndemeObject this[EndemeActuator enAct] {
     get { EndemeDefinition def = By(enAct); if (def.Count > 0)
           {
               return(def[0]);
           }
           else
           {
               return(EndemeObject.Empty);
           } }
 }
 public EndemeDefinition When(EndemeActuator actuator)
 {
     return(By(actuator));
 }
        // ----------------------------------------------------------------------------------------
        /// <!-- By -->
        /// <summary>
        ///      Returns a list of endeme objects by one or more of (filter, order, group?)
        /// </summary>
        /// <param name="actuator"></param>
        /// <returns></returns>
        /// <remarks>
        ///      algortihm:
        ///
        ///      - Go through each HasChar factor and look to see if that is covered by the item profile
        ///         - Look to see if each hashchar factor is covered by the item profile
        /// </remarks>
        public EndemeDefinition By(EndemeActuator actuator)
        {
            actuator.InitWeights();

            EndemeDefinition output = new EndemeDefinition(this.Label + "_" + actuator.ToString(), this.EnRef);


            // --------------------------------------------------------------------------
            //  Go through each item and see whether to add it to the out put list
            // --------------------------------------------------------------------------
            foreach (EndemeObject item in _list.Values)
            {
                // ----------------------------------------------------------------------
                //  Check whether the item's profile covers all of the HasChar factors
                // ----------------------------------------------------------------------
                double charMatch = actuator.HasChar.CharMatch(item.ItemProfile);


                double setMatch = actuator.HasSets.SetMatch(item.ItemProfile);


                double orderMatch = actuator.Ordered.OrderMatch(item.ItemProfile);


                // ----------------------------------------------------------------------
                //  Check for (AND) all the defined value factors
                // ----------------------------------------------------------------------
                bool valFound = true;
                if (charMatch > -0.5 && setMatch > -0.5 && orderMatch > -0.5)
                {
                    foreach (ValueFactor val in actuator.HasVals)
                    {
                        valFound &= val.FoundInProfile(item.ItemProfile.Segment);
                    }
                }


                // ----------------------------------------------------------------------
                //  Check for (OR) all the weight factors
                // ----------------------------------------------------------------------
                double weightMatch = 1.0;
                if (charMatch > -0.5 && setMatch > -0.5 && orderMatch > -0.5)
                {
                    foreach (WeightFactor wgt in actuator.Weights)
                    {
                        double factorWeight = wgt.CalculateFactorWeight(item.ItemProfile.Segment);
                        double normalized   = (factorWeight - wgt.WorstMatch) / (wgt.BestMatch - wgt.WorstMatch);
                        weightMatch *= normalized;
                    }
                }


                // ----------------------------------------------------------------------
                //  Add the item if its profile covers all of the defined factor groups
                // ----------------------------------------------------------------------
                if (charMatch > -0.5 && setMatch > -0.5 && orderMatch > -0.5 && valFound)
                {
                    EndemeObject copy = item.Copy();
                    copy.TempMatch = charMatch + weightMatch;
                    output.Add(copy);
                }
            }


            // --------------------------------------------------------------------------
            //  Order output by weight
            // --------------------------------------------------------------------------
            if (output.Count > 1)
            {
                return(output.SortedCopy());
            }
            else
            {
                return(output);
            }
        }