本文整理了Java中java.time.LocalTime.compareTo()
方法的一些代码示例,展示了LocalTime.compareTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalTime.compareTo()
方法的具体详情如下:
包路径:java.time.LocalTime
类名称:LocalTime
方法名:compareTo
[英]Compares this LocalTime to another time.
The comparison is based on the time-line position of the local times within a day. It is "consistent with equals", as defined by Comparable.
[中]将此LocalTime与其他时间进行比较。
比较是基于一天内当地时间的时间线位置。它是“与相等一致的”,如Comparable所定义。
代码示例来源:origin: neo4j/neo4j
@Override
int unsafeCompareTo( Value otherValue )
{
LocalTimeValue other = (LocalTimeValue) otherValue;
return value.compareTo( other.value );
}
代码示例来源:origin: jtablesaw/tablesaw
@Override
public int compare(LocalTime o1, LocalTime o2) {
return o1.compareTo(o2);
}
代码示例来源:origin: kiegroup/optaplanner
LocalTime startTime = LocalTime.parse(nextStringCell().getStringCellValue(), TIME_FORMATTER);
LocalTime endTime = LocalTime.parse(nextStringCell().getStringCellValue(), TIME_FORMATTER);
if (startTime.compareTo(endTime) >= 0) {
throw new IllegalStateException(currentPosition() + ": The startTime (" + startTime
+ ") must be less than the endTime (" + endTime + ").");
代码示例来源:origin: pholser/junit-quickcheck
/**
* <p>Tells this generator to produce values within a specified
* {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max()
* maximum}, inclusive, with uniform distribution, down to the
* nanosecond.</p>
*
* <p>If an endpoint of the range is not specified, the generator will use
* times with values of either {@link LocalTime#MIN} or
* {@link LocalTime#MAX} as appropriate.</p>
*
* <p>{@link InRange#format()} describes
* {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to
* interpret the range's endpoints}.</p>
*
* @param range annotation that gives the range's constraints
*/
public void configure(InRange range) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(range.format());
if (!defaultValueOf(InRange.class, "min").equals(range.min()))
min = LocalTime.parse(range.min(), formatter);
if (!defaultValueOf(InRange.class, "max").equals(range.max()))
max = LocalTime.parse(range.max(), formatter);
if (min.compareTo(max) > 0)
throw new IllegalArgumentException(String.format("bad range, %s > %s", range.min(), range.max()));
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Checks if this {@code LocalTime} is after the specified time.
* <p>
* The comparison is based on the time-line position of the time within a day.
*
* @param other the other time to compare to, not null
* @return true if this is after the specified time
* @throws NullPointerException if {@code other} is null
*/
public boolean isAfter(LocalTime other) {
return compareTo(other) > 0;
}
代码示例来源:origin: org.neo4j/neo4j-values
@Override
int unsafeCompareTo( Value otherValue )
{
LocalTimeValue other = (LocalTimeValue) otherValue;
return value.compareTo( other.value );
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Checks if this {@code LocalTime} is before the specified time.
* <p>
* The comparison is based on the time-line position of the time within a day.
*
* @param other the other time to compare to, not null
* @return true if this point is before the specified time
* @throws NullPointerException if {@code other} is null
*/
public boolean isBefore(LocalTime other) {
return compareTo(other) < 0;
}
代码示例来源:origin: stackoverflow.com
static boolean isInRange(LocalTime start, LocalTime end, LocalTime value) {
return start.compareTo(end) > 0
// Reversed: if it's earlier than the end point, or later than the start
? value.compareTo(end) <= 0 || start.compareTo(value) <= 0
: start.compareTo(value) <= 0 && value.compareTo(end) <= 0;
}
代码示例来源:origin: stackoverflow.com
import java.time.LocalTime;
public class Event implements Comparable<Event> {
LocalTime time;
@Override
public int compareTo(final Event o) {
return time.compareTo(o.time);
}
}
代码示例来源:origin: zavtech/morpheus-core
/**
* Constructor
* @param start the start for range, inclusive
* @param end the end for range, exclusive
* @param step the step increment
* @param excludes optional predicate to exclude elements in this range
*/
RangeOfLocalTimes(LocalTime start, LocalTime end, Duration step, Predicate<LocalTime> excludes) {
super(start, end);
this.step = step;
this.ascend = start.compareTo(end) <= 0;
this.excludes = excludes;
}
代码示例来源:origin: stackoverflow.com
public boolean isWithinInterval(LocalTime start, LocalTime end, LocalTime time) {
if (start.isAfter(end)) {
// Return true if the time is after (or at) start, *or* it's before end
return time.compareTo(start) >= 0 ||
time.compareTo(end) < 0;
} else {
return start.compareTo(time) <= 0 &&
time.compareTo(end) < 0;
}
}
代码示例来源:origin: stackoverflow.com
static boolean isInRange(LocalTime start, LocalTime end, LocalTime value) {
// Avoid equality problems - see description
if (value.equals(start) || value.equals(end)) {
return true;
}
if (start.compareTo(end) > 0) {
return !isInRange(end, start, value);
}
return start.compareTo(value) < 0 && value.compareTo(end) < 0;
}
代码示例来源:origin: stackoverflow.com
public boolean isWithinInterval(LocalTime start, LocalTime end, LocalTime time) {
if (start.isAfter(end)) {
return !isWithinInterval(end, start, time);
}
// This assumes you want an inclusive start and an exclusive end point.
return start.compareTo(time) <= 0 &&
time.compareTo(end) < 0;
}
代码示例来源:origin: com.github.almex/raildelays-api
@Override
public int compareTo(TimeDelay target) {
Objects.requireNonNull(target);
return this.getEffectiveTime().compareTo(target.getEffectiveTime());
}
代码示例来源:origin: com.github.seratch/java-time-backport
private int compareTo0(LocalDateTime other) {
int cmp = date.compareTo0(other.toLocalDate());
if (cmp == 0) {
cmp = time.compareTo(other.toLocalTime());
}
return cmp;
}
代码示例来源:origin: stackoverflow.com
LocalDateTime from = LocalDateTime.parse("2015-07-24T09:39:14.000Z", DateTimeFormatter.ISO_DATE_TIME);
LocalDateTime to = LocalDateTime.parse("2015-07-24T09:45:44.000Z", DateTimeFormatter.ISO_DATE_TIME);
System.out.println(from + " - " + to);
LocalTime fromTime = from.toLocalTime();
LocalTime toTime = to.toLocalTime();
System.out.println(fromTime + " - " + toTime);
System.out.println(fromTime + " before " + toTime + " = " + fromTime.isBefore(toTime));
System.out.println(fromTime + " after " + toTime + " = " + fromTime.isAfter(toTime));
System.out.println(fromTime + " equals " + toTime + " = " + fromTime.equals(toTime));
System.out.println(fromTime + " compareTo " + toTime + " = " + fromTime.compareTo(toTime));
代码示例来源:origin: nroduit/Weasis
@Override
public int compare(DicomImageElement m1, DicomImageElement m2) {
LocalTime val1 = TagD.getTagValue(m1, Tag.AcquisitionTime, LocalTime.class);
LocalTime val2 = TagD.getTagValue(m2, Tag.AcquisitionTime, LocalTime.class);
if (val1 == null || val2 == null) {
return 0;
}
return val1.compareTo(val2);
}
代码示例来源:origin: nroduit/Weasis
@Override
public int compare(DicomImageElement m1, DicomImageElement m2) {
LocalTime val1 = TagD.getTagValue(m1, Tag.ContentTime, LocalTime.class);
LocalTime val2 = TagD.getTagValue(m2, Tag.ContentTime, LocalTime.class);
if (val1 == null || val2 == null) {
return 0;
}
return val1.compareTo(val2);
}
代码示例来源:origin: stackoverflow.com
LocalTime start = new LocalTime(9, 0, 0);
LocalTime stop = new LocalTime(17, 0, 0);
LocalTime time = start; // Just use the reference
while (time.compareTo(stop) <= 0)
{
method(time, start, stop);
time = time.plusMinutes(1);
}
代码示例来源:origin: com.github.seratch/java-time-backport
public int compareTo(TZRule other) {
int cmp = year - other.year;
cmp = (cmp == 0 ? month.compareTo(other.month) : cmp);
if (cmp == 0) {
// convert to date to handle dow/domIndicator/timeEndOfDay
LocalDate thisDate = toLocalDate();
LocalDate otherDate = other.toLocalDate();
cmp = thisDate.compareTo(otherDate);
}
cmp = (cmp == 0 ? time.compareTo(other.time) : cmp);
return cmp;
}
内容来源于网络,如有侵权,请联系作者删除!