remove Ambiguity.

This commit is contained in:
nieqiurong 2024-04-19 22:38:36 +08:00
parent 2f67d16b92
commit f2fd9b892b

View File

@ -405,6 +405,7 @@ public class MybatisConfiguration extends Configuration {
private static final long serialVersionUID = -4950446264854982944L;
private final String name;
private BiFunction<V, V, String> conflictMessageProducer;
private final Object AMBIGUITY_INSTANCE = new Object();
public StrictMap(String name, int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
@ -453,7 +454,7 @@ public class MybatisConfiguration extends Configuration {
if (super.get(shortKey) == null) {
super.put(shortKey, value);
} else {
super.put(shortKey, (V) new StrictMap.Ambiguity(shortKey));
super.put(shortKey, (V) AMBIGUITY_INSTANCE);
}
}
}
@ -465,7 +466,6 @@ public class MybatisConfiguration extends Configuration {
if (key == null) {
return false;
}
return super.get(key) != null;
}
@ -475,25 +475,13 @@ public class MybatisConfiguration extends Configuration {
if (value == null) {
throw new IllegalArgumentException(name + " does not contain value for " + key);
}
if (useGeneratedShortKey && value instanceof StrictMap.Ambiguity) {
throw new IllegalArgumentException(((StrictMap.Ambiguity) value).getSubject() + " is ambiguous in " + name
if (useGeneratedShortKey && AMBIGUITY_INSTANCE == value) {
throw new IllegalArgumentException(key + " is ambiguous in " + name
+ " (try using the full name including the namespace, or rename one of the entries)");
}
return value;
}
protected class Ambiguity {
private final String subject;
public Ambiguity(String subject) {
this.subject = subject;
}
public String getSubject() {
return subject;
}
}
private String getShortName(String key) {
final String[] keyParts = key.split("\\.");
return keyParts[keyParts.length - 1];