Example #1
0
        private LinkedList <PurchasePolicy> parseTwoComplex(IEnumerable <PolicyEntry> policyEntries)
        {
            LinkedList <PurchasePolicy> policyList = new LinkedList <PurchasePolicy>();
            ComplexPurchasePolicy       compParent = null;
            ComplexPurchasePolicy       compChild  = null;
            int compParentPos  = -1;
            int compChildPos   = -1;
            int idRegularChild = -1;
            int id1Child       = -1;
            int id2Child       = -1;

            for (int i = 0; i < policyEntries.Count(); i++)
            {
                if (policyEntries.ElementAt(i).getType() == "complex" && policyEntries.ElementAt(i).getIsPartOfComp())
                {
                    compChildPos = i;
                    id1Child     = policyEntries.ElementAt(i).getSubID1();
                    id2Child     = policyEntries.ElementAt(i).getSubID2();
                }
                else if (policyEntries.ElementAt(i).getType() == "complex" && !policyEntries.ElementAt(i).getIsPartOfComp())
                {
                    compParentPos = i;
                }
            }
            PurchasePolicy child1 = null;
            PurchasePolicy child2 = null;

            for (int i = 0; i < policyEntries.Count(); i++)
            {
                PolicyEntry p = policyEntries.ElementAt(i);
                if (p.getPolicyID() == id1Child)
                {
                    child1 = parseRegular(p);
                }
                else if (p.getPolicyID() == id2Child)
                {
                    child2 = parseRegular(p);
                }
                else if (p.getPolicyID() != id1Child & p.getPolicyID() != id2Child && p.getPolicyID() != compChildPos)
                {
                    idRegularChild = i;
                }
            }

            compChild = new ComplexPurchasePolicy(policyEntries.ElementAt(compChildPos).getCompType(), child1, child2, policyEntries.ElementAt(compChildPos).getPolicyID());
            PurchasePolicy regularChild = parseRegular(policyEntries.ElementAt(idRegularChild));

            compParent = new ComplexPurchasePolicy(policyEntries.ElementAt(compParentPos).getCompType(), compChild, regularChild, policyEntries.ElementAt(compParentPos).getPolicyID());

            policyList.AddLast(compParent);
            return(policyList);
        }
Example #2
0
 public PurchasePolicy parseRegular(PolicyEntry p)
 {
     if (p.getType() == "min")
     {
         MinAmountPurchase policy = new MinAmountPurchase(p.getAmount(), p.getPolicyID());
         return(policy);
     }
     else if (p.getType() == "max")
     {
         MaxAmountPurchase policy = new MaxAmountPurchase(p.getAmount(), p.getPolicyID());
         return(policy);
     }
     else
     {
         TotalPricePolicy policy = new TotalPricePolicy(p.getAmount(), p.getPolicyID());
         return(policy);
     }
 }