1 | /* $Id: XMLTokenTableBase.java 19907 2012-12-30 13:06:01Z closettop_nightlybuild $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009-2012 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * bobtarling | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2006 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.persistence; | |
40 | ||
41 | import java.util.Hashtable; | |
42 | import java.util.logging.Level; | |
43 | import java.util.logging.Logger; | |
44 | ||
45 | /** | |
46 | * @author Jim Holy | |
47 | */ | |
48 | ||
49 | abstract class XMLTokenTableBase { | |
50 | private static final Logger LOG = | |
51 | Logger.getLogger(XMLTokenTableBase.class.getName()); | |
52 | ||
53 | //////////////////////////////////////////////////////////////// | |
54 | // instance variables | |
55 | ||
56 | private Hashtable tokens = null; | |
57 | private boolean dbg = false; | |
58 | private String[] openTags = new String[100]; | |
59 | private int[] openTokens = new int[100]; | |
60 | private int numOpen = 0; | |
61 | ||
62 | ||
63 | //////////////////////////////////////////////////////////////// | |
64 | // constructors | |
65 | ||
66 | /** | |
67 | * The constructor. | |
68 | * | |
69 | * @param tableSize the size of the table | |
70 | */ | |
71 | public XMLTokenTableBase(int tableSize) { | |
72 | tokens = new Hashtable(tableSize); | |
73 |
1
1. |
setupTokens(); |
74 | } | |
75 | ||
76 | //////////////////////////////////////////////////////////////// | |
77 | // accessors | |
78 | ||
79 | /** | |
80 | * @param s the string | |
81 | * @param push true if the token is to be pushed | |
82 | * @return the token | |
83 | */ | |
84 | public final int toToken(String s, boolean push) { | |
85 |
1
1. toToken : negated conditional → NO_COVERAGE |
if (push) { |
86 |
1
1. toToken : Replaced integer addition with subtraction → NO_COVERAGE |
openTags[++numOpen] = s; |
87 |
1
1. toToken : negated conditional → NO_COVERAGE |
} else if (s.equals(openTags[numOpen])) { |
88 | LOG.log(Level.FINE, "matched: {0}", s); | |
89 |
2
1. toToken : Replaced integer subtraction with addition → NO_COVERAGE 2. toToken : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return openTokens[numOpen--]; |
90 | } | |
91 | Integer i = (Integer) tokens.get(s); | |
92 |
1
1. toToken : negated conditional → NO_COVERAGE |
if (i != null) { |
93 | openTokens[numOpen] = i.intValue(); | |
94 |
1
1. toToken : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return openTokens[numOpen]; |
95 | } else { | |
96 |
1
1. toToken : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return -1; |
97 | } | |
98 | } | |
99 | ||
100 | /** | |
101 | * @param d true if debugging | |
102 | */ | |
103 | public void setDbg(boolean d) { dbg = d; } | |
104 | ||
105 | /** | |
106 | * @return true if debugging is turned on | |
107 | */ | |
108 |
1
1. getDbg : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
public boolean getDbg() { return dbg; } |
109 | ||
110 | //////////////////////////////////////////////////////////////// | |
111 | // class methods | |
112 | ||
113 | /** | |
114 | * @param s the string represented by the token number | |
115 | * @param i the token number | |
116 | */ | |
117 | protected void addToken(String s, Integer i) { | |
118 | boolean error = false; | |
119 |
1
1. addToken : negated conditional → NO_COVERAGE |
if (dbg) { |
120 |
2
1. addToken : negated conditional → NO_COVERAGE 2. addToken : negated conditional → NO_COVERAGE |
if (tokens.contains(i) || tokens.containsKey(s)) { |
121 | LOG.log(Level.SEVERE, | |
122 | "ERROR: token table already contains " + s); | |
123 | error = true; | |
124 | } | |
125 | } | |
126 | tokens.put(s, i); | |
127 |
2
1. addToken : negated conditional → NO_COVERAGE 2. addToken : negated conditional → NO_COVERAGE |
if (dbg && !error) { |
128 | LOG.log(Level.FINE, "NOTE: added {0} to token table", s); | |
129 | } | |
130 | } | |
131 | ||
132 | /** | |
133 | * @param token the given token | |
134 | * @return true if the token is present | |
135 | */ | |
136 | public boolean contains(String token) { | |
137 |
1
1. contains : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return tokens.containsKey(token); |
138 | } | |
139 | ||
140 | /** | |
141 | * This function shall set up all the tokens with the addToken function. | |
142 | */ | |
143 | protected abstract void setupTokens(); | |
144 | ||
145 | } /* end class XMLTokenTableBase */ | |
Mutations | ||
73 |
1.1 |
|
85 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
89 |
1.1 2.2 |
|
92 |
1.1 |
|
94 |
1.1 |
|
96 |
1.1 |
|
108 |
1.1 |
|
119 |
1.1 |
|
120 |
1.1 2.2 |
|
127 |
1.1 2.2 |
|
137 |
1.1 |