/* * Node.cs * Authors: * Copyright (c) 2007-2008 Cornell University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections.Generic; using System.Text; namespace ColonySim.Graphs { /// /// Represents a Node in the resource graph. /// internal class Node { #region Fields // The list of adjacencies we have private List mAdjacencies = new List(); #endregion #region Properties /// /// Expose the list of edges for use. /// public List Adjacencies { get { return mAdjacencies; } } /// /// Returns the number of adjacencies this Node has. /// public int NumberOfAdjacencies { get { return mAdjacencies.Count; } } #endregion #region Utility /// /// Add the given node to our adjacency list. /// /// The node to add. public void AddAdjacency(Node pNode) { // If we don't contain that node if (!mAdjacencies.Contains(pNode)) { // Add the node mAdjacencies.Add(pNode); } } /// /// Reemoves the given node from our adjacency list. /// /// The node to remove. /// Whether we removed the adjacency or not. public bool RemoveAdjacency(Node pNode) { // Return return mAdjacencies.Remove(pNode); } /// /// Get the Node adjacency at the given index position. /// /// The index for us to get the node at. /// The adjacency at the given index. public Node GetAdjacency(int pIndex) { // Return the adjacency at the point in the adjacency list return mAdjacencies[pIndex]; } /// /// Clears all of our adjacencies. /// public void ClearAdjacencies() { // Clear our adjacency list mAdjacencies.Clear(); } #endregion } }