Example usage for org.joda.time Minutes isGreaterThan

List of usage examples for org.joda.time Minutes isGreaterThan

Introduction

In this page you can find the example usage for org.joda.time Minutes isGreaterThan.

Prototype

public boolean isGreaterThan(Minutes other) 

Source Link

Document

Is this minutes instance greater than the specified number of minutes.

Usage

From source file:org.artifactory.cron.CronUtils.java

License:Open Source License

/**
 * Checks if the given cron expression interval is less or equals to a certain minimum.
 *
 * @param cronExpression the cron expression to check
 *//*w  w  w  .j  a  va 2s  .c  o m*/
public static boolean isCronIntervalLessThanMinimum(String cronExpression) {
    try {
        // If input is empty or invalid simply return false as default
        if (StringUtils.isBlank(cronExpression) || !isValid(cronExpression)) {
            return false;
        }

        CronExpression cron = new CronExpression(cronExpression);
        final Date firstExecution = cron.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
        final Date secondExecution = cron.getNextValidTimeAfter(firstExecution);

        Minutes intervalMinutes = Minutes.minutesBetween(new DateTime(firstExecution),
                new DateTime(secondExecution));
        return !intervalMinutes.isGreaterThan(MINIMUM_ALLOWED_MINUTES);
    } catch (ParseException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}