/* * [Changes.java] * * Summary: Notice the changes between files we distributed before and what we are about to distribute. * * 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: * 10.2 2009-04-03 tidy up code to check presence of necessary files to make it more WORA. * When done have filesToDistribute sorted by MaxiFD.BY_DATE_AND_FILENAME */ package com.mindprod.replicatorsender; import com.mindprod.sorted.Merge; import com.mindprod.sorted.SortedArrayList; /** * Notice the changes between files we distributed before and what we are about to distribute. * * @author Roedy Green, Canadian Mind Products * @version 10.2 2009-04-03 tidy up code to check presence of necessary files to make it more WORA. * When done have filesToDistribute sorted by MaxiFD.BY_DATE_AND_FILENAME * @since 2002-09-10 */ final class Changes { /** * Avoid repacking unchanged, still extant files in new zips. */ @SuppressWarnings( { "UnusedAssignment" } ) private static void avoidAlreadyDistributed() { // compare by filename and elapsedTime, old in zip replaces new if totally // unchanged. // If timestamps don't match, we use the new file, otherwise the old. ReplicatorSender.oldFilesDistributed .sort( MaxiFD.BY_DATE_AND_FILENAME ); // collect unchanged, just to get count SortedArrayList unchanged = Merge.intersection( ReplicatorSender.oldFilesDistributed, ReplicatorSender.filesToDistribute, MaxiFD.BY_DATE_AND_FILENAME ); StatsForSender.recentUnchangedFilesCount = unchanged.size(); unchanged = null; // free RAM // mixture of old, updated and new, no deletions. ReplicatorSender.filesToDistribute = Merge.replace( ReplicatorSender.filesToDistribute, ReplicatorSender.oldFilesDistributed, MaxiFD.BY_DATE_AND_FILENAME ); StatsForSender.recentNewFilesCount = ReplicatorSender.filesToDistribute.size() - StatsForSender.recentUnchangedFilesCount - StatsForSender.recentUpdatedFilesCount; } /** * Newly appearing files with old dates, must be given recent clumping dates to be handled properly. It is too late * to assign them to the natural zip. They must be lumped just before the new files. */ private static void handleLateArrivals() { // newly appearing files prior to this cutoff date will have to be // redated so they will fit in a new jar. ReplicatorSender.filesToDistribute .sort( MaxiFD.BY_DATE_AND_FILENAME ); for ( MaxiFD fd : ReplicatorSender.filesToDistribute ) { if ( fd.getTimestamp() >= ReplicatorSender.cutOffTimestamp ) { break; } if ( fd.getZipNumber() == 0 ) { // does not disturb BY_DATE_AND_FILENAME order. fd.setClumping( ReplicatorSender.cutOffTimestamp ); } } // end for } /** * detect and handle changes since last distribution. */ public static void process() { avoidAlreadyDistributed(); handleLateArrivals(); StatsForSender.activeFilesCount = ReplicatorSender.filesToDistribute.size(); } }