Exemplo n.º 1
0
        /// <summary>
        /// Reorders the specified items.
        /// </summary>
        /// <param name="items">The items.</param>
        /// <param name="oldIndex">The old index.</param>
        /// <param name="newIndex">The new index.</param>
        /// <returns>List of Ids who's order changed</returns>
        public virtual List <int> Reorder(List <T> items, int oldIndex, int newIndex)
        {
            var Ids = new List <int>();

            T movedItem = items[oldIndex];

            if (movedItem != null)
            {
                Ids.Add(movedItem.Id);

                items.RemoveAt(oldIndex);
                if (newIndex >= items.Count)
                {
                    items.Add(movedItem);
                }
                else
                {
                    items.Insert(newIndex, movedItem);
                }

                int order = 0;
                foreach (T item in items)
                {
                    IOrdered orderedItem = item as IOrdered;
                    if (orderedItem != null)
                    {
                        if (orderedItem.Order != order)
                        {
                            Ids.Add(item.Id);
                            orderedItem.Order = order;
                        }
                    }
                    order++;
                }
            }

            return(Ids);
        }
Exemplo n.º 2
0
 public OrderOps(IOrdered <X> Ordered)
 => this.Ordered = Ordered;
Exemplo n.º 3
0
 /// <summary> Binary search for an object</summary>
 /// <param name="array">The array of <code>Ordered</code> objects.
 /// </param>
 /// <param name="ref_Renamed">The name to search for.
 /// </param>
 /// <returns> The index at which reference was found or is to be inserted.
 /// </returns>
 public static int Bsearch(IOrdered[] array, IOrdered ref_Renamed)
 {
     return(Bsearch(array, ref_Renamed, 0, array.Length - 1));
 }
Exemplo n.º 4
0
 /// <summary> Binary search for an object</summary>
 /// <param name="vector">The vector of <code>Ordered</code> objects.
 /// </param>
 /// <param name="ref_Renamed">The name to search for.
 /// </param>
 /// <returns> The index at which reference was found or is to be inserted.
 /// </returns>
 public static int bsearch(System.Collections.ArrayList vector, IOrdered ref_Renamed)
 {
     return(Bsearch(vector, ref_Renamed, 0, vector.Count - 1));
 }
Exemplo n.º 5
0
 /// <summary> Binary search for an object</summary>
 /// <param name="set_Renamed">The collection of <code>Ordered</code> objects.
 /// </param>
 /// <param name="ref_Renamed">The name to search for.
 /// </param>
 /// <returns> The index at which reference was found or is to be inserted.
 /// </returns>
 public static int Bsearch(ISortable set_Renamed, IOrdered ref_Renamed)
 {
     return(Bsearch(set_Renamed, ref_Renamed, set_Renamed.First(), set_Renamed.Last()));
 }
Exemplo n.º 6
0
 public static System.Windows.Input.ICommand SwipeTimeout(IOrdered line)
 {
     return(new Command(() =>
     {
     }));
 }
