All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.torque.util.ChangeDetector Maven / Gradle / Ivy

package org.apache.torque.util;

import java.io.File;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ChangeDetector {

	private static final Log log = LogFactory.getLog(ChangeDetector.class);
	File controlFile;
	List files;

	public ChangeDetector() {
		this(null, null);
	}

	public ChangeDetector(File controlFile, List files) {
		super();
		this.controlFile = controlFile;
		this.files = files;
	}

	/**
	 * Return true if any file in the list of files has a last modified timestamp newer than the control file or if the
	 * control file does not exist
	 */
	public boolean isChanged() {
		if (!getControlFile().exists()) {
			log.debug("File " + getControlFile().getAbsolutePath() + " does not exist.  Returning true");
			return true;
		}
		long lastModified = getControlFile().lastModified();
		for (File file : getFiles()) {
			if (file.lastModified() > lastModified) {
				log.debug("File " + file.getAbsolutePath() + " was modified after " + getControlFile().getAbsolutePath() + " was last modified");
				return true;
			}
		}
		log.debug("No files were modified.");
		return false;
	}

	public File getControlFile() {
		return controlFile;
	}

	public void setControlFile(File controlFile) {
		this.controlFile = controlFile;
	}

	public List getFiles() {
		return files;
	}

	public void setFiles(List files) {
		this.files = files;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy