Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7654383ec9f0361f85847d016cc25d884695f7a2 (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
44
45
46
47
48
49
50
51
52
53
54
/*******************************************************************************
 * Copyright (c) 2008 Versant Corp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Markus Kuppe (mkuppe <at> versant <dot> com) - initial API and implementation
 ******************************************************************************/
package org.eclipse.ecf.tests.provider.discovery;

import java.net.URI;

import org.eclipse.ecf.discovery.IServiceInfo;
import org.eclipse.ecf.discovery.identity.IServiceID;
import org.eclipse.ecf.tests.discovery.ServiceInfoComparator;

public class CompositeServiceInfoComporator extends ServiceInfoComparator {

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.tests.discovery.ServiceInfoComparator#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;
			boolean priority = first.getPriority() == second.getPriority();
			boolean weight = first.getWeight() == second.getWeight();

			final URI uri1 = first.getLocation();
			final URI uri2 = second.getLocation();
			boolean port = uri1.getPort() == uri2.getPort();
			boolean host = uri1.getHost().equals(uri2.getHost());

			final IServiceID firstID = first.getServiceID();
			final IServiceID secondID = second.getServiceID();
			boolean serviceType = firstID.getServiceTypeID().equals(secondID.getServiceTypeID());
			boolean serviceName = firstID.getServiceName().equals(secondID.getServiceName());

			String firstName = firstID.getName();
			String secondName = secondID.getName();
			boolean name = firstName.equals(secondName);
			
			boolean serviceProperties = compareServiceProperties(first.getServiceProperties(), second.getServiceProperties());
			
			final boolean result = name && serviceType && serviceName && host && port && priority && weight && serviceProperties;
			if (result == true) {
				return 0;
			}
		}
		return -1;
	}
}

Back to the top