/* * [FileFacts.java] * * Summary: Facts we record on each file in a directory. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.7 2009-01-11 round all file timestamps to nearest milli so original/copied/untouched timestamps will match. */ package com.mindprod.untouch; import java.io.Serializable; /** * Facts we record on each file in a directory. *

* Thes fact lets us set LastChangeDate back to what it was if files have not really changed. * * @author Roedy Green, Canadian Mind Products * @version 1.7 2009-01-11 round all file timestamps to nearest milli so original/copied/untouched timestamps will * match. * @since 2003 */ public final class FileFacts implements Serializable { /** * to prevent spurious InvalidClassExceptions. */ static final long serialVersionUID = 2L; static final long SLOP = 1000 /* treat stamps this close in ms as equal */; /** * name of the file, converted to lower case. */ public final String filename; /** * Adlerian 32 bit checksum the file used to be. */ public final int digest; /** * length the file used to be in bytes. */ public final long fileLength; /** * The lastChangeDate the file used to have. */ public final long lastChangeDate; /** * standard Constructor. * * @param filename name of the file * @param fileLength length of the file * @param lastChangeDate timestamp when file last changed milliseconds since 1970. * @param digest Adlerian 32 bit checksum of the file. */ public FileFacts( String filename, long fileLength, long lastChangeDate, int digest ) { this.filename = filename; this.fileLength = fileLength; this.lastChangeDate = lastChangeDate; this.digest = digest; } /** * Compare another FileFacts object with this one. * * @param other FileFacts to compare with this one. * * @return true if the same fields. */ @SuppressWarnings( { "BooleanMethodIsAlwaysInverted" } ) public boolean equals( FileFacts other ) { return digest == other.digest && fileLength == other.fileLength && Math.abs( lastChangeDate - other.lastChangeDate ) <= SLOP && filename.equals( other.filename ); } }