Exemple #1
0
 public LinkedListCursor(LinkedListCursor <T> Cursor)
     : this()
 {
     this.Position   = Cursor.Position;
     this.Node       = Cursor.Node;
     this.StayAtFlag = Cursor.StayAtFlag;
 }
        public static LinkedListCursor <T> PositionBegin <T>(this LinkedList <T> List) where T : class
        {
            var firstNode = List.First;
            LinkedListCursor <T> cursor = new LinkedListCursor <T>(firstNode, RelativePosition.Before);

            return(cursor);
        }
Exemple #3
0
        public LinkedListCursor <T> Next( )
        {
            LinkedListNode <T> nxNode = null;

            // stay at the current location.
            if (StayAtFlag == true)
            {
                if (this.Position != RelativePosition.At)
                {
                    throw new ApplicationException("cursor not position at location to stay at");
                }
                StayAtFlag = false;
                nxNode     = this.Node;
            }

            else
            {
                switch (this.Position)
                {
                case RelativePosition.Begin:
                    throw new ApplicationException("begin position not supported.");

                case RelativePosition.Before:
                    nxNode = this.Node;
                    break;

                case RelativePosition.At:
                    nxNode = this.Node.Next;
                    break;

                case RelativePosition.After:
                    nxNode = this.Node.Next;
                    break;

                case RelativePosition.End:
                    nxNode = null;
                    break;

                default:
                    throw new ApplicationException("Next failed. Relative position is not set");
                }
            }

            if (nxNode == null)
            {
                return(null);
            }
            else
            {
                var csr = new LinkedListCursor <T>(nxNode, RelativePosition.At);
                return(csr);
            }
        }
Exemple #4
0
 public LinkedListCursor <T> PositionBefore()
 {
     if (_Position == RelativePosition.Begin)
     {
         return(PositionBegin());
     }
     else if (_Position == RelativePosition.End)
     {
         return(PositionEnd());
     }
     else if (_Position == RelativePosition.None)
     {
         throw new ApplicationException("PositionBefore cursor is set to None");
     }
     else
     {
         var csr = new LinkedListCursor <T>(this.Node, RelativePosition.Before);
         return(csr);
     }
 }