<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package usda.weru.util;

import de.schlichtherle.truezip.file.TFile;

/**
 *
 * @author Joseph Levin &lt;joelevin@weru.ksu.edu&gt;
 */
public class FileAgeChecksum {

    private final TFile c_file;
    private long c_ageMin;
    private long c_ageMean;
    private long c_ageMax;
    private int c_n;

	/**
	 *
	 * @param file
	 */
	public FileAgeChecksum(TFile file) {
        c_file = file;
        if (c_file == null) {
            return;
        }

        c_ageMin = c_file.lastModified();
        c_ageMax = c_ageMin;
        c_ageMean = c_ageMin;
        c_n = 1;
        TFile[] children = c_file.listFiles();
        if (children != null) {
            for (TFile child : children) {
                c_ageMin = Math.min(c_ageMin, child.lastModified());
                c_ageMax = Math.max(c_ageMax, child.lastModified());
                c_ageMean = ((c_ageMean * c_n++) + child.lastModified()) / c_n;
            }
        }
    }

	/**
	 *
	 * @param obj
	 * @return
	 */
	@Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final FileAgeChecksum other = (FileAgeChecksum) obj;
        if (this.c_ageMin != other.c_ageMin) {
            return false;
        }
        if (this.c_ageMean != other.c_ageMean) {
            return false;
        }
        if (this.c_ageMax != other.c_ageMax) {
            return false;
        }
        if (this.c_n != other.c_n) {
            return false;
        }
        return true;
    }

	/**
	 *
	 * @return
	 */
	@Override
    public int hashCode() {
        int hash = 5;
        hash = 79 * hash + (int) (this.c_ageMin ^ (this.c_ageMin &gt;&gt;&gt; 32));
        hash = 79 * hash + (int) (this.c_ageMean ^ (this.c_ageMean &gt;&gt;&gt; 32));
        hash = 79 * hash + (int) (this.c_ageMax ^ (this.c_ageMax &gt;&gt;&gt; 32));
        hash = 79 * hash + this.c_n;
        return hash;
    }

	/**
	 *
	 * @return
	 */
	public boolean isUpToDate(){
        return equals(new FileAgeChecksum(c_file));
    }
}


</pre></body></html>