Example #1
0
        public void AddBox(Box box)
        {
            var xTreeNode = boxTree.Search(box.X, out BinarySearchTreeNode <YTree> xFather);

            if (xTreeNode != null)
            {
                var yTreeNode = xTreeNode.Value.Search(box.Y, out BinarySearchTreeNode <LinkedTreeBox> yFather);
                if (yTreeNode != null)
                {
                    yTreeNode.Value.BoxNode.Value.Quantity += box.Quantity;
                    dataBase.Save();
                }
                else
                {
                    box.LastTimeBought = DateTimeOffset.Now;

                    boxesByDate.AddLast(box);              // Add to Linked List
                    var newNode = new LinkedTreeBox();
                    newNode.BoxNode = boxesByDate.EndNode; // Take it from LinkedList

                    if (yFather == null)
                    {
                        xTreeNode.Value.Add(newNode);                  // Add to tree
                    }
                    else
                    {
                        xTreeNode.Value.Add(yFather, newNode);
                    }

                    dataBase.AddBox(box); // Add to database
                }
            }
            else
            {
                box.LastTimeBought = DateTimeOffset.Now;

                boxesByDate.AddLast(box);              // Add to Linked List
                var newNode = new LinkedTreeBox();
                newNode.BoxNode = boxesByDate.EndNode; // Take it from LinkedList

                var newYTree = new YTree(box.X);       // Create new Y Tree
                newYTree.Add(newNode);                 // Add to Y Tree

                if (xFather != null)
                {
                    boxTree.Add(xFather, newYTree);                  // Add to tree
                }
                else
                {
                    boxTree.Add(newYTree);
                }

                dataBase.AddBox(box); // Add to database
            }
        }
Example #2
0
 public int CompareTo(YTree other) => this.X.CompareTo(other.X);