Package org.apache.torque.generator.qname

# Class QualifiedNameMap<T>

java.lang.Object
org.apache.torque.generator.qname.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

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface java.util.Map

  `Map.Entry<K,V>`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `QualifiedNameMap()`
  Constructs an empty QualifiedNameMap.
  `QualifiedNameMap(Map<? extends QualifiedName,? extends T> map)`
  Constructs a shallow copy of the supplied map.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  Removes all mappings from this map.
  `boolean`
  `containsKey(Object key)`
  Returns if this Map contains a mapping for the given key.
  `boolean`
  `containsValue(Object value)`
  Checks if any key is mapped to the given value.
  `Set<Map.Entry<QualifiedName,T>>`
  `entrySet()`
  Returns all Entries in this map.
  `boolean`
  `equals(Object object)`
  Checks if this QualifiedNameMap is equal to another object.
  `T`
  `get(Object key)`
  Returns the object which is mapped to the given key.
  `QualifiedNameMap<T>`
  `getAllInHierarchy(Namespace namespace)`
  Returns all mappings which live in the given namespace.
  `QualifiedNameMap<T>`
  `getInHierarchy(Namespace namespace)`
  Returns all mappings which live in the given namespace.
  `T`
  `getInHierarchy(QualifiedName key)`
  Returns the most specific entry in the map which is visible for the provided key.
  `QualifiedName`
  `getKeyInHierarchy(QualifiedName key)`
  Returns the most specific key in the map which is visible for the provided key.
  `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).
  `int`
  `hashCode()`
  Returns a hashCode for this object.
  `boolean`
  `isEmpty()`
  Returns if the map contains any mappings at all.
  `Set<QualifiedName>`
  `keySet()`
  Returns all keys of the map.
  `T`
  `put(QualifiedName key, T value)`
  Creates or overwrites a mapping in the map.
  `void`
  `putAll(Map<? extends QualifiedName,? extends T> toPut)`
  Creates or overrides mappings for all the mappings in the supplied map.
  `T`
  `remove(Object key)`
  Removes the mapping for the supplied key, if this mapping exists.
  `int`
  `size()`
  Counts all mappings in the map.
  `String`
  `toString()`
  Returns a string representation of this map for debugging purposes.
  `Collection<T>`
  `values()`
  Returns all values in this map.

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface java.util.Map

  `compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll`

- ## Constructor Details

  - ### 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 Details

  - ### 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)`

  - ### putAll

    public void putAll(Map<? extends QualifiedName,? extends T> toPut)
    Creates or overrides mappings for all the mappings in the supplied map. The supplied map must not contain a mapping for the key `null`.
    Specified by:
      `putAll` in interface `Map<QualifiedName,T>`
    Parameters:
      `toPut` - the Map whcih mappings should be added to this map, not null.
    Throws:
      `NullPointerException` - if toPut is null.
      `IllegalArgumentException` - if toPut contains a mapping for the key `null`.
    See Also:
      - `Map.putAll(java.util.Map)`

  - ### 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)`

  - ### clear

    public void clear()
    Removes all mappings from this map.
    Specified by:
      `clear` in interface `Map<QualifiedName,T>`
    See Also:
      - `Map.clear()`

  - ### 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)`

  - ### entrySet

    public Set<Map.Entry<QualifiedName,T>> entrySet()
    Returns all Entries in this map.
    Specified by:
      `entrySet` in interface `Map<QualifiedName,T>`
    Returns:
      a Set containing all mappings in this map.
    See Also:
      - `Map.entrySet()`

  - ### 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)`

  - ### values

    public Collection<T> values()
    Returns all values in this map.
    Specified by:
      `values` in interface `Map<QualifiedName,T>`
    Returns:
      a collection containing all values in this map.
    See Also:
      - `Map.values()`

  - ### 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()`

  - ### keySet

    public Set<QualifiedName> keySet()
    Returns all keys of the map.
    Specified by:
      `keySet` in interface `Map<QualifiedName,T>`
    Returns:
      a Collection containing all keys of the map, never null.
    See Also:
      - `Map.keySet()`

  - ### 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.