Exemplo n.º 7
0
        public static System.Windows.Input.ICommand GetMoveSectionCmd(CommonBaseVM vm, IOrdered line)
        {
            return(new Command((arg) =>
            {
                line.TimeStamp = DateTime.Now;

                Task.Factory.StartNew(() => Task.Delay(3000))
                .ContinueWith((t, x) =>
                {
                    if ((DateTime.Now.Subtract((x as IOrdered).TimeStamp).TotalSeconds > 3))
                    {
                        (x as IOrdered).OrderImageName = "empty.png";
                    }
                },
                              line);


                SwipeAction swipe = (arg as SwipeAction?).Value;
                SwipeType swipeType = SwipeType.None;
                if ((swipe.Type & SwipeType.Up) != 0 || (swipe.Type & SwipeType.Left) != 0)
                {
                    line.OrderImageName = "up.png";
                    swipeType = SwipeType.Up;
                }
                else if ((swipe.Type & SwipeType.Down) != 0 || (swipe.Type & SwipeType.Right) != 0)
                {
                    line.OrderImageName = "down.png";
                    swipeType = SwipeType.Down;
                }
                else
                {
                    line.OrderImageName = "empty.png";
                }

                if (swipe.Finished)
                {
                    vm.Order.MoveOutputLine(line, -1, swipeType);
                    line.OrderImageName = "empty.png";
                }

                vm.RaiseChanges();
            }));
        }
		/// <summary> Fetch the object at the given index.</summary>
		/// <param name="index">The item number to get.
		/// </param>
		/// <param name="reuse">If this argument is not null, it is an object
		/// acquired from a previous fetch that is no longer needed and
		/// may be returned as the result if it makes mores sense to alter
		/// and return it than to fetch or create a new element. That is, the
		/// reuse object is garbage and may be used to avoid allocating a new
		/// object if that would normally be the strategy.
		/// </param>
		/// <returns> The Ordered object at that index.
		/// </returns>
		public virtual IOrdered Fetch(int index, IOrdered reuse)
		{
			Cursor ret;
			
			if (null != reuse)
			{
				ret = (Cursor) reuse;
				ret.mPosition = mIndices[index];
				ret.mPage = Page; // redundant
			}
			else
				ret = new Cursor(Page, mIndices[index]);
			
			return (ret);
		}
		/// <summary> Binary search for an object</summary>
		/// <param name="array">The array of <code>Ordered</code> objects.
		/// </param>
		/// <param name="ref_Renamed">The name to search for.
		/// </param>
		/// <returns> The index at which reference was found or is to be inserted.
		/// </returns>
		public static int Bsearch(IOrdered[] array, IOrdered ref_Renamed)
		{
			return (Bsearch(array, ref_Renamed, 0, array.Length - 1));
		}
Exemplo n.º 10
0
		/// <summary> Binary search for an object</summary>
		/// <param name="array">The array of <code>Ordered</code> objects.
		/// </param>
		/// <param name="ref_Renamed">The name to search for.
		/// </param>
		/// <param name="lo">The lower index within which to look.
		/// </param>
		/// <param name="hi">The upper index within which to look.
		/// </param>
		/// <returns> The index at which reference was found or is to be inserted.
		/// </returns>
		public static int Bsearch(IOrdered[] array, IOrdered ref_Renamed, int lo, int hi)
		{
			int num;
			int mid;
			int half;
			int result;
			int ret;
			
			ret = - 1;
			
			num = (hi - lo) + 1;
			while ((- 1 == ret) && (lo <= hi))
			{
				half = num / 2;
				mid = lo + ((0 != (num & 1))?half:half - 1);
				result = ref_Renamed.Compare(array[mid]);
				if (0 == result)
					ret = mid;
				else if (0 > result)
				{
					hi = mid - 1;
					num = ((0 != (num & 1))?half:half - 1);
				}
				else
				{
					lo = mid + 1;
					num = half;
				}
			}
			if (- 1 == ret)
				ret = lo;
			
			return (ret);
		}
Exemplo n.º 11
0
		/// <summary> Binary search for an object</summary>
		/// <param name="vector">The vector of <code>Ordered</code> objects.
		/// </param>
		/// <param name="ref_Renamed">The name to search for.
		/// </param>
		/// <returns> The index at which reference was found or is to be inserted.
		/// </returns>
		public static int bsearch(System.Collections.ArrayList vector, IOrdered ref_Renamed)
		{
			return (Bsearch(vector, ref_Renamed, 0, vector.Count - 1));
		}
Exemplo n.º 12
0
		/// <summary> Binary search for an object</summary>
		/// <param name="set_Renamed">The collection of <code>Ordered</code> objects.
		/// </param>
		/// <param name="ref_Renamed">The name to search for.
		/// </param>
		/// <returns> The index at which reference was found or is to be inserted.
		/// </returns>
		public static int Bsearch(ISortable set_Renamed, IOrdered ref_Renamed)
		{
			return (Bsearch(set_Renamed, ref_Renamed, set_Renamed.First(), set_Renamed.Last()));
		}
