1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Stores the information for Style rules priority |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.tools.themeinstaller.cssparser; |
|
20 |
|
21 /** |
|
22 * The Class CSSSpecificity stores the information for Style rules priority |
|
23 */ |
|
24 public class CSSSpecificity |
|
25 { |
|
26 final public static int ID = 0; |
|
27 final public static int ATTRIBUTE = 1; |
|
28 final public static int ELEMENT = 2; |
|
29 |
|
30 /** Table for counting specificity occurrences. */ |
|
31 private int[] iSpecificity = { 0, 0, 0 }; |
|
32 |
|
33 /** |
|
34 * Increase id count. |
|
35 */ |
|
36 public void incID() |
|
37 { |
|
38 ++iSpecificity[ ID ]; |
|
39 } |
|
40 |
|
41 /** |
|
42 * Increase attribute count. |
|
43 */ |
|
44 public void incAttribute() |
|
45 { |
|
46 ++iSpecificity[ ATTRIBUTE ]; |
|
47 } |
|
48 |
|
49 /** |
|
50 * Increase element count. |
|
51 */ |
|
52 public void incElement() |
|
53 { |
|
54 ++iSpecificity[ ELEMENT ]; |
|
55 } |
|
56 |
|
57 /** |
|
58 * Gets the specificity table. |
|
59 * |
|
60 * @return the specificity |
|
61 */ |
|
62 public int[] getSpecificity() |
|
63 { |
|
64 return iSpecificity; |
|
65 } |
|
66 |
|
67 /** |
|
68 * Reset the table. |
|
69 */ |
|
70 public void reset() |
|
71 { |
|
72 iSpecificity[ ID ] = 0; |
|
73 iSpecificity[ ATTRIBUTE ] = 0; |
|
74 iSpecificity[ ELEMENT ] = 0; |
|
75 } |
|
76 |
|
77 /** |
|
78 * Compare for another specificity. |
|
79 * |
|
80 * Order for priorities (3 has the highest priority): 1. element 2. .class |
|
81 * 3. #id |
|
82 * |
|
83 * @param aSpecificity Specificity to be compared |
|
84 * |
|
85 * @return 0 if this is equal, -1 if this is less, +1 if this is greater. |
|
86 */ |
|
87 public int compare( CSSSpecificity aSpecificity ) |
|
88 { |
|
89 int difference; |
|
90 |
|
91 difference = iSpecificity[ ID ] - aSpecificity.iSpecificity[ ID ]; |
|
92 if ( difference != 0 ) |
|
93 { |
|
94 if ( difference < 0 ) |
|
95 { |
|
96 return -1; |
|
97 } |
|
98 else |
|
99 { |
|
100 return 1; |
|
101 } |
|
102 } |
|
103 |
|
104 difference = iSpecificity[ ATTRIBUTE ] |
|
105 - aSpecificity.iSpecificity[ ATTRIBUTE ]; |
|
106 if ( difference != 0 ) |
|
107 { |
|
108 if ( difference < 0 ) |
|
109 { |
|
110 return -1; |
|
111 } |
|
112 else |
|
113 { |
|
114 return 1; |
|
115 } |
|
116 } |
|
117 |
|
118 difference = iSpecificity[ ELEMENT ] |
|
119 - aSpecificity.iSpecificity[ ELEMENT ]; |
|
120 if ( difference != 0 ) |
|
121 { |
|
122 if ( difference < 0 ) |
|
123 { |
|
124 return -1; |
|
125 } |
|
126 else |
|
127 { |
|
128 return 1; |
|
129 } |
|
130 } |
|
131 |
|
132 return 0; |
|
133 } |
|
134 |
|
135 } |
|