blob: 57097dc0ad147445d808a5473d1758e7b8456560 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/****************************************************************************
* Copyright (c) 2009 Markus Alexander Kuppe.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* Markus Alexander Kuppe (ecf-dev_eclipse.org <at> lemmster <dot> de) - initial API and implementation
*
* SPDX-License-Identifier: EPL-2.0
*****************************************************************************/
package org.eclipse.ecf.tests.provider.dnssd;
import org.eclipse.ecf.discovery.IServiceInfo;
import org.eclipse.ecf.discovery.identity.IServiceID;
import org.eclipse.ecf.tests.discovery.ServiceInfoComparator;
public class DnsSdDiscoveryComparator extends ServiceInfoComparator {
/* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(Object arg0, Object arg1) {
if (arg0 instanceof IServiceInfo && arg1 instanceof IServiceInfo) {
final IServiceInfo first = (IServiceInfo) arg0;
final IServiceInfo second = (IServiceInfo) arg1;
final IServiceID firstServiceId = first.getServiceID();
final IServiceID secondServiceId = second.getServiceID();
boolean idsSame = firstServiceId.equals(secondServiceId);
boolean prioSame = first.getPriority() == second.getPriority();
boolean weightSame = first.getWeight() == second.getWeight();
boolean servicePropertiesSame = compareServiceProperties(first.getServiceProperties(), second.getServiceProperties());
boolean ttlSame = first.getTTL() <= second.getTTL(); // <= due to the fact that we might get a cache hit during testing which ttl has already decreased
final boolean result = (idsSame && prioSame && weightSame && servicePropertiesSame && ttlSame);
if (result == true) {
return 0;
}
}
return -1;
}
}
|