public static AlphaFolder Combine(AlphaFolder folderA, AlphaFolder folderB) { if (null == folderA) { throw new ArgumentNullException(nameof(folderA)); } if (null == folderB) { throw new ArgumentNullException(nameof(folderB)); } if (folderA == folderB) { throw new ArgumentException(); } AlphaFolder combined = null; if (string.Compare(folderA.Start, folderB.Start, true) <= 0) { // A has the lowest Start if (string.Compare(folderA.End, folderB.End, true) <= 0) { // B has the highest End combined = new AlphaFolder(folderA.Start, folderB.End); } else { // A has the highest End combined = new AlphaFolder(folderA.Start, folderA.End); } } else { // B has the lower Start if (string.Compare(folderB.End, folderA.End, true) <= 0) { // A has the highest End combined = new AlphaFolder(folderB.Start, folderA.End); } else { // B has the highest End combined = new AlphaFolder(folderB.Start, folderB.End); } } foreach (string fileName in folderA.Files) { ListUtils.SortedInsert(combined.Files, fileName); } foreach (string fileName in folderB.Files) { ListUtils.SortedInsert(combined.Files, fileName); } return(combined); }
public int CompareTo(object obj) { AlphaFolder other = obj as AlphaFolder; if (null == other) { throw new ArgumentException(); } if (this == other) { throw new ArgumentException(); } int startCmp = string.Compare(Start, other.Start, true); int endCmp = string.Compare(End, other.End, true); if (startCmp < 0 && endCmp < 0) { return(-1); } else if (startCmp > 0 && endCmp > 0) { return(1); } throw new ArgumentException(); }
private void CombineFolders(int indexA, int indexB) { if (Math.Abs(indexA - indexB) != 1) { throw new ArgumentException(); } AlphaFolder folderA = _folders[indexA]; AlphaFolder folderB = _folders[indexB]; AlphaFolder combined = AlphaFolder.Combine(folderA, folderB); _folders.Remove(folderA); _folders.Remove(folderB); ListUtils.SortedInsert(_folders, combined); }
private void AddFolder(string start, string end = null) { AlphaFolder folder = new AlphaFolder(start, end); ListUtils.SortedInsert(_folders, folder); }
private void AddFile(string fileName) { AlphaFolder folder = GetFolderForFile(fileName); ListUtils.SortedInsert(folder.Files, fileName); }
public string GetFolderNameForFile(string fileName) { AlphaFolder folder = GetFolderForFile(fileName); return(folder.ToString()); }