Skip to content

Commit aa05276

Browse files
committed
[refactor] better check for subtypes in Sync.java
1 parent a9a87b9 commit aa05276

File tree

1 file changed

+6
-24
lines changed
  • extensions/modules/file/src/main/java/org/exist/xquery/modules/file

1 file changed

+6
-24
lines changed

extensions/modules/file/src/main/java/org/exist/xquery/modules/file/Sync.java

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ private Map<String, Sequence> getOptions(final Sequence parameter) throws XPathE
178178
}
179179
options.put(EXCLUDES_OPT, seq);
180180

181-
checkOption(optionsMap, PRUNE_OPT, options, Type.BOOLEAN);
182-
checkOption(optionsMap, AFTER_OPT, options, Type.DATE_TIME, Type.DATE_TIME_STAMP);
181+
checkOption(optionsMap, PRUNE_OPT, Type.BOOLEAN, options);
182+
checkOption(optionsMap, AFTER_OPT, Type.DATE_TIME, options);
183183
} else if (parameter.itemAt(0).getType() == Type.DATE_TIME) {
184184
options.put(AFTER_OPT, parameter);
185185
} else {
@@ -192,43 +192,25 @@ private Map<String, Sequence> getOptions(final Sequence parameter) throws XPathE
192192
private void checkOption(
193193
final AbstractMapType optionsMap,
194194
final String name,
195-
final Map<String, Sequence> options,
196-
final int... expectedTypes
195+
final int expectedType,
196+
final Map<String, Sequence> options
197197
) throws XPathException {
198198
final Sequence p = optionsMap.get(new StringValue(this, name));
199199

200200
if (p.isEmpty()) {
201201
return; // nothing to do, continue
202202
}
203203

204-
if (p.hasMany() || !isExpectedType(p.getItemType(), expectedTypes)) {
204+
if (p.hasMany() || !Type.subTypeOf(p.getItemType(),expectedType)) {
205205
throw new XPathException(this, ErrorCodes.XPTY0004,
206206
"Invalid value type for option \"" + name + "\", expected " +
207-
formatTypes(expectedTypes) + " got " +
207+
Type.getTypeName(expectedType) + " got " +
208208
Type.getTypeName(p.itemAt(0).getType()));
209209
}
210210

211211
options.put(name, p);
212212
}
213213

214-
private boolean isExpectedType(final int actualType, final int... expectedTypes) {
215-
for(int type : expectedTypes) {
216-
if(type == actualType) {
217-
return true;
218-
}
219-
}
220-
return false;
221-
}
222-
223-
private String formatTypes(final int... expectedTypes) {
224-
StringBuilder buff = new StringBuilder(Type.getTypeName(expectedTypes[0]));
225-
for(int i = 1; i < expectedTypes.length; i++) {
226-
buff.append(", ");
227-
buff.append(Type.getTypeName(expectedTypes[i]));
228-
}
229-
return buff.toString();
230-
}
231-
232214
private Sequence startSync(
233215
final String target,
234216
final String collectionPath,

0 commit comments

Comments
 (0)