Java Code Examples for org.apache.commons.lang3.ObjectUtils#compare()
The following examples show how to use
org.apache.commons.lang3.ObjectUtils#compare() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnyTypeRestClient.java From syncope with Apache License 2.0 | 6 votes |
@Override public int compare(final String o1, final String o2) { if (SyncopeConstants.REALM_ANYTYPE.equals(o1)) { return -1; } if (SyncopeConstants.REALM_ANYTYPE.equals(o2)) { return 1; } if (AnyTypeKind.USER.name().equals(o1)) { return -1; } if (AnyTypeKind.USER.name().equals(o2)) { return 1; } if (AnyTypeKind.GROUP.name().equals(o1)) { return -1; } if (AnyTypeKind.GROUP.name().equals(2)) { return 1; } return ObjectUtils.compare(o1, o2); }
Example 2
Source File: TimeSeriesRow.java From incubator-pinot with Apache License 2.0 | 6 votes |
private static <E extends Comparable<E>> int compareListOfComparable(List<E> a, List<E> b) { if (a == null && b == null) return 0; if (a == null) return -1; if (b == null) return 1; int sizeA = a.size(); int sizeB = b.size(); int sizeDiff = ObjectUtils.compare(sizeA, sizeB); if (sizeDiff != 0) { return sizeDiff; } for (int i = 0; i < sizeA; i++) { E comparableA = a.get(i); E comparableB = b.get(i); int comparableDiff = ObjectUtils.compare(comparableA, comparableB); if (comparableDiff != 0) { return comparableDiff; } } return 0; }
Example 3
Source File: HomeNFamilyStatusFragment.java From arcusandroid with Apache License 2.0 | 6 votes |
@Override public int compare(PicListItemModel firstModel, PicListItemModel secondModel) { String firstDisplayName; String secondDisplayName; if (!TextUtils.isEmpty(firstModel.getPersonId())) { firstDisplayName = firstModel.getPersonName(); } else { firstDisplayName = firstModel.getDeviceName(); } if (!TextUtils.isEmpty(secondModel.getPersonId())) { secondDisplayName = secondModel.getPersonName(); } else { secondDisplayName = secondModel.getDeviceName(); } return ObjectUtils.compare(firstDisplayName.toUpperCase(), secondDisplayName.toUpperCase()); }
Example 4
Source File: InvoiceForLease.java From estatio with Apache License 2.0 | 6 votes |
public String validate$$( final Charge charge, final BigDecimal quantity, final BigDecimal netAmount, final LocalDate startDate, final LocalDate endDate) { if (startDate != null && endDate == null) { return "Also enter an end date when using a start date"; } if (ObjectUtils.compare(startDate, endDate) > 0) { return "Start date must be before end date"; } if (startDate == null && endDate == null) { messageService.warnUser("Both start date and end date are empty. Is this done intentionally?"); } if (startDate == null && endDate != null) { messageService.warnUser("Start date is empty. Is this done intentionally?"); } return null; }
Example 5
Source File: AnyTypeRestClient.java From syncope with Apache License 2.0 | 6 votes |
@Override public int compare(final AnyTypeTO o1, final AnyTypeTO o2) { if (o1.getKind() == AnyTypeKind.USER) { return -1; } if (o2.getKind() == AnyTypeKind.USER) { return 1; } if (o1.getKind() == AnyTypeKind.GROUP) { return -1; } if (o2.getKind() == AnyTypeKind.GROUP) { return 1; } return ObjectUtils.compare(o1.getKey(), o2.getKey()); }
Example 6
Source File: LeaseTypeImport.java From estatio with Apache License 2.0 | 5 votes |
@Programmatic @Override public List<Object> importData(final Object previousRow) { final ApplicationTenancy appTenancy = applicationTenancyRepository.findByPath(atPath); final LeaseType leaseType = leaseTypeRepository.findOrCreate(reference, name, appTenancy); if (ObjectUtils.compare(name, leaseType.getName()) != 0) { leaseType.setName(name); } return Lists.newArrayList(leaseType); }
Example 7
Source File: BusinessObjectDataKeyComparator.java From herd with Apache License 2.0 | 5 votes |
@Override public int compare(final BusinessObjectDataKey data1, final BusinessObjectDataKey data2) { if (data1 == null || data2 == null) { return data1 == null && data2 == null ? 0 : (data1 == null ? -1 : 1); } int result = ObjectUtils.compare(data1.getBusinessObjectDefinitionName(), data2.getBusinessObjectDefinitionName()); if (result != 0) { return result; } result = ObjectUtils.compare(data1.getBusinessObjectFormatUsage(), data2.getBusinessObjectFormatUsage()); if (result != 0) { return result; } result = ObjectUtils.compare(data1.getBusinessObjectFormatFileType(), data2.getBusinessObjectFormatFileType()); if (result != 0) { return result; } result = ObjectUtils.compare(data1.getBusinessObjectFormatVersion(), data2.getBusinessObjectFormatVersion()); if (result != 0) { return result; } result = ObjectUtils.compare(data1.getPartitionValue(), data2.getPartitionValue()); if (result != 0) { return result; } return ObjectUtils.compare(data1.getBusinessObjectDataVersion(), data2.getBusinessObjectDataVersion()); }
Example 8
Source File: Asset.java From bonita-ui-designer with GNU General Public License v2.0 | 5 votes |
public static Comparator<Asset> getComparatorByComponentId() { return new Comparator<Asset>() { @Override public int compare(Asset asset1, Asset asset2) { return ObjectUtils.compare(asset1.getComponentId(), asset2.getComponentId(), true); } }; }
Example 9
Source File: RawAnomalyResultBean.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Override public int compareTo(RawAnomalyResultBean o) { // compare by dimension, -startTime, functionId, id int diff = ObjectUtils.compare(getDimensions(), o.getDimensions()); if (diff != 0) { return diff; } diff = -ObjectUtils.compare(startTime, o.getStartTime()); // inverted to sort by // decreasing time if (diff != 0) { return diff; } return ObjectUtils.compare(getId(), o.getId()); }
Example 10
Source File: AccountView.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@Override public int compare(Viewer viewer, Object e1, Object e2){ if ((e1 instanceof AccountTransaction) && (e2 instanceof AccountTransaction)) { AccountTransaction accountTransaction1 = (AccountTransaction) e1; AccountTransaction accountTransaction2 = (AccountTransaction) e2; int retVal = 0; switch (sortColumn) { case DATE: retVal = ObjectUtils.compare(new TimeTool(accountTransaction1.getDate()), new TimeTool(accountTransaction2.getDate())); break; case AMOUNT: retVal = ObjectUtils.compare(accountTransaction1.getAmount(), accountTransaction2.getAmount()); break; case BILL: Rechnung rechnung1 = accountTransaction1.getRechnung(); Rechnung rechnung2 = accountTransaction2.getRechnung(); if (rechnung1 == null) retVal = -1; else if (rechnung2 == null) retVal = 1; else retVal = ObjectUtils.compare(NumberUtils.toInt(rechnung1.getNr()), NumberUtils.toInt(rechnung2.getNr())); break; case REMARKS: retVal = ObjectUtils.compare(accountTransaction1.getRemark(), accountTransaction2.getRemark()); break; case ACCOUNT: retVal = ObjectUtils.compare(accountTransaction1.getAccount().getName(), accountTransaction2.getAccount().getName()); break; } return sortReverse ? retVal * -1 : retVal; } return 0; }
Example 11
Source File: CellReference.java From yarg with Apache License 2.0 | 5 votes |
@Override public int compareTo(Object o) { if (o instanceof CellReference) { int rows = ObjectUtils.compare(row, ((CellReference) o).row); int columns = ObjectUtils.compare(column, ((CellReference) o).column); return rows != 0 ? rows : columns; } else { throw new IllegalArgumentException("Could not compare with " + o); } }
Example 12
Source File: FallComparator.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@Override public int compare(Object o1, Object o2) { int comp = 0; if (o1 instanceof ICoverage && o2 instanceof ICoverage) { ICoverage f1 = (ICoverage) o1; ICoverage f2 = (ICoverage) o2; // compare gesetz boolean isFall1Closed = !f1.isOpen(); boolean isFall2Closed = !f2.isOpen(); comp = ObjectUtils.compare(isFall1Closed, isFall2Closed); if (comp == 0) { comp = ObjectUtils.compare(f1.getBillingSystem().getName(), f2.getBillingSystem().getName()); if (comp == 0) { LocalDate f1DateFrom = f1.getDateFrom(); LocalDate f2DateFrom = f2.getDateFrom(); if (f1DateFrom != null && f2DateFrom != null) { // compare beginn date comp = f1.getDateFrom().compareTo(f2.getDateFrom()); if (comp == 0) { comp = ObjectUtils.compare(f1.getDescription(), f2.getDescription()); if (comp == 0) { comp = ObjectUtils.compare(f1.getId(), f2.getId()); } } } else { return f1.getLastupdate().compareTo(f2.getLastupdate()); } } } } return comp; }
Example 13
Source File: Service.java From appstatus with Apache License 2.0 | 5 votes |
public int compareTo(IService otherService) { int groupCompare = ObjectUtils.compare(group, otherService.getGroup()); if (groupCompare != 0) { return groupCompare; } return ObjectUtils.compare(name, otherService.getName()); }
Example 14
Source File: Api.java From estatio with Apache License 2.0 | 5 votes |
@ActionSemantics(Of.IDEMPOTENT) public void putLeaseType( @Named("reference") final String reference, @Named("name") final String name) { final LeaseType leaseType = leaseTypes.findOrCreate(reference, name); if (ObjectUtils.compare(name, leaseType.getName()) != 0) { leaseType.setName(name); } }
Example 15
Source File: Document.java From maven-framework-project with MIT License | 4 votes |
@Override public int compareTo(Document o) { return ObjectUtils.compare(this.createdDate, o.createdDate); }
Example 16
Source File: DictionaryEditorModel.java From sailfish-core with Apache License 2.0 | 4 votes |
@Override public int compare(DictFileContainer o1, DictFileContainer o2) { return ObjectUtils.compare(o1.getURI(), o2.getURI()); }
Example 17
Source File: GuaranteeRepository.java From estatio with Apache License 2.0 | 4 votes |
@Programmatic public Guarantee newGuarantee( final Lease lease, final @Parameter(regexPattern = ReferenceType.Meta.REGEX, regexPatternReplacement = ReferenceType.Meta.REGEX_DESCRIPTION) String reference, final String name, final GuaranteeType guaranteeType, final LocalDate startDate, final LocalDate endDate, final String description, final BigDecimal contractualAmount, final BigDecimal startAmount ) { AgreementRoleType artGuarantee = agreementRoleTypeRepository.find(GuaranteeAgreementRoleTypeEnum.GUARANTEE); Party leasePrimaryParty = lease.primaryPartyAsOfElseCurrent(startDate); AgreementRoleType artGuarantor = agreementRoleTypeRepository.find(GuaranteeAgreementRoleTypeEnum.GUARANTOR); Party leaseSecondaryParty = lease.secondaryPartyAsOfElseCurrent(startDate); Guarantee guarantee = newTransientInstance(Guarantee.class); final AgreementType at = agreementTypeRepository.find(GuaranteeAgreementTypeEnum.GUARANTEE); guarantee.setType(at); guarantee.setReference(reference); guarantee.setDescription(description); guarantee.setName(name); guarantee.setStartDate(startDate); guarantee.setEndDate(endDate); guarantee.setGuaranteeType(guaranteeType); guarantee.setLease(lease); guarantee.setContractualAmount(contractualAmount); guarantee.newRole( artGuarantee, leasePrimaryParty, null, null); guarantee.newRole( artGuarantor, leaseSecondaryParty, null, null); FinancialAccountType financialAccountType = guaranteeType.getFinancialAccountType(); if (financialAccountType != null) { FinancialAccount financialAccount = financialAccountRepository.newFinancialAccount( financialAccountType, reference, name, leaseSecondaryParty); guarantee.setFinancialAccount(financialAccount); if (ObjectUtils.compare(startAmount, BigDecimal.ZERO) > 0) { financialAccountTransactionRepository.newTransaction(guarantee.getFinancialAccount(), startDate, null, startAmount); } } persistIfNotAlready(guarantee); return guarantee; }
Example 18
Source File: HistoricTask.java From maven-framework-project with MIT License | 4 votes |
@Override public int compareTo(HistoricTask o) { return ObjectUtils.compare(this.completedDate, o.completedDate); }
Example 19
Source File: ConnConfProperty.java From syncope with Apache License 2.0 | 4 votes |
@Override public int compareTo(final ConnConfProperty connConfProperty) { return ObjectUtils.compare(this.getSchema(), connConfProperty.getSchema()); }
Example 20
Source File: PropertyComparator.java From feilong-core with Apache License 2.0 | 3 votes |
/** * 处理值相等的情况. * * <p> * 如果用于 {@link TreeSet}/{@link TreeMap},那么建议 bean 对象需要实现 {@link Comparable} 接口<br> * * 避免过滤掉同sort字段但是对象不相同的情况 * </p> * * <h3>说明:</h3> * <blockquote> * <ol> * <li>如果对象实现了 {@link Comparable} 接口, 那么直接比较</li> * <li>如果对象没有实现 {@link Comparable} 接口, 那么比较两个对象的hashCode</li> * </ol> * </blockquote> * * @param t1 * the t 1 * @param t2 * the t 2 * @return 如果对象实现了 {@link Comparable} 接口, 那么直接强转比较<br> * 如果对象没有实现 {@link Comparable} 接口, 那么比较两个对象的hashCode * @see <a href="https://github.com/venusdrogon/feilong-core/issues/631">PropertyComparator hash判断两个对象是否相等是否太草率?</a> * @see <a href="https://github.com/venusdrogon/feilong-core/issues/643">SortUtil.sortMapByValueDesc(Map<String, Integer>) 会报异常</a> * @since 1.10.3 */ @SuppressWarnings({ "rawtypes", "unchecked" }) private int compareWithSameValue(T t1,T t2){ //如果对象实现了 Comparable 接口, 那么直接强转比较 return isInstance(t1, Comparable.class) ? ObjectUtils.compare((Comparable) t1, (Comparable) t2) : ObjectUtils.compare(t1.hashCode(), t2.hashCode()); }