Class QNameCache

java.lang.Object
dev.metaschema.core.qname.QNameCache

public final class QNameCache extends Object
Provides a cache for managing commonly reused qualified names, represented using the IEnhancedQName interface.

The cache operations provided by this cache are thread safe.

A unique integer index value is assigned for each namespace and localname pair. This index value can be used to retrieve the qualified name using the get(int) method. This allows the index value to be used in place of the actual qualified name.

The IEnhancedQName.getIndexPosition() method can be used to get the index value of a given qualified name.

  • Method Details

    • instance

      @NonNull public static QNameCache instance()
      Get the singleton qualified name cache.
      Returns:
      the singleton instance
    • cachedQNameFor

      @NonNull public IEnhancedQName cachedQNameFor(@NonNull String namespace, @NonNull String name)
      Get a cached qualified name based on the provided namespace and name.

      The qualified name will be added to the cache if it doesn't already exist.

      Parameters:
      namespace - the namespace for the new qualified name
      name - the local name for the new qualified name
      Returns:
      the new cached qualified name or the existing cached name if it already exists in the cache
    • get

      @Nullable public IEnhancedQName get(int index)
      Get an existing qualified name from the cache that is assigned to the provided index value.

      Note: There is a chance that an entry associated index value may not exist at first, but subsequent calls may find an associated value in the future if one is created with that value.

      Parameters:
      index - the index value for the qualified name
      Returns:
      the cached qualified name or null if a cache entry does not exist for the index value