01: /*******************************************************************************
02: * Copyright (c) 2003, 2006 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.keys;
11:
12: import java.util.Comparator;
13:
14: import org.eclipse.ui.keys.ModifierKey;
15:
16: abstract class AbstractModifierKeyComparator implements Comparator {
17:
18: public int compare(Object left, Object right) {
19: ModifierKey modifierKeyLeft = (ModifierKey) left;
20: ModifierKey modifierKeyRight = (ModifierKey) right;
21: int modifierKeyLeftRank = rank(modifierKeyLeft);
22: int modifierKeyRightRank = rank(modifierKeyRight);
23:
24: if (modifierKeyLeftRank != modifierKeyRightRank) {
25: return modifierKeyLeftRank - modifierKeyRightRank;
26: } else {
27: return modifierKeyLeft.compareTo(modifierKeyRight);
28: }
29: }
30:
31: protected abstract int rank(ModifierKey modifierKey);
32: }
|