Skip to content

Commit 8c79132

Browse files
committed
[refactor] small tweaks in FunctionSignature
- final value in addMetadata - simplify and combine conditions in equals - fix output of toString (" as " before returntype) - rename char constant var to ANON_VAR
1 parent c26eae1 commit 8c79132

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

exist-core/src/main/java/org/exist/xquery/FunctionSignature.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,14 @@ public void setDescription(final String description) {
170170
this.description = description;
171171
}
172172

173-
public void addMetadata(final String key, String value) {
173+
public void addMetadata(final String key, final String value) {
174174
if(metadata == null) {
175175
metadata = new HashMap<>(5);
176176
}
177177
final String old = metadata.get(key);
178-
if (old != null) {
179-
// if the key exists, simply append the new value
180-
value = old + ", " + value;
181-
}
182-
metadata.put(key, value);
178+
// if the key exists, append the new value
179+
final String newValue = old == null ? value : old + ", " + value;
180+
metadata.put(key, newValue);
183181
}
184182

185183
public String getMetadata(final String key) {
@@ -232,7 +230,7 @@ public String toString() {
232230
buf.append(name.getStringValue());
233231
buf.append('(');
234232
if(arguments != null) {
235-
final char var = 'a';
233+
final char ANON_VAR = 'a';
236234
for(int i = 0; i < arguments.length; i++) {
237235
if(i > 0) {
238236
buf.append(", ");
@@ -241,7 +239,7 @@ public String toString() {
241239
if(arguments[i] instanceof FunctionParameterSequenceType) {
242240
buf.append(((FunctionParameterSequenceType)arguments[i]).getAttributeName());
243241
} else {
244-
buf.append((char)(var + i));
242+
buf.append((char)(ANON_VAR + i));
245243
}
246244
buf.append(" as ");
247245
buf.append(arguments[i].toString());
@@ -251,15 +249,15 @@ public String toString() {
251249
buf.append(", ...");
252250
}
253251
}
254-
buf.append(") ");
252+
buf.append(") as ");
255253
buf.append(returnType.toString());
256254

257255
return buf.toString();
258256
}
259257

260258
@Override
261259
public boolean equals(final Object obj) {
262-
if(obj == null || !(obj instanceof FunctionSignature)) {
260+
if (!(obj instanceof FunctionSignature)) {
263261
return false;
264262
}
265263
// quick comparison by object identity
@@ -275,11 +273,8 @@ public boolean equals(final Object obj) {
275273
return false;
276274
}
277275

278-
if (name.equals(other.name)) {
279-
return getArgumentCount() == other.getArgumentCount();
280-
}
281-
282-
return false;
276+
// compare by QName and arity
277+
return (name.equals(other.name) && getArgumentCount() == other.getArgumentCount());
283278
}
284279

285280
/**

0 commit comments

Comments
 (0)