Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.storemate.store.file;
  
  import java.io.*;
  import java.util.*;
  
Object that represents the main-level data directory, directly under data file root directory. Sortable in ascending direction, that is, order by time of creation.
 
 public class DirByDate implements Comparable<DirByDate>
 {
     private final static Logger LOG = LoggerFactory.getLogger(DirByDate.class);

    
Pattern used for the main-level date-based directories
 
     final static Pattern DATE_DIR_PATTERN = Pattern.compile("(\\d\\d\\d\\d)\\-(\\d\\d)\\-(\\d\\d)");
 
     final static Pattern TIME_DIR_PATTERN = Pattern.compile("(\\d\\d):(\\d\\d)");
     
     protected final File _dir;
     
     protected final DateTime _createTime;
 
     public DirByDate(File dirDateTime createTime)
     {
          = dir;
          = createTime;
     }
 
     public static List<DirByDatelistMainDataDirs(File rootFileCleanupStats stats)
     {
         ArrayList<DirByDatedirs = new ArrayList<DirByDate>();
         for (File dir : root.listFiles()) {
             Matcher m = .matcher(dir.getName());
             if (m.matches()) {
                 try {
                     int year = Integer.parseInt(m.group(1));
                     int month = Integer.parseInt(m.group(2));
                     int day = Integer.parseInt(m.group(3));
                     MutableDateTime created = new MutableDateTime(0L, .);
                     created.setTime(0, 0, 0, 0);
                     created.setDate(yearmonthday);
                     dirs.add(new DirByDate(dircreated.toDateTime()));
                     continue;
                 } catch (IllegalArgumentException e) {
                     .warn("Invalid directory name {}, will skip"dir.getAbsolutePath());
                 }
             }
             if (stats != null) {
                 stats.addSkippedDir();
             }
         }
         // and then sort...
         Collections.sort(dirs);
         return dirs;
     }
     
     public File getDirectory() { return ; }
     
     public List<DirByTimelistTimeDirs(FileCleanupStats stats//throws IOException
     {
         ArrayList<DirByTimedirs = new ArrayList<DirByTime>();
         for (File dir : .listFiles()) {
             Matcher m = .matcher(dir.getName());
             if (m.matches()) {
                 try {
                     int hour = Integer.parseInt(m.group(1));
                     int minute = Integer.parseInt(m.group(2));
                     dirs.add(new DirByTime(dir,
                         
                             .withHourOfDay(hour)
                             .withMinuteOfHour(minute)));
                     continue;
                 } catch (IllegalArgumentException e) {
                     .warn("Invalid directory name {}, will skip"dir.getAbsolutePath());
                 }
             }
             if (stats != null) {
                 stats.addSkippedDir();
             }
         }
         return dirs;
     }
     
     public long getRawCreateTime() {
         return .getMillis();
     }
     
    @Override
    public int compareTo(DirByDate other)
    {
        long thisTime = getRawCreateTime();
        long thatTime = other.getRawCreateTime();
        if (thisTime < thatTime) {
            return -1;
        }
        if (thisTime > thatTime) {
            return 1;
        }
        return 0;
    }
    @Override
    public String toString() { return .getAbsolutePath(); }
New to GrepCode? Check out our FAQ X