package org.sugarj.cleardep.stamp;

import java.util.HashMap;
import java.util.Map;

import org.sugarj.common.FileCommands;
import org.sugarj.common.path.Path;

/**
 * @author Sebastian Erdweg
 *
 */
public class LastModifiedStamper implements Stamper {

  private static final long serialVersionUID = 8242859577253542194L;

  private LastModifiedStamper() {}
  public static final Stamper instance = new LastModifiedStamper();
  
  /**
   * @see org.sugarj.cleardep.stamp.Stamper#stampOf(org.sugarj.common.path.Path)
   */
  @Override
  public Stamp stampOf(Path p) {
    if (!FileCommands.exists(p))
      return new ValueStamp<>(this, 0l);
    
    if (p.getFile().isDirectory()) {
      Map<Path, Stamp> stamps = new HashMap<>();
      stamps.put(p, stampOf(p));
      
      for (Path sub : FileCommands.listFilesRecursive(p))
        stamps.put(sub, stampOf(sub));
      
      return new ValueStamp<>(this, stamps);
    }
    
    return new ValueStamp<>(this, p.getFile().lastModified());
  }
}

@@ -751,17 +751,57 @@
 (p, 
-stampOf(p
+new ValueStamp%3C%3E(this, p.getFile().lastModified()
 ));%0A
@@ -893,19 +893,59 @@
 ub, 
-stampOf(sub
+new ValueStamp%3C%3E(this, sub.getFile().lastModified()
 ));%0A

fix stack overflow