List of usage examples for org.apache.commons.collections ComparatorUtils max
public static Object max(Object o1, Object o2, Comparator comparator)
From source file:acromusashi.stream.ml.anomaly.lof.LofCalculator.java
/** * basePoint?targetPoint?????(Reachability distance)? * /*from w w w.j a va 2 s . c o m*/ * @param basePoint * @param targetPoint * @return ??? */ protected static double calculateReachDistance(LofPoint basePoint, LofPoint targetPoint) { double distance = MathUtils.distance(basePoint.getDataPoint(), targetPoint.getDataPoint()); double reachDistance = (double) ComparatorUtils.max(distance, targetPoint.getkDistance(), ComparatorUtils.NATURAL_COMPARATOR); return reachDistance; }
From source file:org.openvpms.web.workspace.history.CustomerPatientHistoryQuery.java
/** * Returns a list of {@link CustomerPatient} instances representing the selected customers and their corresponding * patients, ordered on most recent selection first. * * @param customers the customer selection history * @param patients the patient selection history * @return a list of customer/patient pairs *//*from ww w .ja v a2 s . com*/ private List<CustomerPatient> getHistory(SelectionHistory customers, SelectionHistory patients) { List<CustomerPatient> result = new ArrayList<CustomerPatient>(); Set<SelectionHistory.Selection> allCustomers = new HashSet<SelectionHistory.Selection>( customers.getSelections()); Set<SelectionHistory.Selection> allPatients = new HashSet<SelectionHistory.Selection>( patients.getSelections()); for (SelectionHistory.Selection selection : allPatients .toArray(new SelectionHistory.Selection[allPatients.size()])) { Party patient = (Party) selection.getObject(); if (patient != null) { IMObjectReference customerRef = rules.getOwnerReference(patient); Party customer = (Party) IMObjectHelper.getObject(customerRef, context); Date patientSelect = selection.getTime(); Date customerSelect = (customer != null) ? customers.getSelected(customer) : null; Date selected; if (customerSelect != null) { selected = (Date) ComparatorUtils.max(customerSelect, patientSelect, null); } else { selected = patientSelect; } CustomerPatient pair = new CustomerPatient(customer, patient, selected); result.add(pair); if (customer != null) { allCustomers.remove(new SelectionHistory.Selection(customerRef, context)); } } allPatients.remove(selection); } for (SelectionHistory.Selection selection : allCustomers) { Party customer = (Party) selection.getObject(); if (customer != null) { result.add(new CustomerPatient(customer, null, selection.getTime())); } } for (SelectionHistory.Selection selection : allPatients) { Party patient = (Party) selection.getObject(); if (patient != null) { result.add(new CustomerPatient(null, patient, selection.getTime())); } } Collections.sort(result, new Comparator<CustomerPatient>() { public int compare(CustomerPatient o1, CustomerPatient o2) { return -o1.getSelected().compareTo(o2.getSelected()); } }); return result; }
From source file:org.openvpms.web.workspace.history.CustomerPatientHistoryQueryTestCase.java
/** * Verifies that a <tt>CustomerPatient</tt> instance contains both a customer and patient. * * @param pair the customer/patient pair * @param customer the expected customer * @param patient the expected patient//ww w. j a v a 2 s.c o m */ private void checkCustomerPatient(CustomerPatient pair, SelectionHistory.Selection customer, SelectionHistory.Selection patient) { assertEquals(customer.getObject(), pair.getCustomer()); assertEquals(patient.getObject(), pair.getPatient()); Date expected = (Date) ComparatorUtils.max(customer.getTime(), patient.getTime(), null); assertEquals(expected, pair.getSelected()); }