Skip to content

Commit 418516e

Browse files
committed
[refactor] Remove dependency on commons-collections4
1 parent f21ee77 commit 418516e

File tree

5 files changed

+89
-90
lines changed

5 files changed

+89
-90
lines changed

exist-parent/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,6 @@
375375
<version>3.3.0</version>
376376
</dependency>
377377

378-
<dependency>
379-
<groupId>org.apache.commons</groupId>
380-
<artifactId>commons-collections4</artifactId>
381-
<version>4.4</version>
382-
</dependency>
383-
384378
<dependency>
385379
<groupId>org.exquery</groupId>
386380
<artifactId>exquery-common</artifactId>

extensions/exquery/restxq/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@
7575
<artifactId>cglib</artifactId>
7676
</dependency>
7777

78-
<dependency>
79-
<groupId>org.apache.commons</groupId>
80-
<artifactId>commons-collections4</artifactId>
81-
</dependency>
82-
8378
<dependency>
8479
<groupId>commons-io</groupId>
8580
<artifactId>commons-io</artifactId>

extensions/exquery/restxq/src/main/java/org/exist/extensions/exquery/restxq/impl/adapters/TypeAdapter.java

Lines changed: 75 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -26,194 +26,204 @@
2626
*/
2727
package org.exist.extensions.exquery.restxq.impl.adapters;
2828

29-
import org.apache.commons.collections4.BidiMap;
30-
import org.apache.commons.collections4.bidimap.DualHashBidiMap;
29+
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
30+
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
31+
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
32+
import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
3133
import org.exist.xquery.value.Type;
3234

