Interface Attributable

  • All Known Implementing Classes:
    AttributedInputStream, RereadableContent.RrcInputStream

    public interface Attributable
    This interface allows arbitrary objects to have additional attributes. This is similar to UserAttributeContainer but allows for arbitrary values not just strings. Obviously, this interface is not directly for serialisable objects since the stored objects need not be serialisable.
    See Also:
    Map
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      Object computeIfAbsent​(String name, Function<? super String,​Object> compFunc)
      Computes the value of the attribute with the designated name if the attribute is not present yet and returns the value (or the current value if already present and not computed).
      boolean contains​(String name)
      Gets whether this Attributable contains an attribute value for the designated attribute name.
      boolean containsType​(String name, Class<?> valueType)
      Gets whether this Attributable contains an attribute value for the designated attribute name of the designated type.
      Object get​(String name)
      Gets the value of the attribute with the designated name or null if the attribute is not present or has a null value.
      Object putIfAbsent​(String name, Object value)
      Puts an attribute with the designated name and value if the attribute is not present yet and returns null or the existing current value.
      Object remove​(String name)
      Removes the attribute with the designated name and returns its current (previous) value.
      Object replace​(String name, Object newValue)
      Replaces the value of the attribute with the designated name if it has a value and returns its previous value.
      boolean replace​(String name, Object oldValue, Object newValue)
      Replaces the value of the attribute with the designated name if it has the designated value.
    • Method Detail

      • contains

        boolean contains​(String name)
        Gets whether this Attributable contains an attribute value for the designated attribute name.
        Parameters:
        name - The name of the attribute for which an attribute value exists or not.
        Returns:
        Whether this Attributable contains an attribute value for the designated attribute name.
      • containsType

        boolean containsType​(String name,
                             Class<?> valueType)
        Gets whether this Attributable contains an attribute value for the designated attribute name of the designated type.
        Parameters:
        name - The name of the attribute for which an attribute value exists or not.
        valueType - The type of the value of the attribute of the designated name.
        Returns:
        Whether this Attributable contains an attribute value for the designated attribute name of the designate type.
      • get

        Object get​(String name)
        Gets the value of the attribute with the designated name or null if the attribute is not present or has a null value.
        Parameters:
        name - The name of the attribute for which to retrieve the value.
        Returns:
        The value of the attribute with the designated name or null if the attribute is not present or has a null value.
      • putIfAbsent

        Object putIfAbsent​(String name,
                           Object value)
        Puts an attribute with the designated name and value if the attribute is not present yet and returns null or the existing current value.
        Parameters:
        name - The name of the attribute which make available.
        value - The value of the attribute which to make available.
        Returns:
        The previous value (always null) or the current value (in case putting is refused since the attribute is already present).
      • computeIfAbsent

        Object computeIfAbsent​(String name,
                               Function<? super String,​Object> compFunc)
        Computes the value of the attribute with the designated name if the attribute is not present yet and returns the value (or the current value if already present and not computed).
        Parameters:
        name - The name of the attribute which make available.
        compFunc - The function computing the attribute value which to make available.
        Returns:
        The previous value if already present (and therefore not computed) or the computed value.
      • remove

        Object remove​(String name)
        Removes the attribute with the designated name and returns its current (previous) value.
        Parameters:
        name - The name of the attribute which to remove.
        Returns:
        The value of the removed attribute.
      • replace

        Object replace​(String name,
                       Object newValue)
        Replaces the value of the attribute with the designated name if it has a value and returns its previous value. If the attribute does not have a value yet, it will not be added and null will be returned. Note that null will also be returned when replacing the explicit attribute value null.
        Parameters:
        name - The name of the attribute which to replace.
        newValue - The value of the attribute with which to replace the existing value.
        Returns:
        The replaced value of the attribute or null in case of an unknown attribute (and no replacement).
      • replace

        boolean replace​(String name,
                        Object oldValue,
                        Object newValue)
        Replaces the value of the attribute with the designated name if it has the designated value. If the attribute does not have a value yet, it will not be added and false will be returned.
        Parameters:
        name - The name of the attribute which to replace.
        oldValue - The old value of the attribute which to replace.
        newValue - The value of the attribute with which to replace the old value.
        Returns:
        Whether the attribute value has been replaced.