Esempio n. 1
0
        public void AssignCutItemToStick(CutItem cutItem)  // this is like a push (or store) in a push-pop scenario;
        {
            if (StickCollection.Capacity <= 0)
            {
                StickCollection.Add(new Stick(_stickLength));
            }

            var stickIsPlaced = false;

            foreach (var stick in StickCollection)
            {
                // assigning the condition to the variable is self-describing code; here it describes the intent w/o a comment per-se
                var cutItemWillFitInStick = (cutItem.CutItemLength <= stick.RemainingSpace); // if it fits it ships
                if (cutItemWillFitInStick)
                {
                    stick.AddCutItemToStick(cutItem);
                    stickIsPlaced = true;
                    break;
                }
            }

            if (!stickIsPlaced)
            {
                var freshStick = new Stick(_stickLength);
                if (cutItem.CutItemLength <= freshStick.RemainingSpace)
                {
                    freshStick.AddCutItemToStick(cutItem);
                    StickCollection.Add(freshStick);
                    stickIsPlaced = true;
                }
            }

            /*
             * todo: Unassigned CutItems; what if the cut is too large for the stick????
             * Example 18 foot cut for a 16 foot stick.
             */
            if (!stickIsPlaced)
            {
                UnassignedCutItems.Add(cutItem);
                stickIsPlaced = true;
            }
        }
Esempio n. 2
0
 public void AddCutItemToStick(CutItem cutItem)
 {
     CutItemCollection.Add(cutItem);
 }