@Test public void testIterator() { assertEquals(5, folder.getFilenames().length); Iterator<EncryptedEmailPacket> iterator = folder.iterator(); assertTrue("Folder is empty!", iterator.hasNext()); EncryptedEmailPacket retrievedPacket1 = iterator.next(); iterator.remove(); assertTrue("Folder has less than two elements!", iterator.hasNext()); EncryptedEmailPacket retrievedPacket2 = iterator.next(); iterator.remove(); assertFalse("Folder is not empty!", iterator.hasNext()); assertTrue("Folder packet 1 differs from the original!", equals(emailPacket1, retrievedPacket1) || equals(emailPacket2, retrievedPacket1)); assertTrue("Folder packet 2 differs from the original!", equals(emailPacket1, retrievedPacket2) || equals(emailPacket2, retrievedPacket2)); assertFalse("The two retrieved packets are equal!", equals(retrievedPacket1, retrievedPacket2)); assertFalse("Packets were not deleted!", folder.iterator().hasNext()); }
protected File[] getFilenames() { File[] files = storageDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.toUpperCase().endsWith(fileExtension.toUpperCase()); } }); if (files == null) { log.error("Cannot list files in directory <" + storageDir + ">"); files = new File[0]; } else { try { Arrays.sort(files, new Comparator<File>() { @Override public int compare(File f1, File f2) { return (int)Math.signum(f2.lastModified() - f1.lastModified()); } }); } catch (IllegalArgumentException iae) { log.warn("Error while sorting files in " + storageDir + ", order will be unstable", iae); } } return files; }
Folder { protected File[] getFilenames() { File[] files = storageDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.toUpperCase().endsWith(fileExtension.toUpperCase()); } }); if (files == null) { log.error("Cannot list files in directory <" + storageDir + ">"); files = new File[0]; } else { try { Arrays.sort(files, new Comparator<File>() { @Override public int compare(File f1, File f2) { return (int)Math.signum(f2.lastModified() - f1.lastModified()); } }); } catch (IllegalArgumentException iae) { log.warn("Error while sorting files in " + storageDir + ", order will be unstable", iae); } } return files; } }
Folder { protected File[] getFilenames() { File[] files = storageDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.toUpperCase().endsWith(fileExtension.toUpperCase()); } }); if (files == null) { log.error("Cannot list files in directory <" + storageDir + ">"); files = new File[0]; } else { try { Arrays.sort(files, new Comparator<File>() { @Override public int compare(File f1, File f2) { return (int)Math.signum(f2.lastModified() - f1.lastModified()); } }); } catch (IllegalArgumentException iae) { log.warn("Error while sorting files in " + storageDir + ", order will be unstable", iae); } } return files; } protected  Folder(File storageDir, String fileExtension); }
Folder { protected File[] getFilenames() { File[] files = storageDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.toUpperCase().endsWith(fileExtension.toUpperCase()); } }); if (files == null) { log.error("Cannot list files in directory <" + storageDir + ">"); files = new File[0]; } else { try { Arrays.sort(files, new Comparator<File>() { @Override public int compare(File f1, File f2) { return (int)Math.signum(f2.lastModified() - f1.lastModified()); } }); } catch (IllegalArgumentException iae) { log.warn("Error while sorting files in " + storageDir + ", order will be unstable", iae); } } return files; } protected  Folder(File storageDir, String fileExtension); File getStorageDirectory(); String getName(); int getNumElements(); List<T> getElements(); final FolderIterator<T> iterate(); @Override String toString(); }
Folder { protected File[] getFilenames() { File[] files = storageDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.toUpperCase().endsWith(fileExtension.toUpperCase()); } }); if (files == null) { log.error("Cannot list files in directory <" + storageDir + ">"); files = new File[0]; } else { try { Arrays.sort(files, new Comparator<File>() { @Override public int compare(File f1, File f2) { return (int)Math.signum(f2.lastModified() - f1.lastModified()); } }); } catch (IllegalArgumentException iae) { log.warn("Error while sorting files in " + storageDir + ", order will be unstable", iae); } } return files; } protected  Folder(File storageDir, String fileExtension); File getStorageDirectory(); String getName(); int getNumElements(); List<T> getElements(); final FolderIterator<T> iterate(); @Override String toString();  }