Exemplo n.º 13
0
		/// <summary> Binary search for an object</summary>
		/// <param name="set_Renamed">The collection of <code>Ordered</code> objects.
		/// </param>
		/// <param name="ref_Renamed">The name to search for.
		/// </param>
		/// <param name="lo">The lower index within which to look.
		/// </param>
		/// <param name="hi">The upper index within which to look.
		/// </param>
		/// <returns> The index at which reference was found or is to be inserted.
		/// </returns>
		public static int Bsearch(ISortable set_Renamed, IOrdered ref_Renamed, int lo, int hi)
		{
			int num;
			int mid;
			IOrdered ordered;
			int half;
			int result;
			int ret;
			
			ret = - 1;
			
			num = (hi - lo) + 1;
			ordered = null;
			while ((- 1 == ret) && (lo <= hi))
			{
				half = num / 2;
				mid = lo + ((0 != (num & 1))?half:half - 1);
				ordered = set_Renamed.Fetch(mid, ordered);
				result = ref_Renamed.Compare(ordered);
				if (0 == result)
					ret = mid;
				else if (0 > result)
				{
					hi = mid - 1;
					num = ((0 != (num & 1))?half:half - 1);
				}
				else
				{
					lo = mid + 1;
					num = half;
				}
			}
			if (- 1 == ret)
				ret = lo;
			
			return (ret);
		}
Exemplo n.º 14
0
		/// <summary> Sort a Hashtable.</summary>
		/// <param name="h">A Hashtable with String or Ordered keys.
		/// </param>
		/// <returns> A sorted array of the keys.
		/// </returns>
		public static System.Object[] QuickSort(System.Collections.Hashtable h)
		{
			System.Collections.IEnumerator e;
			bool are_strings;
			System.Object[] ret;
			
			// make the array
			ret = new IOrdered[h.Count];
			e = h.Keys.GetEnumerator();
			are_strings = true; // until proven otherwise
			for (int i = 0; i < ret.Length; i++)
			{
				ret[i] = e.Current;
				if (are_strings && !(ret[i] is System.String))
					are_strings = false;
			}
			
			// sort it
			if (are_strings)
				QuickSort((System.String[]) ret);
			else
				QuickSort((IOrdered[]) ret);
			
			return (ret);
		}
Exemplo n.º 15
0
		/// <summary> This is a generic version of C.A.R Hoare's Quick Sort algorithm.
		/// This will handle arrays that are already sorted,
		/// and arrays with duplicate keys.
		/// <p>
		/// If you think of a one dimensional array as going from
		/// the lowest index on the left to the highest index on the right
		/// then the parameters to this function are lowest index or
		/// left and highest index or right.
		/// </summary>
		/// <param name="a">An array of <code>Ordered</code> items.
		/// </param>
		/// <param name="lo0">Left boundary of array partition.
		/// </param>
		/// <param name="hi0">Right boundary of array partition.
		/// </param>
		public static void  QuickSort(IOrdered[] a, int lo0, int hi0)
		{
			int lo = lo0;
			int hi = hi0;
			IOrdered mid;
			
			if (hi0 > lo0)
			{
				// arbitrarily establish partition element as the midpoint of the array
				mid = a[(lo0 + hi0) / 2];
				
				// loop through the vector until indices cross
				while (lo <= hi)
				{
					// find the first element that is greater than or equal to
					// the partition element starting from the left index
					while ((lo < hi0) && (0 > a[lo].Compare(mid)))
						++lo;
					
					// find an element that is smaller than or equal to
					// the partition element starting from the right Index.
					while ((hi > lo0) && (0 < a[hi].Compare(mid)))
						--hi;
					
					// if the indexes have not crossed, swap
					if (lo <= hi)
						Swap(a, lo++, hi--);
				}
				
				// if the right index has not reached the left side of array
				// must now sort the left partition
				if (lo0 < hi)
					QuickSort(a, lo0, hi);
				
				// if the left index has not reached the right side of array
				// must now sort the right partition
				if (lo < hi0)
					QuickSort(a, lo, hi0);
			}
		}
Exemplo n.º 16
0
		/// <summary> This is a generic version of C.A.R Hoare's Quick Sort algorithm.
		/// This will handle arrays that are already sorted,
		/// and arrays with duplicate keys.
		/// <p>
		/// Equivalent to:
		/// <pre>
		/// QuickSort (a, 0, a.length - 1);
		/// </pre>
		/// </summary>
		/// <param name="a">An array of <code>Ordered</code> items.
		/// </param>
		public static void  QuickSort(IOrdered[] a)
		{
			QuickSort(a, 0, a.Length - 1);
		}