• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eXist-db / exist / 40903079005

29 Oct 2026 03:35PM UTC coverage: 58.179% (-0.01%) from 58.193%
40903079005

push

github

web-flow
Merge pull request #6944 from eXist-db/dependabot/maven/greenmail.version-2.1.15

Bump greenmail.version from 2.1.14 to 2.1.15

32492 of 61720 branches covered (52.64%)

Branch coverage included in aggregate %.

85570 of 141209 relevant lines covered (60.6%)

2.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.23
/exist-core/src/main/java/org/exist/util/hashtable/NamePool.java
1
/*
2
 * eXist-db Open Source Native XML Database
3
 * Copyright (C) 2001 The eXist-db Authors
4
 *
5
 * info@exist-db.org
6
 * http://www.exist-db.org
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this library; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
 */
22
package org.exist.util.hashtable;
23

24
import java.util.concurrent.ConcurrentHashMap;
25
import java.util.concurrent.ConcurrentMap;
26

27
import net.jcip.annotations.ThreadSafe;
28
import org.exist.dom.QName;
29
import org.exist.xquery.Constants;
30

31
/**
32
 * @author Pieter Deelen
33
 */
34
@ThreadSafe
35
public class NamePool {
36

37
    private final ConcurrentMap<WrappedQName, QName> pool;
38

39
    public NamePool() {
2 ✔
40
        pool = new ConcurrentHashMap<>();
5 ✔
41
    }
1 ✔
42

43
    public QName getSharedName(final QName name) {
44
        final WrappedQName wrapped = new WrappedQName(name);
5 ✔
45
        final QName sharedName = pool.putIfAbsent(wrapped, name);
7 ✔
46
        if (sharedName == null) {
2 ✔
47
            // The name was not in the pool, return the name just added.
48
            return name;
2 ✔
49
        } else {
50
            // The name was in the pool, return the shared name.
51
            return sharedName;
2 ✔
52
        }
53
    }
54

55
    /**
56
     * QName ignores nameType and prefix when testing for equality.
57
     * Wrap it to compare all four parts instead, as {@link QName#isIdenticalTo(QName)} does.
58
     */
59
    private static class WrappedQName implements Comparable<WrappedQName> {
60
        private final QName qname;
61

62
        public WrappedQName(final QName qname) {
2 ✔
63
            this.qname = qname;
3 ✔
64
        }
1 ✔
65

66
        @Override
67
        public int compareTo(final WrappedQName other) {
68
            if (qname.getNameType() != other.qname.getNameType()) {
×
69
                return qname.getNameType() < other.qname.getNameType() ? Constants.INFERIOR : Constants.SUPERIOR;
×
70
            }
71
            return qname.compareTo(other.qname);
×
72
        }
73

74
        @Override
75
        public int hashCode() {
76
            return qname.identicalHashCode();
4 ✔
77
        }
78

79
        @Override
80
        public boolean equals(final Object obj) {
81
            return obj instanceof WrappedQName other && qname.isIdenticalTo(other.qname);
16 !
82
        }
83
    }
84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc