Ejemplo n.º 1
0
        private IEnumerable <string> SerializeNodesAsStream(IReadOnlyDictionary <ListNode, int> idMappings, ListNode headNode)
        {
            var currNode = headNode;

            while (currNode != null)
            {
                var nodeConverter = new ListNodeConverter(idMappings);
                var nodeString    = nodeConverter.ToString(currNode);
                yield return(nodeString);

                currNode = currNode.Next;
            }
        }
Ejemplo n.º 2
0
        public ListRand ToListRand(FileLinesStream fileLines, Dictionary <int, ListNode> idMappings)
        {
            var element = fileLines.Peek();

            if (element != Constants.ObjectSymbols.Start)
            {
                return(null);
            }

            var list = new ListRand();

            var line = fileLines.Next();

            while (line != null)
            {
                var(name, value) = Split(line);

                switch (name)
                {
                case nameof(list.Head):
                    list.Head = ToLink(value, idMappings);
                    break;

                case nameof(list.Tail):
                    list.Tail = ToLink(value, idMappings);
                    break;

                case nameof(list.Count):
                    list.Count = int.Parse(value);
                    break;

                case Constants.ObjectSymbols.ListRand.Nodes:
                    if (value != Constants.ArraySymbols.Start)
                    {
                        throw new FileHasIncorrectFormat();
                    }

                    fileLines.Next();
                    ListNode node = null;
                    do
                    {
                        var nodeConverter = new ListNodeConverter();
                        node = nodeConverter.ToNode(fileLines, idMappings);
                    } while (node != null);

                    var command = fileLines.Peek();
                    if (command != Constants.ArraySymbols.End)
                    {
                        throw new FileHasIncorrectFormat();
                    }
                    break;

                case Constants.ObjectSymbols.End:
                    fileLines.Next();
                    return(list);

                default:
                    throw new FileHasIncorrectFormat();
                }

                line = fileLines.Next();
            }

            return(list);
        }
Ejemplo n.º 3
0
 public ListRandConverter(IReadOnlyDictionary <ListNode, int> idMappings)
 {
     _idMappings        = idMappings;
     _listNodeConverter = new ListNodeConverter();
 }