/* * [DescribedMaxiFD.java] * * Summary: File Descriptor with an additional notation. * * Copyright: (c) 2011-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.0 2011-09-07 initial version. */ package com.mindprod.replicatorsender; import com.mindprod.fastcat.FastCat; import com.mindprod.replicatorcommon.FilenameContext; import java.text.SimpleDateFormat; import java.util.Date; /** * File Descriptor with an additional notation. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2011-09-07 initial version. * @since 2011-09-07 */ final class DescribedMaxiFD implements Comparable { /** * Date format mask for: 2005-01-20 23:59 GMT */ private static final SimpleDateFormat DF = new SimpleDateFormat( "yyyy-MM-dd HH:mm zz" ); /** * descriptor for a file we distribute */ private final MaxiFD maxiFD; /** * notation e.g. "oldest redeleted file" */ private final String notation; /** * Constructor * * @param maxiFD maxiFD. We will pad other fields out later. * @param notation e.g. "oldest redeleted file" */ DescribedMaxiFD( MaxiFD maxiFD, String notation ) { this.maxiFD = maxiFD; this.notation = notation; } /** * prepare a display string for a File Description with filename, time and description. * * @return display string */ String displayFDNameAndTime() { if ( maxiFD != null ) { final FastCat sb = new FastCat( 6 ); sb.append( notation ); sb.append( ": " ); sb.append( maxiFD.getFilename( FilenameContext.INSIDE_ZIP ) ); sb.append( ' ' ); sb.append( DF.format( new Date( maxiFD.getClumping() ) ) ); // usually the same as getTimeStamp. sb.append( '\n' ); return sb.toString(); } else { return ""; } } /** * Sort by date/time. * Defines default the sort order for DescribedMaxiFD Objects. * Compare this DescribedMaxiFD with another DescribedMaxiFD with JDK 1.5+ generics. * Compares maxiFD.getTimestamp() numerically. * Informally, returns (this-other) or +ve if this sorts after other. * The Java source code for this Comparable implementation was generated by the * Canadian Mind Products ComparatorCutter Applet at http://mindprod.com/applet/comparatorcutter.html * * @param other other DescribedMaxiFD to compare with this one * * @return +ve if this>other, 0 if this==other, -ve if this<other */ public final int compareTo( DescribedMaxiFD other ) { // Long.compare only available in Java 1.7+ // return Misc.signum( this.maxiFD.getClumping() - other.maxiFD.getClumping() ); return Long.compare( this.maxiFD.getClumping(), other.maxiFD.getClumping() ); } }