Class QualifiedNameMap<T>

  • Type Parameters:
    T - The class of the object which should be stored in the map.
    All Implemented Interfaces:
    Serializable, Map<QualifiedName,​T>

    public class QualifiedNameMap<T>
    extends Object
    implements Map<QualifiedName,​T>, Serializable
    A special map with a QualifiedName as a key. This map acts as a normal map, except that it has an additional method, getInNamespace(), which respects the visibility rules in the namespace hierarchy. Null cannot be stored as a key for this map.
    See Also:
    Serialized Form
    • Constructor Detail

      • QualifiedNameMap

        public QualifiedNameMap()
        Constructs an empty QualifiedNameMap.
      • QualifiedNameMap

        public QualifiedNameMap​(Map<? extends QualifiedName,​? extends T> map)
        Constructs a shallow copy of the supplied map.
        Parameters:
        map - the map to copy, not null.
    • Method Detail

      • getInHierarchy

        public T getInHierarchy​(QualifiedName key)
        Returns the most specific entry in the map which is visible for the provided key. I.e. not only the namespace of the provided QualifiedName is searched, but also all the parent namespaces of the provided QualifiedName. Note that if the most specific matching key is mapped to null, then null is returned, even if another less specific entry exists which is not mapped to null. If only exact matches for the QualifiedName should be returned, use the get(Object) method.
        Parameters:
        key - the qualified name for which the entries in the map should be searched, not null.
        Returns:
        The entry which is visible to the supplied QualifiedName, or null if no such entry exists. If more such entries exist, the most specific one (i.e. the one with the longest namespace) is returned.
        Throws:
        NullPointerException - if key is null.
        See Also:
        get(Object)
      • getKeyInHierarchy

        public QualifiedName getKeyInHierarchy​(QualifiedName key)
        Returns the most specific key in the map which is visible for the provided key. I.e. not only the namespace of the provided QualifiedName is searched, but also all the parent namespaces of the provided QualifiedName. If no such key exists, null is returned.
        Parameters:
        key - the qualified name for which the entries in the map should be searched, not null.
        Returns:
        The key which is visible to the supplied QualifiedName, or null if no such key exists. If more such keys exist, the most specific one (i.e. the one with the longest namespace) is returned.
        Throws:
        NullPointerException - if key is null.
      • getAllInHierarchy

        public QualifiedNameMap<T> getAllInHierarchy​(Namespace namespace)
        Returns all mappings which live in the given namespace. If one mapping hides another mapping, i.e. if one mapping is a more specialized version of another, both mappings are present in the returned map. For example, if the map contains mappings for org.apache.torque:name1, org.apache:name1, org.apache.torque:name2 and org.apache.torque.generator:name1, and the queried namespace is org.apache.torque, then the mappings for org.apache.torque:name1 and org.apache.torque:name2 and org.apache:name1 are returned. The mapping for org.apache.torque.generator:name1 is not returned, because it is not in the target namespace.
        Parameters:
        namespace - the namespace in which the desired objects should be visible.
        Returns:
        all mappings in the desired Namespace, not null.
      • getInHierarchy

        public QualifiedNameMap<T> getInHierarchy​(Namespace namespace)
        Returns all mappings which live in the given namespace. If one mapping hides another mapping, i.e. if one mapping is a more specialized version of another, the hidden mapping is NOT returned. For example, if the map contains mappings for org.apache.torque:name1, org.apache:name1, org.apache.torque:name2 and org.apache.torque.generator:name1, and the queried namespace is org.apache.torque, then the mappings for org.apache.torque:name1 and org.apache.torque:name2 are returned. The mapping for org.apache:name1 is hidden by org.apache.torque:name1, and org.apache.torque.generator:name1 is not in the target namespace.
        Parameters:
        namespace - the namespace in which the desired objects should be visible.
        Returns:
        all mappings in the desired Namespace, except the mappings which are hidden by another mapping, not null.
      • get

        public T get​(Object key)
        Returns the object which is mapped to the given key. Only Objects of class Namespace are used as keys in this map.
        Specified by:
        get in interface Map<QualifiedName,​T>
        Parameters:
        key - the key for which the mapped object should be returned.
        Returns:
        the object mapped to the given key, or null if no mapping exists for the key or null is mapped to the key.
        See Also:
        Map.get(java.lang.Object), getInHierarchy(QualifiedName)
      • put

        public T put​(QualifiedName key,
                     T value)
        Creates or overwrites a mapping in the map. Null as key is not supported.
        Specified by:
        put in interface Map<QualifiedName,​T>
        Parameters:
        key - the key for the mapping, not null.
        value - the object mapped to the key.
        Returns:
        the previous object which was mapped to the given key, or null if no mapping existed for the given key.
        See Also:
        Map.put(Object, Object)
      • remove

        public T remove​(Object key)
        Removes the mapping for the supplied key, if this mapping exists.
        Specified by:
        remove in interface Map<QualifiedName,​T>
        Parameters:
        key - the key for which the mapping should be removed.
        Returns:
        the object which was previously mapped to the key, or null if no mapping existed for the provided key.
        See Also:
        Map.remove(java.lang.Object)
      • containsKey

        public boolean containsKey​(Object key)
        Returns if this Map contains a mapping for the given key.
        Specified by:
        containsKey in interface Map<QualifiedName,​T>
        Parameters:
        key - the key for which the existence of a mapping should be checked.
        Returns:
        true if the map contains a mapping for the given key, false otherwise.
        See Also:
        Map.containsKey(java.lang.Object)
      • containsValue

        public boolean containsValue​(Object value)
        Checks if any key is mapped to the given value.
        Specified by:
        containsValue in interface Map<QualifiedName,​T>
        Parameters:
        value - the value which existence should be checked in the map.
        Returns:
        true if any key is mapped to the given value, false otherwise.
        See Also:
        Map.containsValue(java.lang.Object)
      • size

        public int size()
        Counts all mappings in the map.
        Specified by:
        size in interface Map<QualifiedName,​T>
        Returns:
        the number of mappings in the map.
        See Also:
        Map.size()
      • isEmpty

        public boolean isEmpty()
        Returns if the map contains any mappings at all.
        Specified by:
        isEmpty in interface Map<QualifiedName,​T>
        Returns:
        true if the map contains mappings, false otherwise.
        See Also:
        Map.isEmpty()
      • getMoreSpecific

        public T getMoreSpecific​(T object1,
                                 QualifiedName qualifiedName1,
                                 T object2,
                                 QualifiedName qualifiedName2)
        Returns the more specific object out of two objects (the object which hides the other object). If one of the two objects is null, the other is returned. If both objects is null, null is returned. If both objects are in the same namespace, object1 is returned. It is assumed that namespace1 is an ancestor namespace of namespace2 or that namespace2 is in an ancestor namespace of namespace1 or both namespaces are the same.
        Parameters:
        object1 - the first object to compare.
        qualifiedName1 - the qualified name of the first object, must not be null if object1 is not null.
        object2 - the second object to compare.
        qualifiedName2 - the namepsace of the second object, must not be null, if object2 is not null.
        Returns:
        the more specific object, or null if both object1 and object2 are null.
        Throws:
        NullPointerException - if object1 and object2 are not null and namespace1 or namespace2 are null.
      • equals

        public boolean equals​(Object object)
        Checks if this QualifiedNameMap is equal to another object. This is true if and only if the other object is a QualifiedNameMap, and contains the same mappings as this QualifiedNameMap.
        Specified by:
        equals in interface Map<QualifiedName,​T>
        Overrides:
        equals in class Object
        Parameters:
        object - the object to check whether it is equal to this object.
        Returns:
        true if this QualifiedNameMap is equal to the object, false otherwise.
      • hashCode

        public int hashCode()
        Returns a hashCode for this object. The returned hashCode is consistent with equals().
        Specified by:
        hashCode in interface Map<QualifiedName,​T>
        Overrides:
        hashCode in class Object
        Returns:
        a hashcode for this QualifiedNameMap.
      • toString

        public String toString()
        Returns a string representation of this map for debugging purposes.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this map, not null.