Example usage for java.util Calendar before

List of usage examples for java.util Calendar before

Introduction

In this page you can find the example usage for java.util Calendar before.

Prototype

public boolean before(Object when) 

Source Link

Document

Returns whether this Calendar represents a time before the time represented by the specified Object.

Usage

From source file:com.ecofactor.qa.automation.newapp.service.MockDataServiceImpl.java

/**
 * List events./*from   w w  w  .j a  v  a  2 s.  co  m*/
 * 
 * @param thermostatId
 *            the thermostat id
 * @param startTime
 *            the start time
 * @param endTime
 *            the end time
 * @return the list
 * @see com.ecofactor.qa.automation.algorithm.service.DataService#listEvents(java.lang.Integer,
 *      java.util.Calendar, java.util.Calendar)
 */
@Override
public List<PartitionedThermostatEvent> listEvents(Integer thermostatId, Calendar startTime, Calendar endTime) {

    loadEvents(thermostatId);
    List<PartitionedThermostatEvent> events = new ArrayList<PartitionedThermostatEvent>();
    Set<Calendar> timeSet = timeEventMap.keySet();
    Calendar startTimeUTC = DateUtil.copyToUTC(startTime);
    Calendar endTimeUTC = DateUtil.copyToUTC(endTime);
    for (Calendar time : timeSet) {
        LOGGER.info("Checking event for " + DateUtil.format(time, DateUtil.DATE_FMT_FULL_TZ) + " "
                + timeEventMap.get(time).getAlgorithmId() + ", "
                + DateUtil.format(startTimeUTC, DateUtil.DATE_FMT_FULL_TZ) + ", "
                + DateUtil.format(endTimeUTC, DateUtil.DATE_FMT_FULL_TZ));
        if (time.after(startTimeUTC) && time.before(endTimeUTC)) {
            events.add(timeEventMap.get(time));
            LOGGER.info("Including event for " + DateUtil.format(time, DateUtil.DATE_FMT_FULL_TZ));
        }
    }

    return events;
}

From source file:com.aerospike.examples.timeseries.TimeSeriesManipulator.java

