Ejemplo n.º 1
0
 private static void PopulateCollection(PushOutCollection <int> collection, int count)
 {
     for (int i = 0; i < count; i++)
     {
         collection.Add(i);
     }
 }
Ejemplo n.º 2
0
        public void PushOutFirstElement(int capacity, int extraElements, int[] expected)
        {
            // Arrange
            var collection = new PushOutCollection <int>(capacity);

            // Act
            for (int i = 0; i < capacity + extraElements; i++)
            {
                collection.Add(i);
            }

            // Assert
            Assert.Equal(expected, collection);
        }
Ejemplo n.º 3
0
        public void IncreaseCount(int capacity, int newElements)
        {
            // Arrange
            var collection = new PushOutCollection <int>(capacity);

            // Act
            for (int i = 0; i < newElements; i++)
            {
                collection.Add(i);
            }

            // Assert
            Assert.Equal(newElements, collection.Count);
        }
Ejemplo n.º 4
0
        public void NotExceedCapacity(int capacity, int newElements)
        {
            // Arrange
            var collection = new PushOutCollection <int>(capacity);

            // Act
            for (int i = 0; i < newElements; i++)
            {
                collection.Add(i);
            }

            // Assert
            Assert.Equal(capacity, collection.Count);
            Assert.Equal(capacity, collection.MaxCount);
        }
Ejemplo n.º 5
0
        private bool TryAddSnapshotInternal(ref LineViewSnapshot snapshot)
        {
            if (EqualsToCurrentSnapshot(ref snapshot))
            {
                return(false);
            }

            if (_iterator.HasNext())
            {
                _snapshots.TrimTo(_iterator.Index + 1);
            }

            _snapshots.Add(snapshot);
            _iterator.MoveToLast();

            return(true);
        }
Ejemplo n.º 6
0
        public void AddCommand(string command)
        {
            EnsureCommandsLoaded();

            if (String.IsNullOrWhiteSpace(command) ||
                IsEqualsToLastCommand(command))
            {
                _current = _commands.Count;
                return;
            }

            lock (_commandsWriteLock)
            {
                _commands.Add(command);
                _current = _commands.Count;
            }

            ScheduleSaveCommands();
        }
Ejemplo n.º 7
0
        private void EnsureCommandsLoaded()
        {
            if (_commands != null)
            {
                return;
            }

            lock (_commandsWriteLock)
            {
                if (_historyStorage == null)
                {
                    _commands = new PushOutCollection <string>(MaxCount);
                }
                else
                {
                    IReadOnlyList <string> loaded = null;
                    lock (_historyStorage)
                    {
                        loaded = _historyStorage.Load();
                    }
                    loaded = loaded.Where(_ => !String.IsNullOrWhiteSpace(_)).ToArray();

                    if (loaded.Count > MaxCount)
                    {
                        _commands = new PushOutCollection <string>(loaded.Skip(loaded.Count - MaxCount));
                    }
                    else
                    {
                        _commands = new PushOutCollection <string>(MaxCount);
                        for (int i = 0; i < loaded.Count; i++)
                        {
                            _commands.Add(loaded[i]);
                        }
                    }
                }

                _current = _commands.Count;
            }
        }