Coverage Report - org.webslinger.commons.vfs.ReloadingCachingLister
 
Classes in this File Line Coverage Branch Coverage Complexity
ReloadingCachingLister
100%
20/20
100%
4/4
0
 
 1  
 package org.webslinger.commons.vfs;
 2  
 
 3  
 import java.io.IOException;
 4  
 import java.util.Set;
 5  
 import java.util.TreeSet;
 6  
 
 7  
 import org.apache.commons.vfs.FileName;
 8  
 import org.apache.commons.vfs.FileObject;
 9  
 
 10  
 import org.webslinger.util.TTLObject;
 11  
 
 12  9
 public class ReloadingCachingLister extends TTLObject<Set<String>> implements CachingLister {
 13  
     static {
 14  1
         TTLObject.setDefaultTTLForClass(ReloadingCachingLister.class, 1000);
 15  1
     }
 16  
 
 17  
     private final FileObject dir;
 18  
 
 19  9
     public ReloadingCachingLister(FileObject dir) {
 20  9
         this.dir = dir;
 21  9
     }
 22  
 
 23  
     public Set<String> getNames() throws IOException {
 24  9
         return getObject();
 25  
     }
 26  
 
 27  
     public FileObject getDir() {
 28  3
         return dir;
 29  
     }
 30  
 
 31  
     protected Set<String> load(Set<String> oldNames) throws IOException {
 32  9
         dir.refresh();
 33  9
         FileObject[] children = dir.getChildren();
 34  9
         TreeSet<String> names = new TreeSet<String>();
 35  36
         for (int i = 0; i < children.length; i++) {
 36  27
             FileName name = children[i].getName();
 37  27
             String baseName = name.getBaseName();
 38  27
             String extension = name.getExtension();
 39  27
             if (extension.length() > 0) baseName = baseName.substring(0, baseName.length() - extension.length() - 1);
 40  27
             if (baseName.equals("index")) continue;
 41  18
             if (baseName.startsWith(".")) continue;
 42  18
             names.add(baseName);
 43  
         }
 44  9
         return names;
 45  
     }
 46  
 }