У меня есть проверка причины возникновения этого исключения. Не могли бы вы направить меня? Что я делаю неправильно в блоке кода ниже?Метод сравнения нарушает его общее исключение контракта
Collections.sort(discountGroupDetailList, new Comparator<DiscountGroupDetail>() {
long bdsIdOne;
long bdsIdTwo;
public int compare(DiscountGroupDetail discountGroupDetailOne, DiscountGroupDetail discountGroupDetailTwo) {
boolean discOne;
boolean discTwo;
SimpleDateFormat DATE_FORMATER = new SimpleDateFormat("yyyy/MM/dd");
int compVal = 0;
discOne = discountGroupDetailOne != null && discountGroupDetailOne.getServiceId() != null
&& discountGroupDetailOne.getServiceId().getCodeAndVersion() != null
&& discountGroupDetailOne.getServiceId().getCodeAndVersion().getCodeDetail() != null
&& discountGroupDetailOne.getServiceId().getCodeAndVersion().getCodeDetail().getCode() != null;
discTwo = discountGroupDetailTwo != null && discountGroupDetailTwo.getServiceId() != null
&& discountGroupDetailTwo.getServiceId().getCodeAndVersion() != null
&& discountGroupDetailTwo.getServiceId().getCodeAndVersion().getCodeDetail() != null
&& discountGroupDetailTwo.getServiceId().getCodeAndVersion().getCodeDetail().getCode() != null;
if (discOne == true && discTwo == true) {
bdsIdOne = MessageBuilderHelper.getBaseDiscountServiceById(discountGroupDetailOne.getServiceId())
.getBdsIdNbr();
bdsIdTwo = MessageBuilderHelper.getBaseDiscountServiceById(discountGroupDetailTwo.getServiceId())
.getBdsIdNbr();
compVal = (int) (bdsIdOne - bdsIdTwo);
}
DateRange dateRangeOne = discountGroupDetailOne != null ? discountGroupDetailOne.getDateSegment() : null;
DateRange dateRangeTwo = discountGroupDetailTwo != null ? discountGroupDetailTwo.getDateSegment() : null;
if (compVal == 0 && dateRangeOne != null && dateRangeTwo != null) {
Date date = new Date();
compVal = DATE_FORMATER.format(date.parse(dateRangeOne.getStartDate())).compareTo(
DATE_FORMATER.format(date.parse(dateRangeTwo.getStartDate())));
}
DiscountCode discountTypeOne = (discountGroupDetailOne != null && discountGroupDetailOne
.getVolumeDiscountGroupDetail() != null) ? DiscountCode.getDiscount(discountGroupDetailOne
.getVolumeDiscountGroupDetail().getType()) : null;
DiscountCode discountTypeTwo = (discountGroupDetailTwo != null && discountGroupDetailTwo
.getVolumeDiscountGroupDetail() != null) ? DiscountCode.getDiscount(discountGroupDetailTwo
.getVolumeDiscountGroupDetail().getType()) : null;
boolean isFXG = ("FXG".equals(discountGroupDetailOne.getServiceGeography()) || (discountGroupDetailOne
.getServiceId() != null && "FXG".equals(discountGroupDetailOne.getServiceId().getOperatingCompany())))
&& ("FXG".equals(discountGroupDetailTwo.getServiceGeography()) || (discountGroupDetailTwo
.getServiceId() != null && "FXG".equals(discountGroupDetailTwo.getServiceId()
.getOperatingCompany())));
if (compVal == 0 && discountTypeOne != null && discountTypeTwo != null && isFXG) {
compVal = ((int) (Integer.parseInt(discountTypeOne.getDiscountID()) - Integer.parseInt(discountTypeTwo
.getDiscountID())));
}
return compVal;
}
});
}
, пожалуйста, сообщите нам точное сообщение об ошибке, включая трассировку стека, если это возможно, и в какой строке это исключение. –
Теперь я вижу, что если A имеет нулевой тип скидки, а B имеет непустой тип скидки, а C имеет другой тип нечетного дисконта, а все остальное равно, то A == B и A = = C и B! = C в соответствии с вашим компаратором. – immibis
@ Daniel.Schroeder. Да –