public void run() throws ParseException, FileNotFoundException, IOException, InterruptedException {
    GregorianCalendar cal = new GregorianCalendar();
    //String formattedDate = new String();
    String[] tokens;/*from ww  w  .j  av a  2 s . c om*/
    String[] ticker;
    if (tickerList != null) {
        ticker = timeParser.parse(tickerList);
    } else {
        ticker = new String[0];
    }
    long token;
    if (this.operation.contains("L")) {
        System.out.println("****************************************");
        System.out.println("Loading Data");
        System.out.println("****************************************");
        if (this.days != null) {
            if (ticker != null) {
                for (int i = 0; i < ticker.length; i++) {
                    this.sum = 0;
                    try (BufferedReader br = getStocks(this.days, ticker[i])) {
                        String line;
                        while ((line = br.readLine()) != null) {
                            if (line.startsWith("a")) {
                                this.sum = 0;
                                tokens = timeParser.parse(line);
                                token = new Long(tokens[0].substring(1)).longValue() * 1000L;
                                cal.setTimeInMillis(token);
                                //formattedDate = dateOp.dateFormatter(cal.getTime());
                                this.updateTimeSeries(ticker[i], cal.getTime(), line);
                                Date insertDate = dateOp.getDate(cal.getTime());
                                this.dateList.add(insertDate.getTime());
                            } else if ((!line.startsWith("EXCHANGE")) && (!line.startsWith("MARKET"))
                                    && (!line.startsWith("INTERVAL")) && (!line.startsWith("COLUMNS"))
                                    && (!line.startsWith("DATA")) && (!line.startsWith("TIMEZONE"))) {
                                this.updateTimeSeries(ticker[i], cal.getTime(), line);

                            }
                        }
                    }
                }
            }
        } else {
            try (BufferedReader br = new BufferedReader(new FileReader("stocktick.txt"))) {
                String line;
                while ((line = br.readLine()) != null) {
                    if (line.startsWith("a")) {
                        tokens = timeParser.parse(line);
                        token = new Long(tokens[0].substring(1)).longValue() * 1000L;
                        cal.setTimeInMillis(token);
                        //formattedDate = dateOp.dateFormatter(cal.getTime());
                        Date insertDate = dateOp.getDate(cal.getTime());
                        this.updateTimeSeries(ticker[0], cal.getTime(), line);
                        this.dateList.add(insertDate.getTime());
                    } else if ((!line.startsWith("EXCHANGE")) && (!line.startsWith("MARKET"))
                            && (!line.startsWith("INTERVAL")) && (!line.startsWith("COLUMNS"))
                            && (!line.startsWith("DATA")) && (!line.startsWith("TIMEZONE"))) {
                        if (ticker != null)
                            this.updateTimeSeries(ticker[0], cal.getTime(), line);

                    }
                }
            }
        }
        System.out.println("****************************************");
        System.out.println("Loading Complete");
        System.out.println("****************************************");
    }
    Calendar startCal = Calendar.getInstance();
    Calendar endCal = Calendar.getInstance();
    int count = 0;
    if (this.operation.contains("R")) {
        //if (this.startString.equals(null) && this.endString.equals(null)) {
        if (this.operation.contains("L")) {
            count++;
            this.retrieveResult(ticker, this.dateList);
        } else {
            count++;

            int[] startList = timeParser.getCalDate(this.startString);
            if (startList[0] > 0 && startList[1] > 0 && startList[2] > 0) {
                startCal = new GregorianCalendar(startList[2], startList[1] - 1, startList[0]);
            } else {
                System.out.println("Invalid Start Date Format. Specify as dd/MM/yyyy");
                System.exit(0);
            }
            int[] endList = timeParser.getCalDate(this.endString);
            if (endList[0] > 0 && endList[1] > 0 && endList[2] > 0) {
                endCal = new GregorianCalendar(endList[2], endList[1] - 1, endList[0]);
            } else {
                System.out.println("Invalid End Date Format. Specify as dd/MM/yyyy");
                System.exit(0);
            }
            if (!endCal.before(startCal))
                this.retrieveResult(ticker, startCal.getTime(), endCal.getTime());
            else
                System.out.println("Invalid Dates. Start Date is greater than End Date");
        }

    }
    if (this.operation.contains("R") && count == 0)
        System.out.println("Invalid Operation. Use L or R");

}

From source file:stg.utils.immutable.Day.java

/**
 * The number of months between this and day parameter
 * /*from   w  ww.j  a  va2 s.c  o m*/
 * @param b
 *            any date
 * @return the number of days between this and day parameter and b (> 0 if
 *         this day comes after b)
 */
public int monthsBetween(Day b) {
    Calendar gcThisDay = getCalendarInstance(tzone);
    gcThisDay.setTime(this.getUtilDate());
    Calendar gcTarget = getCalendarInstance(tzone);
    gcTarget.setTime(b.getUtilDate());

    int iMonthsBetween = 0;
    if (gcThisDay.after(gcTarget)) {
        while (gcThisDay.after(gcTarget)) {
            gcTarget.add(Calendar.MONTH, 1);
            if (gcThisDay.after(gcTarget))
                iMonthsBetween++;
            if (gcThisDay.equals(gcTarget)) {
                iMonthsBetween++;
                break;
            }
        }
    } else if (gcThisDay.before(gcTarget)) {
        while (gcThisDay.before(gcTarget)) {
            gcThisDay.add(Calendar.MONTH, 1);
            if (gcThisDay.before(gcTarget)) {
                iMonthsBetween++;
            } else if (gcThisDay.equals(gcTarget)) {
                iMonthsBetween++;
                break;
            }
        }
    }

    return (iMonthsBetween);
}

