public override void Promote(FrugalListBase<T> oldList)
        {
            int count = oldList.Count;
            if (3 >= 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("oldList");
            }
            throw new ArgumentException(System.Xaml.SR.Get("FrugalList_TargetMapCannotHoldAllData", new object[] { oldList.ToString(), this.ToString() }), "oldList");
        }
 public override void Promote(FrugalListBase <T> oldList)
 {
     if (1 != oldList.Count)
     {
         throw new ArgumentException(System.Xaml.SR.Get("FrugalList_TargetMapCannotHoldAllData", new object[] { oldList.ToString(), this.ToString() }), "oldList");
     }
     this.SetCount(1);
     this.SetAt(0, oldList.EntryAt(0));
 }
 public override void Promote(FrugalListBase <T> oldList)
 {
     for (int i = 0; i < oldList.Count; i++)
     {
         if (this.Add(oldList.EntryAt(i)) != FrugalListStoreState.Success)
         {
             throw new ArgumentException(System.Xaml.SR.Get("FrugalList_TargetMapCannotHoldAllData", new object[] { oldList.ToString(), this.ToString() }), "oldList");
         }
     }
 }
 public FrugalStructList(ICollection <T> collection)
 {
     if (collection.Count > 6)
     {
         this._listStore = new ArrayItemList <T>(collection);
     }
     else
     {
         this._listStore = null;
         this.Capacity   = collection.Count;
         foreach (T local in collection)
         {
             this.Add(local);
         }
     }
 }
        public int Add(T value)
        {
            if (this._listStore == null)
            {
                this._listStore = new SingleItemList <T>();
            }
            FrugalListStoreState state = this._listStore.Add(value);

            if (state != FrugalListStoreState.Success)
            {
                if (FrugalListStoreState.ThreeItemList != state)
                {
                    if (FrugalListStoreState.SixItemList != state)
                    {
                        if (FrugalListStoreState.Array != state)
                        {
                            throw new InvalidOperationException(System.Xaml.SR.Get("FrugalList_CannotPromoteBeyondArray"));
                        }
                        ArrayItemList <T> list3 = new ArrayItemList <T>(this._listStore.Count + 1);
                        list3.Promote(this._listStore);
                        this._listStore = list3;
                        list3.Add(value);
                        this._listStore = list3;
                    }
                    else
                    {
                        SixItemList <T> list2 = new SixItemList <T>();
                        list2.Promote(this._listStore);
                        this._listStore = list2;
                        list2.Add(value);
                        this._listStore = list2;
                    }
                }
                else
                {
                    ThreeItemList <T> list = new ThreeItemList <T>();
                    list.Promote(this._listStore);
                    list.Add(value);
                    this._listStore = list;
                }
            }
            return(this._listStore.Count - 1);
        }
 public FrugalStructList(int size)
 {
     this._listStore = null;
     this.Capacity   = size;
 }
Ejemplo n.º 7
0
 public abstract void Promote(FrugalListBase <T> newList);