예제 #1
0
 /// <summary>
 /// Removes neighbouring node
 /// </summary>
 /// <param name="node">Neighbour to remove</param>
 public void RemoveNeighbour(Node node)
 {
     if (node == null)
         throw new ArgumentNullException(nameof(node));
     var match = Neighbours.SingleOrDefault(n => node.Equals(n));
     //Prevent endless circular removing
     if (match == null)
         return;
     if (!CanRemoveNeighbour(node))
         throw new InvalidOperationException("Neighbour cannot be removed!");
     Neighbours.Remove(match);
     match.RemoveNeighbour(this);
 }
예제 #2
0
 /// <summary>
 /// Adds neighbouring node. Will fail if not added via <see cref="T:Localwire.Graphinder.Core.Graph.Graph"/>.
 /// </summary>
 /// <param name="node">New neighbour to add</param>
 public void AddNeighbour(Node node)
 {
     if (node == null)
         throw new ArgumentNullException(nameof(node));
     //Prevent endless circular adding
     if (Neighbours.Contains(node))
         return;
     if (node.Equals(this))
         throw new InvalidOperationException("Attempt to add self as neighbour!");
     if (!CanAddNeighbour(node))
         throw new InvalidOperationException("Neighbour cannot be added!");
     Neighbours.Add(node);
     node.AddNeighbour(this);
 }
예제 #3
0
        /// <summary>
        /// Removes neighbouring node
        /// </summary>
        /// <param name="node">Neighbour to remove</param>
        public void RemoveNeighbour(Node node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }
            var match = _neighbours.SingleOrDefault(n => node.Equals(n));

            //Prevent endless circular removing
            if (match == null)
            {
                return;
            }
            if (!CanRemoveNeighbour(node))
            {
                throw new InvalidOperationException("Neighbour cannot be removed!");
            }
            _neighbours.Remove(match);
            match.RemoveNeighbour(this);
        }
예제 #4
0
 /// <summary>
 /// Adds neighbouring node. Will fail if not added via <see cref="T:Localwire.Graphinder.Core.Graph.Graph"/>.
 /// </summary>
 /// <param name="node">New neighbour to add</param>
 public void AddNeighbour(Node node)
 {
     if (node == null)
     {
         throw new ArgumentNullException(nameof(node));
     }
     //Prevent endless circular adding
     if (_neighbours.Contains(node))
     {
         return;
     }
     if (node.Equals(this))
     {
         throw new InvalidOperationException("Attempt to add self as neighbour!");
     }
     if (!CanAddNeighbour(node))
     {
         throw new InvalidOperationException("Neighbour cannot be added!");
     }
     _neighbours.Add(node);
     node.AddNeighbour(this);
 }