Example #1
0
        /// <summary>
        /// Determines whether the specified System.Object is equal to the current System.Object.
        /// </summary>
        /// <param name="obj">The System.Object to compare with the current System.Object.</param>
        /// <returns>true if the specified System.Object is equal to the current System.Object; otherwise, false.</returns>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }

            if (obj == null)
            {
                return(false);
            }

            GraphEdge <E, N> edge = obj as GraphEdge <E, N>;

            if (edge == null)
            {
                return(false);
            }

            object o1 = edge.Object as object;
            object o2 = Object as object;

            return(o1 == o2);
        }
Example #2
0
        /// <summary>
        /// Creates an edge between two nodes with the bound objects
        /// </summary>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        /// <param name="edgeObj"></param>
        /// <param name="nodeObj1"></param>
        /// <param name="nodeObj2"></param>
        /// <returns></returns>
        public GraphEdge <E, N> CreateEdge(E edgeObj, N nodeObj1, N nodeObj2)
        {
            if (edgeObj == null)
            {
                throw new ArgumentNullException("edgeObj");
            }
            else if (nodeObj1 == null)
            {
                throw new ArgumentNullException("nodeObj1");
            }
            else if (nodeObj2 == null)
            {
                throw new ArgumentNullException("nodeObj2");
            }
            else if (ReferenceEquals(nodeObj1, nodeObj2))
            {
                throw new ArgumentException("Arguments nodeObj1 and nodeObj2 can not be the same object");
            }

            GraphNode <N, E> node1 = FindGraphNode(nodeObj1);
            GraphNode <N, E> node2 = FindGraphNode(nodeObj2);
            GraphEdge <E, N> edge  = FindGraphEdge(edgeObj);

            if (edge != null)
            {
                // The edgeObj already is bound to an edge
                throw new ArgumentException("edgeObj is already bound to an edge");
            }

            if (node1 != null && node2 != null && !AllowCircularLinks)
            {
                // Check if the both nodes are already connected to each other.
                GraphNode <N, E> foundNode = FindConnectedNode(node1, node2, true);

                if (foundNode != null)
                {
                    throw new ArgumentException("Circular link not allowed");
                }
            }

            if (node1 == null)
            {
                node1 = new GraphNode <N, E>(nodeObj1);
            }

            if (node2 == null)
            {
                node2 = new GraphNode <N, E>(nodeObj2);
            }

            GraphEdge <E, N> commonedge = (from e1 in node1.Edges join e2 in node2.Edges on e1 equals e2 select e2).SingleOrDefault();

            if (commonedge != null)
            {
                throw new ArgumentException("An edge already exists between nodeObj1 and nodeObj2");
            }

            edge = new GraphEdge <E, N>(edgeObj, node1, node2);

            Edges.Add(edge);

            node1.Edges.Add(edge);
            Nodes.Add(node1);

            node2.Edges.Add(edge);
            Nodes.Add(node2);

            return(edge);
        }