import static org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil.getRevisionFormat;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Interner;
+import com.google.common.collect.Interners;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
*
*/
public final class QName implements Immutable, Serializable, Comparable<QName> {
+ private static final Interner<QName> INTERNER = Interners.newWeakInterner();
private static final ObjectCache CACHE = ObjectCacheFactory.getObjectCache(QName.class);
private static final long serialVersionUID = 5398411242927766414L;
*
* @param qname QName instance
* @return Cached instance, according to {@link ObjectCache} policy.
+ *
+ * @deprecated Use {@link #intern()} instead.
*/
+ @Deprecated
public static QName cachedReference(final QName qname) {
// We also want to make sure we keep the QNameModule cached
final QNameModule myMod = qname.getModule();
return module.getRevision();
}
+ /**
+ * Return an interned reference to a equivalent QName.
+ *
+ * @return Interned reference, or this object if it was interned.
+ */
+ public QName intern() {
+ // We also want to make sure we keep the QNameModule cached
+ final QNameModule cacheMod = module.intern();
+
+ // Identity comparison is here on purpose, as we are deciding whether to potentially store 'qname' into the
+ // interner. It is important that it does not hold user-supplied reference (such a String instance from
+ // parsing of an XML document).
+ final QName template = cacheMod == module ? this : QName.create(cacheMod, localName);
+
+ return INTERNER.intern(template);
+ }
+
@Override
public int hashCode() {
final int prime = 31;
package org.opendaylight.yangtools.yang.common;
import com.google.common.base.MoreObjects;
+import com.google.common.collect.Interner;
+import com.google.common.collect.Interners;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import org.slf4j.LoggerFactory;
public final class QNameModule implements Immutable, Serializable {
+ private static final Interner<QNameModule> INTERNER = Interners.newWeakInterner();
private static final ObjectCache CACHE = ObjectCacheFactory.getObjectCache(QNameModule.class);
private static final Logger LOG = LoggerFactory.getLogger(QNameModule.class);
private static final QNameModule NULL_INSTANCE = new QNameModule(null, null);
*
* @param module Module instance
* @return Cached instance, according to {@link ObjectCache} policy.
+ *
+ * @deprecated Use {@link #intern()} instead.
*/
+ @Deprecated
public static QNameModule cachedReference(final QNameModule module) {
return CACHE.getReference(module);
}
+ /**
+ * Return an interned reference to a equivalent QNameModule.
+ *
+ * @return Interned reference, or this object if it was interned.
+ */
+ public QNameModule intern() {
+ return INTERNER.intern(this);
+ }
+
/**
* Create a new QName module instance with specified namespace/revision.
*