/// <summary> /// This is simply a debugging aid that tests the functionality of /// the class. /// </summary> /// <remarks> /// This is simply a debugging aid that tests the functionality of /// the class. The supplied arguments are put in a /// <c>Collection</c> /// , and passed to the /// <c>FileSequentialCollection</c> /// constructor. /// An iterator is then used to print the names of all the files /// (but not directories) in the collection. /// </remarks> /// <param name="args">A list of file paths</param> public static void Main(string[] args) { FileSequentialCollection fcollect = new FileSequentialCollection(Arrays.AsList(args)); foreach (File fi in fcollect) { System.Console.Out.WriteLine(fi); } // test the other constructors System.Console.Out.WriteLine("Above was Collection constructor"); System.Console.Out.WriteLine("Empty constructor"); FileSequentialCollection fcollect2 = new FileSequentialCollection(); foreach (File fi_1 in fcollect2) { System.Console.Out.WriteLine(fi_1); } System.Console.Out.WriteLine("File String(mrg) boolean(true) constructor"); FileSequentialCollection fcollect3 = new FileSequentialCollection(new File(args[0]), "mrg", true); foreach (File fi_2 in fcollect3) { System.Console.Out.WriteLine(fi_2); } System.Console.Out.WriteLine("Collection String(mrg) boolean constructor"); FileSequentialCollection fcollect4 = new FileSequentialCollection(Arrays.AsList(args), "mrg", true); foreach (File fi_3 in fcollect4) { System.Console.Out.WriteLine(fi_3); } System.Console.Out.WriteLine("Testing number range file filter"); FileSequentialCollection fcollect5 = new FileSequentialCollection(Arrays.AsList(args), new NumberRangeFileFilter(320, 410, true)); foreach (File fi_4 in fcollect5) { System.Console.Out.WriteLine(fi_4); } System.Console.Out.WriteLine("Testing null filter but include dirs"); FileSequentialCollection fcollect6 = new FileSequentialCollection(Arrays.AsList(args), (IFileFilter)null, true); foreach (File fi_5 in fcollect6) { System.Console.Out.WriteLine(fi_5); } }
public FileSequentialCollectionIterator(FileSequentialCollection _enclosing) { this._enclosing = _enclosing; // current state is a rootsIterator, a position in a recursion // under a directory listing, and a pointer in the current // directory. // these may be of type File or String // these next two simulate a list of pairs, but I was too lazy to // make an extra class // log.info("Coll is " + coll); this.roots = Sharpen.Collections.ToArray(this._enclosing.coll); this.rootsIndex = 0; this.fileArrayStack = new Stack <object>(); this.fileArrayStackIndices = new Stack <int>(); if (this.roots.Length > 0) { this.fileArrayStack.Add(this.roots[this.rootsIndex]); this.fileArrayStackIndices.Push(int.Parse(0)); } this.next = this.PrimeNextFile(); }