下面列出了java.time.LocalDate#compareTo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static sun.util.calendar.Era privateEraFrom(LocalDate isoDate) {
for (int i = KNOWN_ERAS.length - 1; i > 0; i--) {
JapaneseEra era = KNOWN_ERAS[i];
if (isoDate.compareTo(era.since) >= 0) {
return ERA_CONFIG[i];
}
}
return null;
}
/**
* Obtains an instance of {@code JapaneseEra} from a date.
*
* @param date the date, not null
* @return the Era singleton, never null
*/
static JapaneseEra from(LocalDate date) {
if (date.isBefore(MEIJI_6_ISODATE)) {
throw new DateTimeException("JapaneseDate before Meiji 6 are not supported");
}
for (int i = KNOWN_ERAS.length - 1; i > 0; i--) {
JapaneseEra era = KNOWN_ERAS[i];
if (date.compareTo(era.since) >= 0) {
return era;
}
}
return null;
}
/**
* Obtains an instance of {@code JapaneseEra} from a date.
*
* @param date the date, not null
* @return the Era singleton, never null
*/
static JapaneseEra from(LocalDate date) {
if (date.isBefore(MEIJI_6_ISODATE)) {
throw new DateTimeException("JapaneseDate before Meiji 6 are not supported");
}
for (int i = KNOWN_ERAS.length - 1; i > 0; i--) {
JapaneseEra era = KNOWN_ERAS[i];
if (date.compareTo(era.since) >= 0) {
return era;
}
}
return null;
}
public IUnit getUnit() {
LocalDate from = this.from.getValue();
LocalDate to = this.to.getValue();
if (from != null && to != null) {
if (from.compareTo(to) <= 0) {
return new BattleLogs.CustomUnit(from, to);
} else {
return new BattleLogs.CustomUnit(to, from);
}
}
return null;
}
static sun.util.calendar.Era privateEraFrom(LocalDate isoDate) {
for (int i = KNOWN_ERAS.length - 1; i > 0; i--) {
JapaneseEra era = KNOWN_ERAS[i];
if (isoDate.compareTo(era.since) >= 0) {
return ERA_CONFIG[i];
}
}
return null;
}
static sun.util.calendar.Era privateEraFrom(LocalDate isoDate) {
for (int i = KNOWN_ERAS.length - 1; i > 0; i--) {
JapaneseEra era = KNOWN_ERAS[i];
if (isoDate.compareTo(era.since) >= 0) {
return ERA_CONFIG[i];
}
}
return null;
}
/**
* Search for the sale price list for the current date in the partner.
*
* @param partner
* @return the sale price list for the partner null if no active price list has been found
*/
@Override
public PriceList getSalePriceList(Partner partner) {
PartnerPriceList partnerPriceList = partner.getSalePartnerPriceList();
if (partnerPriceList == null) {
return null;
}
Set<PriceList> priceListSet = partnerPriceList.getPriceListSet();
if (priceListSet == null) {
return null;
}
LocalDate today = Beans.get(AppBaseService.class).getTodayDate();
List<PriceList> candidatePriceListList = new ArrayList<>();
for (PriceList priceList : priceListSet) {
LocalDate beginDate =
priceList.getApplicationBeginDate() != null
? priceList.getApplicationBeginDate()
: LocalDate.MIN;
LocalDate endDate =
priceList.getApplicationEndDate() != null
? priceList.getApplicationEndDate()
: LocalDate.MAX;
if (beginDate.compareTo(today) <= 0 && today.compareTo(endDate) <= 0) {
candidatePriceListList.add(priceList);
}
}
// if we found multiple price list, then the user will have to select one
if (candidatePriceListList.size() == 1) {
return candidatePriceListList.get(0);
} else {
return null;
}
}
@Override
public boolean accepts(LocalDate value, TableFilterContext context) {
if (value == null) {
return false;
}
return value.compareTo(getMinValue()) < 0 || value.compareTo(getMaxValue()) > 0;
}
@Override
public boolean accepts(LocalDate value, TableFilterContext context) {
if (value == null) {
return false;
}
return value.compareTo(getMinValue()) >= 0 && value.compareTo(getMaxValue()) <= 0;
}
/**
* Obtains an instance of {@code JapaneseEra} from a date.
*
* @param date the date, not null
* @return the Era singleton, never null
*/
static JapaneseEra from(LocalDate date) {
if (date.isBefore(MEIJI_6_ISODATE)) {
throw new DateTimeException("JapaneseDate before Meiji 6 are not supported");
}
for (int i = KNOWN_ERAS.length - 1; i > 0; i--) {
JapaneseEra era = KNOWN_ERAS[i];
if (date.compareTo(era.since) >= 0) {
return era;
}
}
return null;
}
/**
* Obtains an instance of {@code JapaneseEra} from a date.
*
* @param date the date, not null
* @return the Era singleton, never null
*/
static JapaneseEra from(LocalDate date) {
if (date.isBefore(MEIJI_6_ISODATE)) {
throw new DateTimeException("JapaneseDate before Meiji 6 are not supported");
}
for (int i = KNOWN_ERAS.length - 1; i > 0; i--) {
JapaneseEra era = KNOWN_ERAS[i];
if (date.compareTo(era.since) >= 0) {
return era;
}
}
return null;
}
static sun.util.calendar.Era privateEraFrom(LocalDate isoDate) {
for (int i = KNOWN_ERAS.length - 1; i > 0; i--) {
JapaneseEra era = KNOWN_ERAS[i];
if (isoDate.compareTo(era.since) >= 0) {
return ERA_CONFIG[i];
}
}
return null;
}
static sun.util.calendar.Era privateEraFrom(LocalDate isoDate) {
for (int i = KNOWN_ERAS.length - 1; i > 0; i--) {
JapaneseEra era = KNOWN_ERAS[i];
if (isoDate.compareTo(era.since) >= 0) {
return ERA_CONFIG[i];
}
}
return null;
}
static sun.util.calendar.Era privateEraFrom(LocalDate isoDate) {
for (int i = KNOWN_ERAS.length - 1; i > 0; i--) {
JapaneseEra era = KNOWN_ERAS[i];
if (isoDate.compareTo(era.since) >= 0) {
return ERA_CONFIG[i];
}
}
return null;
}
@Override
public int compareTo(@NotNull BiopsyTreatmentResponseData other) {
LocalDate date1 = date();
LocalDate date2 = other.date();
if (date1 == null && date2 == null) {
return 0;
} else if (date1 == null) {
return 1;
} else if (date2 == null) {
return -1;
} else {
return date1.compareTo(date2);
}
}
@Override
public int compare(LocalDate first, LocalDate second) {
int cmp = first.compareTo(second);
return ascendingComparison ? cmp : -cmp;
}
@Override
public List<KilometricAllowParam> getListOfKilometricAllowParamVehicleFilter(
ExpenseLine expenseLine, Expense expense) throws AxelorException {
List<KilometricAllowParam> kilometricAllowParamList = new ArrayList<>();
if (expense == null) {
return kilometricAllowParamList;
}
if (expense.getId() != null) {
expense = expenseRepository.find(expense.getId());
}
if (expense.getUser() != null && expense.getUser().getEmployee() == null) {
return kilometricAllowParamList;
}
List<EmployeeVehicle> vehicleList = expense.getUser().getEmployee().getEmployeeVehicleList();
LocalDate expenseDate = expenseLine.getExpenseDate();
if (expenseDate == null) {
throw new AxelorException(
TraceBackRepository.CATEGORY_MISSING_FIELD,
I18n.get(IExceptionMessage.KILOMETRIC_ALLOWANCE_NO_DATE_SELECTED));
}
for (EmployeeVehicle vehicle : vehicleList) {
if (vehicle.getKilometricAllowParam() == null) {
break;
}
LocalDate startDate = vehicle.getStartDate();
LocalDate endDate = vehicle.getEndDate();
if ((startDate == null && (endDate == null || expenseDate.compareTo(endDate) <= 0))
|| (endDate == null
&& (expenseDate.compareTo(startDate) >= 0
|| (expenseDate.compareTo(startDate) >= 0
&& expenseDate.compareTo(endDate) <= 0)))) {
kilometricAllowParamList.add(vehicle.getKilometricAllowParam());
}
}
return kilometricAllowParamList;
}
@Override
public double getDaycountFraction(final LocalDate startDate, final LocalDate endDate) {
if(startDate.isAfter(endDate)) {
return -getDaycountFraction(endDate,startDate);
}
/*
* Determine the denominator of act/act.
*/
double denominator;
final LocalDate startDatePlusOneYear = startDate.plusYears(1);
if(endDate.isAfter(startDatePlusOneYear)) {
/*
* The following method applies, if the interval spans more than one year:
* fraction = actual number of days / average number of days per year.
*/
final LocalDate startDateYearStart = startDate.withDayOfYear(1);
final LocalDate endDateYearEnd = endDate.withDayOfYear(endDate.lengthOfYear()).plusDays(1);
final double spannedYears = endDate.getYear() - startDate.getYear() + 1;
denominator = getDaycount(startDateYearStart, endDateYearEnd) / spannedYears;
}
else {
final boolean isStartLeapYear = startDate.isLeapYear();
final boolean isEndLeapYear = endDate.isLeapYear();
/*
* If the start and end span less or equal one year:
* If start and end fall in a leap year, use ACT/366.
*/
if(isStartLeapYear && isEndLeapYear)
{
denominator = 366.0;
}
else
/*
* If the start and end span less or equal one year:
* If either falls in a leap year and Feb 29th of that leap year lies in between start and end (or is equal to start or end), use ACT/366.
*/
if(isStartLeapYear || isEndLeapYear)
{
// Get February 29th of the respective leap year
final LocalDate leapYearsFeb29th = isStartLeapYear ?
LocalDate.of(startDate.getYear(), Month.FEBRUARY, 29) :
LocalDate.of(endDate.getYear(), Month.FEBRUARY, 29);
// Check position of February 29th
if(startDate.compareTo(leapYearsFeb29th) <= 0 && endDate.compareTo(leapYearsFeb29th) >= 0) {
denominator = 366.0;
}
else {
denominator = 365.0;
}
}
else {
/*
* If the start and end span less or equal one year:
* If none of the above applies, use denominator = ACT/365.
*/
denominator = 365.0;
}
}
final double daycountFraction = getDaycount(startDate, endDate) / denominator;
return daycountFraction;
}
protected int compare(LocalDate first, LocalDate second) {
return first.compareTo(second);
}
/**
* Returns a stable TurboMilestone comparator by due date.
* <p>
* Open milestones without due date are considered to have a due date very far in the future. On the contrary,
* closed milestones without due date are considered to have a due date very far in the past.
* <p>
* Milestones with due dates are considered in between, considered according to their due dates.
*/
public static Comparator<TurboMilestone> getDueDateComparator() {
return (a, b) -> {
LocalDate aDueDate = a.getDueDate().orElse(a.isOpen() ? LocalDate.MAX : LocalDate.MIN);
LocalDate bDueDate = b.getDueDate().orElse(b.isOpen() ? LocalDate.MAX : LocalDate.MIN);
return aDueDate.compareTo(bDueDate);
};
}