Java Code Examples for java.time.Instant.compareTo()

The following are Jave code examples for showing how to use compareTo() of the java.time.Instant class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: presto-manager   File: LogsHandler.java   View Source Code Vote up 6 votes
private static Predicate<String> getFilter(Instant start, Instant end)
{
    boolean nullStart = start == null;
    boolean nullEnd = end == null;
    if (nullStart && nullEnd) {
        return s -> true;
    }
    else if (nullStart) {
        return s -> DATE_FORMAT.parse(s, Instant::from).compareTo(end) <= 0;
    }
    else if (nullEnd) {
        return s -> DATE_FORMAT.parse(s, Instant::from).compareTo(start) >= 0;
    }
    else {
        return s -> {
            Instant date = DATE_FORMAT.parse(s, Instant::from);
            return date.compareTo(start) >= 0 && date.compareTo(end) <= 0;
        };
    }
}
 
Example 2
Project: swblocks-decisiontree   File: DatedTreeNode.java   View Source Code Vote up 6 votes
private void updateDateRange(final TreeNode exactNode, final Range<Instant> range) {
    final Range<Instant> original = exactNode.getDateRange();
    Instant start = original.getStart();
    Instant finish = original.getFinish();

    if (start.isAfter(range.getStart())) {
        start = range.getStart();
    }
    if (finish.isBefore(range.getFinish())) {
        finish = range.getFinish();
    }

    if (start.compareTo(original.getStart()) != 0 ||
            finish.compareTo(original.getFinish()) != 0) {
        this.nextNodes.remove(new DatedNodeKey(exactNode.getValue(), original));

        exactNode.setDateRange(new Range<Instant>(start, finish));
        this.nextNodes.put(
                new DatedNodeKey(exactNode.getValue(), exactNode.getDateRange()), exactNode);
    }
}
 
Example 3
Project: kafka-connect-github-source   File: DateUtils.java   View Source Code Vote up 4 votes
public static Instant MaxInstant (Instant i1, Instant i2){
    return i1.compareTo(i2) > 0 ? i1 : i2;
}
 
Example 4
Project: ProjectAres   File: TimeUtils.java   View Source Code Vote up 4 votes
public static Instant min(Instant a, Instant b) {
    return a.compareTo(b) <= 0 ? a : b;
}
 
Example 5
Project: ProjectAres   File: TimeUtils.java   View Source Code Vote up 4 votes
public static Instant max(Instant a, Instant b) {
    return a.compareTo(b) >= 0 ? a : b;
}
 
Example 6
Project: jdk8u-jdk   File: TCKInstant.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=NullPointerException.class)
public void test_compareTo_ObjectNull() {
    Instant a = Instant.ofEpochSecond(0L, 0);
    a.compareTo(null);
}
 
Example 7
Project: openjdk-jdk10   File: TCKInstant.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=NullPointerException.class)
public void test_compareTo_ObjectNull() {
    Instant a = Instant.ofEpochSecond(0L, 0);
    a.compareTo(null);
}
 
Example 8
Project: swblocks-decisiontree   File: DatedTreeNode.java   View Source Code Vote up 4 votes
private boolean inRange(final Instant time, final Range<Instant> range) {
    final boolean isAfterStart = time.compareTo(range.getStart()) >= 0;
    final boolean isBeforeEnd = time.compareTo(range.getFinish()) <= 0;

    return isAfterStart && isBeforeEnd;
}