From source file:org.simbasecurity.core.saml.SAMLResponseHandlerImpl.java

/**
 * Verifies that the document is still valid according Conditions Element.
 *
 * @return true if still valid// w w w.  ja  v a  2  s.  co m
 */
private boolean validateTimestamps() {
    NodeList timestampNodes = document.getElementsByTagNameNS("*", "Conditions");
    if (timestampNodes.getLength() != 0) {
        for (int i = 0; i < timestampNodes.getLength(); i++) {
            NamedNodeMap attrName = timestampNodes.item(i).getAttributes();
            Node nbAttribute = attrName.getNamedItem("NotBefore");
            Node naAttribute = attrName.getNamedItem("NotOnOrAfter");
            Calendar now = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            log.debug("now :" + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":"
                    + now.get(Calendar.SECOND));
            // validate NotOnOrAfter using UTC
            if (naAttribute != null) {
                final Calendar notOnOrAfterDate = javax.xml.bind.DatatypeConverter
                        .parseDateTime(naAttribute.getNodeValue());
                log.debug("notOnOrAfterDate :" + notOnOrAfterDate.get(Calendar.HOUR_OF_DAY) + ":"
                        + notOnOrAfterDate.get(Calendar.MINUTE) + ":" + notOnOrAfterDate.get(Calendar.SECOND));
                if (now.equals(notOnOrAfterDate) || now.after(notOnOrAfterDate)) {
                    return false;
                }
            }
            // validate NotBefore using UTC
            if (nbAttribute != null) {
                final Calendar notBeforeDate = javax.xml.bind.DatatypeConverter
                        .parseDateTime(nbAttribute.getNodeValue());
                log.debug("notBeforeDate :" + notBeforeDate.get(Calendar.HOUR_OF_DAY) + ":"
                        + notBeforeDate.get(Calendar.MINUTE) + ":" + notBeforeDate.get(Calendar.SECOND));
                if (now.before(notBeforeDate)) {
                    return false;
                }
            }
        }
    }
    return true;
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartHelper.java

/***********************************************************************************************
 * Crop the specified Vector of CalendarisedData to the range given by the start and end Calendars.
 * Return the cropped CalendarisedData, or NULL on failure.
 *
 * @param calendariseddata//www .ja  v  a 2s.  c o m
 * @param startcalendar
 * @param endcalendar
 *
 * @return Vector<Object>
 */

public static Vector<Object> cropCalendarisedDataToRange(final Vector<Object> calendariseddata,
        final Calendar startcalendar, final Calendar endcalendar) {
    Vector<Object> vecCropped;

    vecCropped = null;

    if ((calendariseddata != null) && (!calendariseddata.isEmpty()) && (startcalendar != null)
            && (endcalendar != null)) {
        vecCropped = new Vector<Object>(calendariseddata.size());

        for (int intDataIndex = 0; intDataIndex < calendariseddata.size(); intDataIndex++) {
            final Vector<Object> vecRow;
            final Calendar calendarRow;

            vecRow = (Vector) calendariseddata.get(intDataIndex);

            // We can safely assume that the data Vector is calendarised
            calendarRow = (Calendar) vecRow.get(DataTranslatorInterface.INDEX_TIMESTAMPED_CALENDAR);

            if ((calendarRow.equals(startcalendar) || calendarRow.after(startcalendar))
                    && (calendarRow.before(endcalendar) || calendarRow.equals(endcalendar))) {
                vecCropped.add(vecRow);
            }
        }
    }

    // Did we gather any data?
    if ((vecCropped != null) && (vecCropped.isEmpty())) {
        // Return NULL on failure
        vecCropped = null;
    }

    return (vecCropped);
}

From source file:com.aipo.social.opensocial.spi.AipoStorageService.java

@Override
public boolean deleteOldFolder(String folderPath, Calendar cal, SecurityToken paramSecurityToken)
        throws ProtocolException {
    Calendar mod = Calendar.getInstance();
    boolean flag = true;
    File parent_folder = new File(getAbsolutePath(folderPath));
    try {//from   w w  w.ja  v a  2s  .  com
        if (!parent_folder.exists()) {
            return false;
        }
        if (parent_folder.isFile()) {
            return false;
        }
        String folders_path[] = parent_folder.list();
        if (folders_path.length == 0) {
            return true;
        }
        int length = folders_path.length;
        for (int i = 0; i < length; i++) {
            File folder = new File(parent_folder.getAbsolutePath() + File.separator + folders_path[i]);
            mod.setTimeInMillis(folder.lastModified());// ??
            if (folder.isDirectory()) {
                if (!deleteOldFolder(folder.getAbsolutePath(), cal, paramSecurityToken)) {// ?????????
                    flag = false;
                } else if (mod.before(cal)) {// ?????
                    if (!folder.delete()) {
                        flag = false;
                    }
                }
            } else {
                if (mod.before(cal)) {
                    // ??????????
                    if (!folder.delete()) {
                        flag = false;
                    }
                } else {
                    flag = false;
                }
            }

        }
    } catch (Exception e) {
        return false;
    }
    return flag;
}

From source file:com.ecofactor.qa.automation.newapp.service.BaseDataServiceImpl.java

/**
 * Wait and verify st events fired.//from ww  w  .j a v  a  2s .  c o  m
 * @param thermostatId the thermostat id
 * @param algoId the algo id
 * @see com.ecofactor.qa.automation.algorithm.service.DataService#waitAndVerifySTEventsFired(java.lang.Integer,
 *      int)
 */
public void waitAndVerifySTEventsFired(Integer thermostatId, int algoId) {

    DriverConfig.setLogString(
            "Wait for Thermostat : " + thermostatId + ", Algo Id : " + algoId + " in algo control table", true);

    boolean isNextPhaseFuture = false;
    Algorithm algorithm = findByAlgorithmId(algoId);
    Integer phaseDuration = (int) ((2.5) * (int) (algorithm.getPhaseDuration()));
    Calendar endTime = DateUtil.getUTCCalendar();
    endTime.add(Calendar.SECOND, phaseDuration);

    Calendar currentTime = DateUtil.getUTCCalendar();
    do {
        DriverConfig.setLogString("Current time : " + DateUtil.format(currentTime, DateUtil.DATE_FMT_FULL_TZ)
                + ", " + "End time : " + DateUtil.format(endTime, DateUtil.DATE_FMT_FULL_TZ), true);
        largeWait();

        verifyAlgorithmStatus(thermostatId, algoId);

        List<ThermostatAlgorithmController> activeAlgoControlList = listActiveAlgoControl(thermostatId, algoId);
        if (activeAlgoControlList != null && activeAlgoControlList.size() > 0) {
            currentTime = DateUtil.getUTCCalendar();
            ThermostatAlgorithmController algoController = activeAlgoControlList.get(0);
            Calendar nextPhaseCalendar = algoController.getNextPhaseTime();
            String nextPhaseTimeStamp = DateUtil.format(nextPhaseCalendar, DateUtil.DATE_FMT_FULL);
            nextPhaseCalendar = DateUtil.parseToUTCCalendar(nextPhaseTimeStamp, DateUtil.DATE_FMT_FULL);

            DriverConfig.setLogString(
                    "Next Phase time : " + DateUtil.format(nextPhaseCalendar, DateUtil.DATE_FMT_FULL_TZ), true);
            if (nextPhaseCalendar.after(currentTime)) {
                isNextPhaseFuture = true;
                break;
            }
        }
        currentTime = DateUtil.getUTCCalendar();
    } while (currentTime.before(endTime));

    if (!isNextPhaseFuture) {
        DriverConfig.setLogString("ST Events shows past time for thermostat : " + thermostatId, true);
    }
    Assert.assertTrue(isNextPhaseFuture,
            "Waited for a period and next phase time shows past record for thermostat: " + thermostatId);
}

From source file:org.kuali.kfs.module.ld.batch.service.impl.LaborScrubberProcess.java

protected boolean isCurrentDateBeforeCutoff(Calendar currentCal) {
    if (cutoffHour != null && cutoffMinute != null && cutoffSecond != null) {
        // if cutoff date is not properly defined
        // 24 hour clock (i.e. hour is 0 - 23)

        // clone the calendar so we get the same month, day, year
        // then change the hour, minute, second fields
        // then see if the cutoff is before or after
        Calendar cutoffTime = (Calendar) currentCal.clone();
        cutoffTime.setLenient(false);/*from  w w  w .  j  av  a2s  . co m*/
        cutoffTime.set(Calendar.HOUR_OF_DAY, cutoffHour);
        cutoffTime.set(Calendar.MINUTE, cutoffMinute);
        cutoffTime.set(Calendar.SECOND, cutoffSecond);
        cutoffTime.set(Calendar.MILLISECOND, 0);

        return currentCal.before(cutoffTime);
    }
    // if cutoff date is not properly defined, then it is considered to be after the cutoff
    return false;
}

From source file:com.aurel.track.report.dashboard.BurnDownChart.java

public SortedMap<Integer, SortedMap<Integer, Double>> calculatePlannedValuesDependingOnEffortType(
        Date minStartDate, Date maxEndDate, Integer timeInterval, Integer selectedEffortType) {

    SortedMap<Integer, SortedMap<Integer, Double>> yearToIntervalToPlannedValue = new TreeMap<Integer, SortedMap<Integer, Double>>();
    if (reportBeanWithHistoryList != null) {
        Calendar calendarStartDate = Calendar.getInstance();
        Calendar calendarEndDate = Calendar.getInstance();
        Calendar calendar = Calendar.getInstance();
        //to avoid that the last days of the year to be taken as the first
        //week of the now year but the year remains the old one
        int calendarInterval = EarnedValueDatasource.getCalendarInterval(timeInterval);
        for (ReportBean reportBean : reportBeanWithHistoryList) {
            TWorkItemBean workItemBean = reportBean.getWorkItemBean();
            Date startDate = workItemBean.getStartDate();
            Date endDate = workItemBean.getEndDate();
            if (startDate == null || endDate == null) {
                continue;
            }//from   www.j a va  2 s .  c  o  m

            calendarStartDate.setTime(dateFrom);
            calendarEndDate.setTime(dateTo);
            calendar.setTime(dateFrom);
            int yearValue = calendarStartDate.get(Calendar.YEAR);
            int intervalValue = calendarStartDate.get(calendarInterval);
            boolean isFirst = true;
            while (calendar.before(calendarEndDate) || isFirst) {
                if (isFirst) {
                    isFirst = false;
                } else {
                    calendar.add(calendarInterval, 1);
                }
                yearValue = calendar.get(Calendar.YEAR);
                intervalValue = calendar.get(calendarInterval);
                SortedMap<Integer, Double> intervalToPlannedValues = yearToIntervalToPlannedValue
                        .get(Integer.valueOf(yearValue));
                if (intervalToPlannedValues == null) {
                    yearToIntervalToPlannedValue.put(new Integer(yearValue), new TreeMap<Integer, Double>());
                    intervalToPlannedValues = yearToIntervalToPlannedValue.get(Integer.valueOf(yearValue));
                }
                Double totalPlannedValueForInterval = intervalToPlannedValues
                        .get(Integer.valueOf(intervalValue));
                if (totalPlannedValueForInterval == null) {
                    totalPlannedValueForInterval = 0.0;
                }
                if (DateTimeUtils.less(calendar.getTime(), endDate)) {
                    if (selectedEffortType == EFFORT_TYPE.NR_OF_ITEMS_IN_INTERVAL) {
                        totalPlannedValueForInterval += 1.0;
                    } else {
                        Integer storyPointValueID = getStoryPointValueID(workItemBean,
                                customFieldIDForStoryPoint);
                        if (storyPointValueID != null) {
                            Integer storyPointValue = storyPointValueIDToValueMap.get(storyPointValueID);
                            if (storyPointValue != null) {
                                totalPlannedValueForInterval += storyPointValue;
                            }
                        }
                    }
                }
                intervalToPlannedValues.put(Integer.valueOf(intervalValue), totalPlannedValueForInterval);
            }
        }
    }
    return yearToIntervalToPlannedValue;
}

From source file:com.adobe.acs.commons.workflow.bulk.removal.impl.WorkflowInstanceRemoverImpl.java

/**
 * {@inheritDoc}/*from   w w w  .j  av a  2s.  co  m*/
 */
@SuppressWarnings({ "squid:S3776", "squid:S1141" })
public int removeWorkflowInstances(final ResourceResolver resourceResolver, final Collection<String> modelIds,
        final Collection<String> statuses, final Collection<Pattern> payloads, final Calendar olderThan,
        final int batchSize, final int maxDurationInMins) throws PersistenceException, WorkflowRemovalException,
        InterruptedException, WorkflowRemovalForceQuitException {

    final long start = System.currentTimeMillis();
    long end = -1;

    int count = 0;
    int checkedCount = 0;
    int workflowRemovedCount = 0;

    if (maxDurationInMins > 0) {
        // Max duration has been requested (greater than 0)

        // Convert minutes to milliseconds
        long maxDurationInMs = maxDurationInMins * MS_IN_ONE_MINUTE;

        // Compute the end time
        end = start + maxDurationInMs;
    }

    try {
        this.start(resourceResolver);

        final List<Resource> containerFolders = this.getWorkflowInstanceFolders(resourceResolver);

        for (Resource containerFolder : containerFolders) {
            log.debug("Checking [ {} ] for workflow instances to remove", containerFolder.getPath());

            final Collection<Resource> sortedFolders = this.getSortedAndFilteredFolders(containerFolder);

            for (final Resource folder : sortedFolders) {

                int remaining = 0;

                for (final Resource instance : folder.getChildren()) {

                    if (this.forceQuit.get()) {
                        throw new WorkflowRemovalForceQuitException();
                    } else if (end > 0 && System.currentTimeMillis() >= end) {
                        throw new WorkflowRemovalMaxDurationExceededException();
                    }

                    final ValueMap properties = instance.getValueMap();

                    if (!StringUtils.equals(NT_CQ_WORKFLOW,
                            properties.get(JcrConstants.JCR_PRIMARYTYPE, String.class))) {

                        // Only process cq:Workflow's
                        remaining++;
                        continue;
                    }

                    checkedCount++;

                    final String instanceStatus = getStatus(instance);
                    final String model = properties.get(PN_MODEL_ID, String.class);
                    final Calendar startTime = properties.get(PN_STARTED_AT, Calendar.class);
                    final String payload = properties.get(PAYLOAD_PATH, String.class);

                    if (StringUtils.isBlank(payload)) {
                        log.warn("Unable to find payload for Workflow instance [ {} ]", instance.getPath());
                        remaining++;
                        continue;
                    } else if (CollectionUtils.isNotEmpty(statuses) && !statuses.contains(instanceStatus)) {
                        log.trace("Workflow instance [ {} ] has non-matching status of [ {} ]",
                                instance.getPath(), instanceStatus);
                        remaining++;
                        continue;
                    } else if (CollectionUtils.isNotEmpty(modelIds) && !modelIds.contains(model)) {
                        log.trace("Workflow instance [ {} ] has non-matching model of [ {} ]",
                                instance.getPath(), model);
                        remaining++;
                        continue;
                    } else if (olderThan != null && startTime != null && startTime.before(olderThan)) {
                        log.trace("Workflow instance [ {} ] has non-matching start time of [ {} ]",
                                instance.getPath(), startTime);
                        remaining++;
                        continue;
                    } else {

                        if (CollectionUtils.isNotEmpty(payloads)) {
                            // Only evaluate payload patterns if they are provided

                            boolean match = false;

                            if (StringUtils.isNotEmpty(payload)) {
                                for (final Pattern pattern : payloads) {
                                    if (payload.matches(pattern.pattern())) {
                                        // payload matches a pattern
                                        match = true;
                                        break;
                                    }
                                }

                                if (!match) {
                                    // Not a match; skip to next workflow instance
                                    log.trace("Workflow instance [ {} ] has non-matching payload path [ {} ]",
                                            instance.getPath(), payload);
                                    remaining++;
                                    continue;
                                }
                            }
                        }

                        // Only remove matching

                        try {
                            instance.adaptTo(Node.class).remove();
                            log.debug("Removed workflow instance at [ {} ]", instance.getPath());

                            workflowRemovedCount++;
                            count++;
                        } catch (RepositoryException e) {
                            log.error("Could not remove workflow instance at [ {} ]. Continuing...",
                                    instance.getPath(), e);
                        }

                        if (count % batchSize == 0) {
                            this.batchComplete(resourceResolver, checkedCount, workflowRemovedCount);

                            log.info("Removed a running total of [ {} ] workflow instances", count);
                        }
                    }
                }

                if (remaining == 0 && isWorkflowDatedFolder(folder) && !StringUtils.startsWith(folder.getName(),
                        new SimpleDateFormat(WORKFLOW_FOLDER_FORMAT).format(new Date()))) {
                    // Dont remove folders w items and dont remove any of "today's" folders
                    // MUST match the YYYY-MM-DD(.*) pattern; do not try to remove root folders
                    try {
                        folder.adaptTo(Node.class).remove();
                        log.debug("Removed empty workflow folder node [ {} ]", folder.getPath());
                        // Incrementing only count to trigger batch save and not total since is not a WF
                        count++;
                    } catch (RepositoryException e) {
                        log.error("Could not remove workflow folder at [ {} ]", folder.getPath(), e);
                    }
                }
            }

            // Save final batch if needed, and update tracking nodes
            this.complete(resourceResolver, checkedCount, workflowRemovedCount);
        }

    } catch (PersistenceException e) {
        this.forceQuit.set(false);
        log.error("Error persisting changes with Workflow Removal", e);
        this.error();
        throw e;
    } catch (WorkflowRemovalException e) {
        this.forceQuit.set(false);
        log.error("Error with Workflow Removal", e);
        this.error();
        throw e;
    } catch (InterruptedException e) {
        this.forceQuit.set(false);
        log.error("Errors in persistence retries during Workflow Removal", e);
        this.error();
        throw e;
    } catch (WorkflowRemovalForceQuitException e) {
        this.forceQuit.set(false);
        // Uncommon instance of using Exception to control flow; Force quitting is an extreme condition.
        log.warn("Workflow removal was force quit. The removal state is unknown.");
        this.internalForceQuit();
        throw e;
    } catch (WorkflowRemovalMaxDurationExceededException e) {
        // Uncommon instance of using Exception to control flow; Exceeding max duration extreme condition.
        log.warn("Workflow removal exceeded max duration of [ {} ] minutes. Final removal commit initiating...",
                maxDurationInMins);
        this.complete(resourceResolver, checkedCount, count);
    }

    if (log.isInfoEnabled()) {
        log.info(
                "Workflow Removal Process Finished! "
                        + "Removed a total of [ {} ] workflow instances in [ {} ] ms",
                count, System.currentTimeMillis() - start);
    }

    return count;
}