FmqDir { public FmqDir (File path) { assert (path != null); assert (path.exists ()); this.path = path; files = new ArrayList <FmqFile> (); subdirs = new ArrayList <FmqDir> (); count = 0; size = time = 0L; for (File f : path.listFiles ()) { if (f.getName ().startsWith (".")) continue; if (f.isDirectory ()) subdirs.add (new FmqDir (f)); else files.add (new FmqFile (f)); } for (FmqDir subdir : subdirs) { if (time < subdir.time) time = subdir.time; size += subdir.size; count += subdir.count; } for (FmqFile file : files) { if (time < file.time ()) time = file.time (); size += file.size (); count ++; } } FmqDir(File path); static FmqDir newFmqDir(final String path, final String parent); static FmqDir newFmqDir(final File dir); void destroy(); String path(); long time(); long size(); static FmqFile [] flatten(FmqDir self); void remove(boolean force); void dump(int indent); Map <String, String> cache(); static List<FmqPatch> diff(FmqDir older, FmqDir newer, String alias); static List<FmqPatch> resync(FmqDir self, String alias);  }
@Test public void testFmqDir () { boolean verbose = false; System.out.printf (" * fmq_dir: "); FmqDir older = FmqDir.newFmqDir (".", null); assertNotNull (older); if (verbose) { System.out.printf ("\n"); older.dump (0); } FmqDir newer = FmqDir.newFmqDir ("..", null); List <FmqPatch> patches = FmqDir.diff (older, newer, "/"); assertNotNull (patches); for (FmqPatch patch : patches) { patch.destroy (); } older.destroy (); newer.destroy (); FmqDir here = FmqDir.newFmqDir (".", null); Map <String, String> cache = here.cache (); assertNotNull (cache); here.destroy (); FmqDir nosuch = FmqDir.newFmqDir ("does-not-exist", null); assertNull (nosuch); System.out.printf ("OK\n"); }