Beispiel #1
0
        public override object Clone()
        {
            ThreeItemList <T> threeItemList = new ThreeItemList <T>();

            threeItemList.Promote(this);
            return(threeItemList);
        }
Beispiel #2
0
        public void Promote(ThreeItemList <T> oldList)
        {
            int count = oldList.Count;

            this.SetCount(oldList.Count);
            switch (count)
            {
            case 0:
            {
                return;
            }

            case 1:
            {
                this.SetAt(0, oldList.EntryAt(0));
                return;
            }

            case 2:
            {
                this.SetAt(0, oldList.EntryAt(0));
                this.SetAt(1, oldList.EntryAt(1));
                return;
            }

            case 3:
            {
                this.SetAt(0, oldList.EntryAt(0));
                this.SetAt(1, oldList.EntryAt(1));
                this.SetAt(2, oldList.EntryAt(2));
                return;
            }
            }
            throw new ArgumentOutOfRangeException("index");
        }
Beispiel #3
0
        public override FrugalListStoreState Add(T value)
        {
            switch (this._count)
            {
            case 0:
            {
                this._entry0 = value;
                break;
            }

            case 1:
            {
                this._entry1 = value;
                break;
            }

            case 2:
            {
                this._entry2 = value;
                break;
            }

            default:
            {
                return(FrugalListStoreState.SixItemList);
            }
            }
            ThreeItemList <T> threeItemList = this;

            threeItemList._count = threeItemList._count + 1;
            return(FrugalListStoreState.Success);
        }
Beispiel #4
0
        public int Add(T value)
        {
            if (this._listStore == null)
            {
                this._listStore = new SingleItemList <T>();
            }
            FrugalListStoreState frugalListStoreState = this._listStore.Add(value);

            if (frugalListStoreState != FrugalListStoreState.Success)
            {
                if (FrugalListStoreState.ThreeItemList == frugalListStoreState)
                {
                    ThreeItemList <T> threeItemList = new ThreeItemList <T>();
                    threeItemList.Promote(this._listStore);
                    threeItemList.Add(value);
                    this._listStore = threeItemList;
                }
                else if (FrugalListStoreState.SixItemList != frugalListStoreState)
                {
                    if (FrugalListStoreState.Array != frugalListStoreState)
                    {
                        throw new InvalidOperationException();
                    }
                    ArrayItemList <T> arrayItemList = new ArrayItemList <T>(this._listStore.Count + 1);
                    arrayItemList.Promote(this._listStore);
                    this._listStore = arrayItemList;
                    arrayItemList.Add(value);
                    this._listStore = arrayItemList;
                }
                else
                {
                    SixItemList <T> sixItemList = new SixItemList <T>();
                    sixItemList.Promote(this._listStore);
                    this._listStore = sixItemList;
                    sixItemList.Add(value);
                    this._listStore = sixItemList;
                }
            }
            return(this._listStore.Count - 1);
        }
Beispiel #5
0
        public override void Insert(int index, T value)
        {
            if (this._count >= 3)
            {
                throw new ArgumentOutOfRangeException("index");
            }
            switch (index)
            {
            case 0:
            {
                this._entry2 = this._entry1;
                this._entry1 = this._entry0;
                this._entry0 = value;
                break;
            }

            case 1:
            {
                this._entry2 = this._entry1;
                this._entry1 = value;
                break;
            }

            case 2:
            {
                this._entry2 = value;
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException("index");
            }
            }
            ThreeItemList <T> threeItemList = this;

            threeItemList._count = threeItemList._count + 1;
        }