コード例 #1
0
        internal int Recursive_Sort_Insert(Builder_Page_File NewPageFile, int Start, int End)
        {
            int startIndex = Start;
            int endIndex   = End;
            int midIndex   = (int)Math.Ceiling((double)(endIndex - startIndex) / 2) + startIndex;

            if (endIndex - startIndex <= 1)
            {
                if (NewPageFile.CompareTo(this[startIndex]) <= 0)
                {
                    List.Insert(startIndex, NewPageFile);
                    return(startIndex);
                }

                List.Insert(endIndex, NewPageFile);
                return(endIndex);
            }

            if (NewPageFile.CompareTo(this[midIndex]) < 0)
            {
                endIndex = midIndex;
            }
            else
            {
                startIndex = midIndex;
            }

            return(Recursive_Sort_Insert(NewPageFile, startIndex, endIndex));
        }
コード例 #2
0
        /// <summary> Check to see if these two files are equivalent </summary>
        /// <param name="Obj"> Object to compare to </param>
        /// <returns> Returns -1, 0, or 1, depending on how this object ranks in comparison to the testing object </returns>
        public int CompareTo(object Obj)
        {
            // Check for null
            if (Obj == null)
            {
                return(1);
            }

            // Perform comparison
            int result = 0;

            var obj = Obj as Builder_Page_File;

            if (obj != null)
            {
                // Same object types, so cast
                Builder_Page_File compareToObj = obj;

                // Check for comparison between all the parts
                int maximum_part_checks = Math.Min(Sorter.NameParts.Length, compareToObj.Sorter.NameParts.Length);
                int i = 0;
                while ((i < maximum_part_checks) && (result == 0))
                {
                    // Only check for roman numerals in the first section
                    if (i == 0)
                    {
                        result = CompareStrings(Sorter.NameParts[i], compareToObj.Sorter.NameParts[i], true);
                    }
                    else
                    {
                        result = CompareStrings(Sorter.NameParts[i], compareToObj.Sorter.NameParts[i], false);
                    }

                    // Increment the counter to look at the next one
                    i++;
                }

                // If there was no result, the file with more parts should follow the one with less
                if ((result == 0) && (Sorter.NameParts.Length != compareToObj.Sorter.NameParts.Length))
                {
                    if (Sorter.NameParts.Length > compareToObj.Sorter.NameParts.Length)
                    {
                        return(1);
                    }

                    return(-1);
                }

                return(result);
            }

            return(0);
        }
コード例 #3
0
        /// <summary> Insert a new page into this collection, based on the file name </summary>
        /// <param name="NewPageFile"></param>
        /// <returns></returns>
        internal int Insert(Builder_Page_File NewPageFile)
        {
            if (List.Count == 0)
            {
                return(List.Add(NewPageFile));
            }

            if (NewPageFile.CompareTo(this[0]) <= 0)
            {
                List.Insert(0, NewPageFile);
                return(0);
            }

            if (NewPageFile.CompareTo(this[List.Count - 1]) >= 0)
            {
                return(List.Add(NewPageFile));
            }

            return(Recursive_Sort_Insert(NewPageFile, 0, List.Count - 1));
        }
コード例 #4
0
 /// <summary> Check to see if these two files are equivalent </summary>
 /// <param name="CompareTo"> Object to compare to </param>
 /// <returns> TRUE if equal, otherwise FALSE </returns>
 public bool Equals(Builder_Page_File CompareTo)
 {
     // Must have same name, first of all
     return(Same_Name(CompareTo));
 }
コード例 #5
0
 /// <summary> Check to see if these two files have the same name </summary>
 /// <param name="CompareTo"> Object to compare to </param>
 /// <returns>TRUE if they have the same name, otherwise FALSE </returns>
 public bool Same_Name(Builder_Page_File CompareTo)
 {
     return(String.Compare(FullName, CompareTo.FullName, StringComparison.OrdinalIgnoreCase) == 0);
 }
コード例 #6
0
 /// <summary> Add a new Page_File to this collection. </summary>
 /// <param name="NewPageFile"> <see cref="Builder_Page_File"/> object for this new Page_File </param>
 internal void Add(Builder_Page_File NewPageFile)
 {
     // Add this constructed Page_File to the collection
     List.Add(NewPageFile);
 }