Example usage for org.joda.time Duration compareTo

List of usage examples for org.joda.time Duration compareTo

Introduction

In this page you can find the example usage for org.joda.time Duration compareTo.

Prototype

public int compareTo(ReadableDuration other) 

Source Link

Document

Compares this duration with the specified duration based on length and direction.

Usage

From source file:com.chessix.vas.actors.JournalActor.java

License:Apache License

/**
 * Update the time delay between creation of the message and processing it.
 *//*from  www  . j  a  va 2  s . co m*/
private void updateTimeDelay(final Date timestamp) {
    final Duration d = new Interval(new DateTime(timestamp), DateTime.now()).toDuration();
    if ((delay == null) || (d.compareTo(delay) > 0)) {
        delay = d;
    }
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

/**
 * <code>null</code> safe compare.<br>
 * Note: it has the same semantics as//from w w  w.  j  a va2  s  .  co  m
 * {@link com.phloc.commons.compare.CompareUtils#nullSafeCompare(Comparable, Comparable)}
 * except that the parameter class does not implement
 * {@link java.lang.Comparable} in a Generics-way!
 *
 * @param aDuration1
 *        First object. May be <code>null</code>.
 * @param aDuration2
 *        Second object. May be <code>null</code>.
 * @return -1, 0 or +1
 */
public static int nullSafeCompare(@Nullable final Duration aDuration1, @Nullable final Duration aDuration2) {
    return aDuration1 == aDuration2 ? 0
            : aDuration1 == null ? -1 : aDuration2 == null ? +1 : aDuration1.compareTo(aDuration2);
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

public static boolean isGreater(@Nonnull final Duration aDuration1, @Nonnull final Duration aDuration2) {
    return aDuration1.compareTo(aDuration2) > 0;
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

public static boolean isGreaterOrEqual(@Nonnull final Duration aDuration1, @Nonnull final Duration aDuration2) {
    return aDuration1.compareTo(aDuration2) >= 0;
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

public static boolean isLess(@Nonnull final Duration aDuration1, @Nonnull final Duration aDuration2) {
    return aDuration1.compareTo(aDuration2) < 0;
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

public static boolean isLessOrEqual(@Nonnull final Duration aDuration1, @Nonnull final Duration aDuration2) {
    return aDuration1.compareTo(aDuration2) <= 0;
}

From source file:debop4k.timeperiod.samples.TimeBlockPeriodRelationTestData.java

License:Apache License

public TimeBlockPeriodRelationTestData(DateTime start, DateTime end, Duration duration) {
    assert duration.compareTo(Duration.ZERO) >= 0 : "duration ? 0 ??? ?  .";
    reference = new TimeBlock(start, end, true);

    val beforeEnd = start.minus(duration);
    val beforeStart = beforeEnd.minus(reference.getDuration());
    val insideStart = start.plus(duration);
    val insideEnd = end.minus(duration);
    val afterStart = end.plus(duration);
    val afterEnd = afterStart.plus(reference.getDuration());

    after = new TimeBlock(beforeStart, beforeEnd, true);
    startTouching = new TimeBlock(beforeStart, start, true);
    startInside = new TimeBlock(beforeStart, insideStart, true);
    insideStartTouching = new TimeBlock(start, afterStart, true);
    enclosingStartTouching = new TimeBlock(start, insideEnd, true);
    enclosing = new TimeBlock(insideStart, insideEnd, true);
    enclosingEndTouching = new TimeBlock(insideStart, end, true);
    exactMatch = new TimeBlock(start, end, true);
    inside = new TimeBlock(beforeStart, afterEnd, true);
    insideEndTouching = new TimeBlock(beforeStart, end, true);
    endInside = new TimeBlock(insideEnd, afterEnd, true);
    endTouching = new TimeBlock(end, afterEnd, true);
    before = new TimeBlock(afterStart, afterEnd, true);

    allPeriods.addAll(Arrays.asList(reference, after, startTouching, startInside, insideStartTouching,
            enclosingStartTouching, enclosing, enclosingEndTouching, exactMatch, inside, insideEndTouching,
            endInside, endTouching, before));
}

From source file:debop4k.timeperiod.samples.TimeRangePeriodRelationTestData.java

License:Apache License

public TimeRangePeriodRelationTestData(DateTime start, DateTime end, Duration duration) {
    assert duration.compareTo(Duration.ZERO) >= 0 : "duration ? 0 ??? ?  .";
    reference = new TimeRange(start, end, true);

    val beforeEnd = start.minus(duration);
    val beforeStart = beforeEnd.minus(reference.getDuration());
    val insideStart = start.plus(duration);
    val insideEnd = end.minus(duration);
    val afterStart = end.plus(duration);
    val afterEnd = afterStart.plus(reference.getDuration());

    after = new TimeRange(beforeStart, beforeEnd, true);
    startTouching = new TimeRange(beforeStart, start, true);
    startInside = new TimeRange(beforeStart, insideStart, true);
    insideStartTouching = new TimeRange(start, afterStart, true);
    enclosingStartTouching = new TimeRange(start, insideEnd, true);
    enclosing = new TimeRange(insideStart, insideEnd, true);
    enclosingEndTouching = new TimeRange(insideStart, end, true);
    exactMatch = new TimeRange(start, end, true);
    inside = new TimeRange(beforeStart, afterEnd, true);
    insideEndTouching = new TimeRange(beforeStart, end, true);
    endInside = new TimeRange(insideEnd, afterEnd, true);
    endTouching = new TimeRange(end, afterEnd, true);
    before = new TimeRange(afterStart, afterEnd, true);

    allPeriods.addAll(Arrays.asList(reference, after, startTouching, startInside, insideStartTouching,
            enclosingStartTouching, enclosing, enclosingEndTouching, exactMatch, inside, insideEndTouching,
            endInside, endTouching, before));
}

From source file:es.usc.citius.servando.calendula.pinlock.UnlockStateManager.java

License:Open Source License

/**
 * Checks if unlock is set and not expired
 *
 * @return <code>true</code> if unlocked, false otherwise.
 *///from  ww w. j  a v a 2s .c o  m
public boolean isUnlocked() {
    LogUtil.v(TAG, "isUnlocked() called");
    if (unlockTimestamp != null) {
        Duration diff = new Duration(unlockTimestamp, DateTime.now());
        // need to be a string to use a ListPreference
        final String maxDurationStr = PreferenceUtils.getString(PreferenceKeys.UNLOCK_PIN_TIMEOUT,
                DEFAULT_UNLOCK_DURATION_SECONDS);
        Duration maxDuration = Duration.standardSeconds(Integer.parseInt(maxDurationStr));
        LogUtil.d(TAG, "Max unlock duration is " + maxDuration.toString());
        if (diff.compareTo(maxDuration) <= 0) {
            LogUtil.d(TAG, "isUnlocked() returned: " + true);
            return true;
        } else {
            LogUtil.d(TAG, "isUnlocked: unlock has expired, unsetting and returning null");
            unlockTimestamp = null;
            return false;
        }
    } else {
        LogUtil.d(TAG, "isUnlocked: timestamp is null");
    }
    return false;
}

From source file:fi.hsl.parkandride.core.service.FacilityHistoryService.java

License:EUPL

private static <T extends HasInterval> BinaryOperator<T> greatestOverlap(Interval significantWindow) {
    return (h1, h2) -> {
        final Duration h1overlap = h1.overlapWith(significantWindow);
        final Duration h2overlap = h2.overlapWith(significantWindow);
        return h1overlap.compareTo(h2overlap) >= 0 ? h1 : h2;
    };/*from ww w. j  a  va 2 s.  com*/
}