+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof StringModule)) {
+ return false;
+ }
+ final StringModule other = (StringModule) obj;
+ return namespace.equals(other.namespace) && Objects.equals(revision, other.revision);
+ }
+
+ QNameModule toQNameModule() {
+ return QNameModule.create(URI.create(namespace), Revision.ofNullable(revision));
+ }
+ }
+
+ private static final int MAX_QNAME_CACHE_SIZE = Integer.getInteger(
+ "org.opendaylight.controller.cluster.datastore.node.utils.qname-cache.max-size", 10000);
+ private static final int MAX_MODULE_CACHE_SIZE = Integer.getInteger(
+ "org.opendaylight.controller.cluster.datastore.node.utils.module-cache.max-size", 2000);
+
+ private static final LoadingCache<String, QName> LEGACY_CACHE = CacheBuilder.newBuilder()
+ .maximumSize(MAX_QNAME_CACHE_SIZE).weakValues().build(new CacheLoader<String, QName>() {
+ @Override
+ public QName load(final String key) {
+ return QName.create(key).intern();
+ }
+ });
+ private static final LoadingCache<StringQName, QName> STRING_CACHE = CacheBuilder.newBuilder()
+ .maximumSize(MAX_QNAME_CACHE_SIZE).weakValues().build(new CacheLoader<StringQName, QName>() {
+ @Override
+ public QName load(final StringQName key) {
+ return key.toQName().intern();
+ }
+ });
+ private static final LoadingCache<ModuleQName, QName> QNAME_CACHE = CacheBuilder.newBuilder()
+ .maximumSize(MAX_QNAME_CACHE_SIZE).weakValues().build(new CacheLoader<ModuleQName, QName>() {
+ @Override
+ public QName load(final ModuleQName key) {
+ return key.toQName().intern();
+ }
+ });
+ private static final LoadingCache<StringModule, QNameModule> MODULE_CACHE = CacheBuilder.newBuilder()
+ .maximumSize(MAX_MODULE_CACHE_SIZE).weakValues().build(new CacheLoader<StringModule, QNameModule>() {
+ @Override
+ public QNameModule load(final StringModule key) {
+ return key.toQNameModule().intern();
+ }
+ });
+
+ private QNameFactory() {
+
+ }
+
+ @Deprecated
+ public static QName create(final String name) {
+ return LEGACY_CACHE.getUnchecked(name);
+ }
+
+ public static QName create(final String localName, final String namespace, final @Nullable String revision) {
+ return STRING_CACHE.getUnchecked(new StringQName(localName, namespace, revision));
+ }
+
+ public static QName create(final QNameModule module, final String localName) {
+ return QNAME_CACHE.getUnchecked(new ModuleQName(module, localName));
+ }