01: /* *****************************************************************************
02: * Specificity.java
03: * ****************************************************************************/
04:
05: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
06: * Copyright 2001-2006 Laszlo Systems, Inc. All Rights Reserved. *
07: * Use is subject to license terms. *
08: * J_LZ_COPYRIGHT_END *********************************************************/
09:
10: package org.openlaszlo.css;
11:
12: public class Specificity {
13: final static int SPECIFICITY_ID = 0;
14: final static int SPECIFICITY_ATTRIBUTE = 1;
15: final static int SPECIFICITY_ELEMENT = 2;
16:
17: int[] mSpecificity = { 0, 0, 0 };
18:
19: public void incID() {
20: ++mSpecificity[SPECIFICITY_ID];
21: }
22:
23: public void incAttribute() {
24: ++mSpecificity[SPECIFICITY_ATTRIBUTE];
25: }
26:
27: public void incElement() {
28: ++mSpecificity[SPECIFICITY_ELEMENT];
29: }
30:
31: public void reset() {
32: mSpecificity[SPECIFICITY_ID] = 0;
33: mSpecificity[SPECIFICITY_ATTRIBUTE] = 0;
34: mSpecificity[SPECIFICITY_ELEMENT] = 0;
35: }
36:
37: /**
38: * @return 0 if this is equal, -1 if this is less, +1 if this is
39: * greater.
40: */
41: int compare(Specificity specificity) {
42: int diff;
43:
44: diff = this .mSpecificity[SPECIFICITY_ID]
45: - specificity.mSpecificity[SPECIFICITY_ID];
46: if (diff != 0)
47: return diff < 0 ? -1 : +1;
48:
49: diff = this .mSpecificity[SPECIFICITY_ATTRIBUTE]
50: - specificity.mSpecificity[SPECIFICITY_ATTRIBUTE];
51: if (diff != 0)
52: return diff < 0 ? -1 : +1;
53:
54: diff = this .mSpecificity[SPECIFICITY_ELEMENT]
55: - specificity.mSpecificity[SPECIFICITY_ELEMENT];
56: if (diff != 0)
57: return diff < 0 ? -1 : +1;
58:
59: return 0;
60: }
61: }
|