01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: ******************************************************************************/package org.eclipse.ui.internal.provisional.views.markers;
11:
12: import java.util.Comparator;
13:
14: import org.eclipse.ui.internal.provisional.views.markers.api.MarkerField;
15: import org.eclipse.ui.internal.provisional.views.markers.api.MarkerItem;
16:
17: /**
18: * The MarkerComparator is the class that handles the comparison of markers for
19: * a specific content provider.
20: *
21: * @since 3.4
22: *
23: */
24: class MarkerComparator implements Comparator {
25:
26: private MarkerField category;
27: private MarkerField[] fields;
28:
29: /**
30: * Create a new instance of the receiver categorised by categoryField
31: *
32: * @param categoryField
33: * May be <code>null/<code>
34: * @param mainFields in order of compare significance
35: */
36: public MarkerComparator(MarkerField categoryField,
37: MarkerField[] mainFields) {
38: category = categoryField;
39: fields = mainFields;
40: }
41:
42: /**
43: * Compare the two objects to see if they have the same category value
44: *
45: * @param object1
46: * @param object2
47: * @return int
48: * @see Comparable#compareTo(Object)
49: */
50: public int compareCategory(Object object1, Object object2) {
51: if (category == null)
52: return 0;
53: return category.compare((MarkerItem) object1,
54: (MarkerItem) object2);
55: }
56:
57: /*
58: * (non-Javadoc)
59: *
60: * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
61: */
62: public int compare(Object arg0, Object arg1) {
63: MarkerItem item0 = (MarkerItem) arg0;
64: MarkerItem item1 = (MarkerItem) arg1;
65: for (int i = 0; i < fields.length; i++) {
66: int value = fields[i].compare(item0, item1);
67: if (value == 0)
68: continue;
69: return value;
70: }
71: return 0;
72: }
73:
74: }
|