35+
import javax.annotation.Nullable;
36+
3337
/**
3438
*
3539
* @author <a href="mailto:[email protected]">Adam Retter</a>
3640
*/
3741
public class TypeAdapter {
38-
39-
//eXist-db XQuery Type <-> EXQuery Type
40-
private final static BidiMap mappings = new DualHashBidiMap();
42+
43+
private static final Int2ObjectMap<org.exquery.xquery.Type> EXISTDB_TO_EXQUERY_MAP = new Int2ObjectOpenHashMap<>(53);
44+
private static final Reference2IntMap<org.exquery.xquery.Type> EXQUERY_TO_EXISTDB_MAP = new Reference2IntOpenHashMap<>(53);
45+
46+
private static void addMapping(final int existdbType, final org.exquery.xquery.Type exqueryType) {
47+
EXISTDB_TO_EXQUERY_MAP.put(existdbType, exqueryType);
48+
EXQUERY_TO_EXISTDB_MAP.put(exqueryType, existdbType);
49+
}
50+
4151
static {
42-
mappings.put(Type.NODE,
52+
addMapping(Type.NODE,
4353
org.exquery.xquery.Type.NODE);
4454

45-
mappings.put(Type.ELEMENT,
55+
addMapping(Type.ELEMENT,
4656
org.exquery.xquery.Type.ELEMENT);
4757

48-
mappings.put(Type.ATTRIBUTE,
58+
addMapping(Type.ATTRIBUTE,
4959
org.exquery.xquery.Type.ATTRIBUTE);
5060

51-
mappings.put(Type.TEXT,
61+
addMapping(Type.TEXT,
5262
org.exquery.xquery.Type.TEXT);
5363

54-
mappings.put(Type.PROCESSING_INSTRUCTION,
64+
addMapping(Type.PROCESSING_INSTRUCTION,
5565
org.exquery.xquery.Type.PROCESSING_INSTRUCTION);
5666

57-
mappings.put(Type.COMMENT,
67+
addMapping(Type.COMMENT,
5868
org.exquery.xquery.Type.COMMENT);
5969

60-
mappings.put(Type.DOCUMENT,
70+
addMapping(Type.DOCUMENT,
6171
org.exquery.xquery.Type.DOCUMENT);
6272

63-
mappings.put(Type.ITEM,
73+
addMapping(Type.ITEM,
6474
org.exquery.xquery.Type.ITEM);
6575

66-
mappings.put(Type.ANY_TYPE,
76+
addMapping(Type.ANY_TYPE,
6777
org.exquery.xquery.Type.ANY_TYPE);
6878

69-
mappings.put(Type.ANY_SIMPLE_TYPE,
79+
addMapping(Type.ANY_SIMPLE_TYPE,
7080
org.exquery.xquery.Type.ANY_SIMPLE_TYPE);
7181

72-
mappings.put(Type.UNTYPED,
82+
addMapping(Type.UNTYPED,
7383
org.exquery.xquery.Type.UNTYPED);
7484

75-
mappings.put(Type.STRING,
85+
addMapping(Type.STRING,
7686
org.exquery.xquery.Type.STRING);
7787

78-
mappings.put(Type.BOOLEAN,
88+
addMapping(Type.BOOLEAN,
7989
org.exquery.xquery.Type.BOOLEAN);
8090

81-
mappings.put(Type.QNAME,
91+
addMapping(Type.QNAME,
8292
org.exquery.xquery.Type.QNAME);
8393

84-
mappings.put(Type.ANY_URI,
94+
addMapping(Type.ANY_URI,
8595
org.exquery.xquery.Type.ANY_URI);
8696

87-
mappings.put(Type.BASE64_BINARY,
97+
addMapping(Type.BASE64_BINARY,
8898
org.exquery.xquery.Type.BASE64_BINARY);
8999

90-
mappings.put(Type.HEX_BINARY,
100+
addMapping(Type.HEX_BINARY,
91101
org.exquery.xquery.Type.HEX_BINARY);
92102

93-
mappings.put(Type.NOTATION,
103+
addMapping(Type.NOTATION,
94104
org.exquery.xquery.Type.NOTATION);
95105

96-
mappings.put(Type.INTEGER,
106+
addMapping(Type.INTEGER,
97107
org.exquery.xquery.Type.INTEGER);
98108

99-
mappings.put(Type.DECIMAL,
109+
addMapping(Type.DECIMAL,
100110
org.exquery.xquery.Type.DECIMAL);
101111

102-
mappings.put(Type.FLOAT,
112+
addMapping(Type.FLOAT,
103113
org.exquery.xquery.Type.FLOAT);
104114

105-
mappings.put(Type.DOUBLE,
115+
addMapping(Type.DOUBLE,
106116
org.exquery.xquery.Type.DOUBLE);
107117

108-
mappings.put(Type.NON_POSITIVE_INTEGER,
118+
addMapping(Type.NON_POSITIVE_INTEGER,
109119
org.exquery.xquery.Type.NON_POSITIVE_INTEGER);
110120

111-
mappings.put(Type.NEGATIVE_INTEGER,
121+
addMapping(Type.NEGATIVE_INTEGER,
112122
org.exquery.xquery.Type.NEGATIVE_INTEGER);
113123

114-
mappings.put(Type.LONG,
124+
addMapping(Type.LONG,
115125
org.exquery.xquery.Type.LONG);
116126

117-
mappings.put(Type.INT,
127+
addMapping(Type.INT,
118128
org.exquery.xquery.Type.INT);
119129

120-
mappings.put(Type.SHORT,
130+
addMapping(Type.SHORT,
121131
org.exquery.xquery.Type.SHORT);
122132

123-
mappings.put(Type.BYTE,
133+
addMapping(Type.BYTE,
124134
org.exquery.xquery.Type.BYTE);
125135

126-
mappings.put(Type.NON_NEGATIVE_INTEGER,
136+
addMapping(Type.NON_NEGATIVE_INTEGER,
127137
org.exquery.xquery.Type.NON_NEGATIVE_INTEGER);
128138

129-
mappings.put(Type.UNSIGNED_LONG,
139+
addMapping(Type.UNSIGNED_LONG,
130140
org.exquery.xquery.Type.UNSIGNED_LONG);
131141

132-
mappings.put(Type.UNSIGNED_SHORT,
142+
addMapping(Type.UNSIGNED_SHORT,
133143
org.exquery.xquery.Type.UNSIGNED_SHORT);
134144

135-
mappings.put(Type.UNSIGNED_BYTE,
145+
addMapping(Type.UNSIGNED_BYTE,
136146
org.exquery.xquery.Type.UNSIGNED_BYTE);
137147

138-
mappings.put(Type.POSITIVE_INTEGER,
148+
addMapping(Type.POSITIVE_INTEGER,
139149
org.exquery.xquery.Type.POSITIVE_INTEGER);
140150

141-
mappings.put(Type.DATE_TIME,
151+
addMapping(Type.DATE_TIME,
142152
org.exquery.xquery.Type.DATE_TIME);
143153

144-
mappings.put(Type.DATE,
154+
addMapping(Type.DATE,
145155
org.exquery.xquery.Type.DATE);
146156

147-
mappings.put(Type.TIME,
157+
addMapping(Type.TIME,
148158
org.exquery.xquery.Type.TIME);
149159

150-
mappings.put(Type.DURATION,
160+
addMapping(Type.DURATION,
151161
org.exquery.xquery.Type.DURATION);
152162

153-
mappings.put(Type.YEAR_MONTH_DURATION,
163+
addMapping(Type.YEAR_MONTH_DURATION,
154164
org.exquery.xquery.Type.YEAR_MONTH_DURATION);
155165

156-
mappings.put(Type.DAY_TIME_DURATION,
166+
addMapping(Type.DAY_TIME_DURATION,
157167
org.exquery.xquery.Type.DAY_TIME_DURATION);
158168

159-
mappings.put(Type.GYEAR,
169+
addMapping(Type.GYEAR,
160170
org.exquery.xquery.Type.G_YEAR);
161171

162-
mappings.put(Type.GMONTH,
172+
addMapping(Type.GMONTH,
163173
org.exquery.xquery.Type.G_MONTH);
164174

165-
mappings.put(Type.GDAY,
175+
addMapping(Type.GDAY,
166176
org.exquery.xquery.Type.G_DAY);
167177

168-
mappings.put(Type.GYEARMONTH,
178+
addMapping(Type.GYEARMONTH,
169179
org.exquery.xquery.Type.G_YEAR_MONTH);
170180

171-
mappings.put(Type.GMONTHDAY,
181+
addMapping(Type.GMONTHDAY,
172182
org.exquery.xquery.Type.G_MONTH_DAY);
173183

174-
mappings.put(Type.TOKEN,
184+
addMapping(Type.TOKEN,
175185
org.exquery.xquery.Type.TOKEN);
176186

177-
mappings.put(Type.NORMALIZED_STRING,
187+
addMapping(Type.NORMALIZED_STRING,
178188
org.exquery.xquery.Type.NORMALIZED_STRING);
179189

180-
mappings.put(Type.LANGUAGE,
190+
addMapping(Type.LANGUAGE,
181191
org.exquery.xquery.Type.LANGUAGE);
182192

183-
mappings.put(Type.NMTOKEN,
193+
addMapping(Type.NMTOKEN,
184194
org.exquery.xquery.Type.NM_TOKEN);
185195

186-
mappings.put(Type.NAME,
196+
addMapping(Type.NAME,
187197
org.exquery.xquery.Type.NAME);
188198

189-
mappings.put(Type.NCNAME,
199+
addMapping(Type.NCNAME,
190200
org.exquery.xquery.Type.NC_NAME);
191201

192-
mappings.put(Type.ID,
202+
addMapping(Type.ID,
193203
org.exquery.xquery.Type.ID);
194204

195-
mappings.put(Type.IDREF,
205+
addMapping(Type.IDREF,
196206
org.exquery.xquery.Type.ID_REF);
197207

198-
mappings.put(Type.ENTITY,
208+
addMapping(Type.ENTITY,
199209
org.exquery.xquery.Type.ENTITY);
200210
}
201211

202-
public static org.exquery.xquery.Type toExQueryType(int type) {
203-
org.exquery.xquery.Type exQueryType = (org.exquery.xquery.Type)mappings.get(type);
212+
public static org.exquery.xquery.Type toExQueryType(final int type) {
213+
@Nullable org.exquery.xquery.Type exQueryType = EXISTDB_TO_EXQUERY_MAP.get(type);
204214
if(exQueryType == null) {
205-
exQueryType = org.exquery.xquery.Type.ANY_TYPE;
215+
exQueryType = org.exquery.xquery.Type.ANY_TYPE;
206216
}
207217

208218
return exQueryType;
209219
}
210220

211-
public static int toExistType(org.exquery.xquery.Type type) {
212-
Integer existType = (Integer)mappings.getKey(type);
213-
if(existType == null) {
221+
public static int toExistType(final org.exquery.xquery.Type type) {
222+
int existType = EXQUERY_TO_EXISTDB_MAP.getOrDefault(type,-99);
223+
if (existType == -99) {
214224
existType = Type.ANY_TYPE;
215225
}
216-
226+
217227
return existType;
218228
}
219229
}

extensions/indexes/lucene/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@
7575
<artifactId>exist-core</artifactId>
7676
<version>${project.version}</version>
7777
</dependency>
78-
79-
<dependency>
80-
<groupId>org.apache.commons</groupId>
81-
<artifactId>commons-collections4</artifactId>
82-
</dependency>
8378

8479
<dependency>
8580
<groupId>org.apache.logging.log4j</groupId>

extensions/indexes/lucene/src/main/java/org/exist/indexing/lucene/LuceneIndexConfig.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
*/
4646
package org.exist.indexing.lucene;
4747

48-
import org.apache.commons.collections4.MultiMap;
49-
import org.apache.commons.collections4.map.MultiValueMap;
5048
import org.apache.logging.log4j.LogManager;
5149
import org.apache.logging.log4j.Logger;
5250
import org.apache.lucene.analysis.Analyzer;
@@ -59,6 +57,7 @@
5957
import org.w3c.dom.Element;
6058
import org.w3c.dom.Node;
6159

60+
import javax.annotation.Nullable;
6261
import java.util.*;
6362

6463
public class LuceneIndexConfig {
@@ -100,7 +99,7 @@ public class LuceneIndexConfig {
10099

101100
// This is for the @attr match boosting
102101
// and the intention is to do a proper predicate check instead in the future. /ljo
103-
private MultiMap matchAttrs;
102+
private Map<String, List<MatchAttrData>> matchAttrs;
104103
protected final static Logger LOG = LogManager.getLogger(LuceneIndexConfig.class);
105104

106105

@@ -222,10 +221,17 @@ private void parse(LuceneConfig parent, Element root, Map<String, String> namesp
222221
}
223222
}
224223

225-
if (matchAttrs == null)
226-
matchAttrs = new MultiValueMap();
224+
final List<MatchAttrData> dataList;
225+
if (matchAttrs == null) {
226+
matchAttrs = new HashMap<>();
227+
dataList = new ArrayList<>();
228+
matchAttrs.put(qname, dataList);
229+
} else {
230+
dataList = matchAttrs.computeIfAbsent(qname, key -> new ArrayList<>());
231+
}
232+
233+
dataList.add(new MatchAttrData(qname, value, boost, onSibling));
227234

228-
matchAttrs.put(qname, new MatchAttrData(qname, value, boost, onSibling));
229235
break;
230236
}
231237
}
@@ -278,12 +284,11 @@ public float getAttrBoost(final Collection<AttrImpl> attributes) {
278284
boolean hasBoost = false;
279285

280286
for (final Attr attr : attributes) {
281-
Collection<MatchAttrData> matchAttrData
282-
= (Collection<MatchAttrData>) matchAttrs.get(attr.getName());
283-
287+
@Nullable final List<MatchAttrData> matchAttrData = matchAttrs == null ? null : matchAttrs.get(attr.getName());
284288
if (matchAttrData == null) {
285289
continue;
286290
}
291+
287292
for (MatchAttrData matchAttrDatum : matchAttrData) {
288293
// if matchAttr value is null we don't care about the value
289294
if (matchAttrDatum.value == null

0 commit comments

Comments
 (0)