Skip to content

Package: DuplicateAttributeVerifier

DuplicateAttributeVerifier

nameinstructionbranchcomplexitylinemethod
DuplicateAttributeVerifier()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
checkForDuplicateAttribute(int, int)
M: 23 C: 61
73%
M: 3 C: 7
70%
M: 2 C: 4
67%
M: 5 C: 15
75%
M: 0 C: 1
100%
clear()
M: 0 C: 19
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
increasePool(int)
M: 0 C: 39
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
reset()
M: 0 C: 12
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3: *
4: * Copyright (c) 2004-2018 Oracle and/or its affiliates. All rights reserved.
5: *
6: * Oracle licenses this file to You under the Apache License, Version 2.0
7: * (the "License"); you may not use this file except in compliance with
8: * the License. You may obtain a copy of the License at
9: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: package com.sun.xml.fastinfoset.util;
20:
21: import org.jvnet.fastinfoset.FastInfosetException;
22: import com.sun.xml.fastinfoset.CommonResourceBundle;
23:
24:
25: public class DuplicateAttributeVerifier {
26: public static final int MAP_SIZE = 256;
27:
28: public int _currentIteration;
29:
30: public static class Entry {
31: private int iteration;
32: private int value;
33:
34: private Entry hashNext;
35:
36: private Entry poolNext;
37: }
38:
39: private Entry[] _map;
40:
41: public final Entry _poolHead;
42: public Entry _poolCurrent;
43: private Entry _poolTail;
44:
45:
46: public DuplicateAttributeVerifier() {
47: _poolTail = _poolHead = new Entry();
48: }
49:
50: public final void clear() {
51: _currentIteration = 0;
52:
53: Entry e = _poolHead;
54:• while (e != null) {
55: e.iteration = 0;
56: e = e.poolNext;
57: }
58:
59: reset();
60: }
61:
62: public final void reset() {
63: _poolCurrent = _poolHead;
64:• if (_map == null) {
65: _map = new Entry[MAP_SIZE];
66: }
67: }
68:
69: private final void increasePool(int capacity) {
70:• if (_map == null) {
71: _map = new Entry[MAP_SIZE];
72: _poolCurrent = _poolHead;
73: } else {
74: final Entry tail = _poolTail;
75:• for (int i = 0; i < capacity; i++) {
76: final Entry e = new Entry();
77: _poolTail.poolNext = e;
78: _poolTail = e;
79: }
80:
81: _poolCurrent = tail.poolNext;
82: }
83: }
84:
85: public final void checkForDuplicateAttribute(int hash, int value) throws FastInfosetException {
86:• if (_poolCurrent == null) {
87: increasePool(16);
88: }
89:
90: // Get next free entry
91: final Entry newEntry = _poolCurrent;
92: _poolCurrent = _poolCurrent.poolNext;
93:
94: final Entry head = _map[hash];
95:• if (head == null || head.iteration < _currentIteration) {
96: newEntry.hashNext = null;
97: _map[hash] = newEntry;
98: newEntry.iteration = _currentIteration;
99: newEntry.value = value;
100: } else {
101: Entry e = head;
102: do {
103:• if (e.value == value) {
104: reset();
105: throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.duplicateAttribute"));
106: }
107:• } while ((e = e.hashNext) != null);
108:
109: newEntry.hashNext = head;
110: _map[hash] = newEntry;
111: newEntry.iteration = _currentIteration;
112: newEntry.value = value;
113: }
114: }
115: }