Class LinkedAttribute

  • All Implemented Interfaces:
    Iterable<ByteString>, Collection<ByteString>, Set<ByteString>, Attribute

    public final class LinkedAttribute
    extends AbstractAttribute
    An implementation of the Attribute interface with predictable iteration order.

    Internally, attribute values are stored in a linked list and it's this list which defines the iteration ordering, which is the order in which elements were inserted into the set (insertion-order). This ordering is particularly useful in LDAP where clients generally appreciate having things returned in the same order they were presented.

    All operations are supported by this implementation.

    • Constructor Detail

      • LinkedAttribute

        public LinkedAttribute​(Attribute attribute)
        Creates a new attribute having the same attribute description and attribute values as attribute.
        Parameters:
        attribute - The attribute to be copied.
        Throws:
        NullPointerException - If attribute was null.
      • LinkedAttribute

        public LinkedAttribute​(AttributeDescription attributeDescription)
        Creates a new attribute having the specified attribute description and no attribute values.
        Parameters:
        attributeDescription - The attribute description.
        Throws:
        NullPointerException - If attributeDescription was null.
      • LinkedAttribute

        public LinkedAttribute​(AttributeDescription attributeDescription,
                               Object value)
        Creates a new attribute having the specified attribute description and single attribute value.

        If value is not an instance of ByteString then it will be converted using the ByteString.valueOfObject(Object) method.

        Parameters:
        attributeDescription - The attribute description.
        value - The single attribute value.
        Throws:
        NullPointerException - If attributeDescription or value was null .
      • LinkedAttribute

        public LinkedAttribute​(AttributeDescription attributeDescription,
                               Object... values)
        Creates a new attribute having the specified attribute description and attribute values.

        Any attribute values which are not instances of ByteString will be converted using the ByteString.valueOfObject(Object) method.

        Parameters:
        attributeDescription - The attribute description.
        values - The attribute values.
        Throws:
        NullPointerException - If attributeDescription or values was null.
      • LinkedAttribute

        public LinkedAttribute​(AttributeDescription attributeDescription,
                               Collection<?> values)
        Creates a new attribute having the specified attribute description and attribute values.

        Any attribute values which are not instances of ByteString will be converted using the ByteString.valueOfObject(Object) method.

        Parameters:
        attributeDescription - The attribute description.
        values - The attribute values.
        Throws:
        NullPointerException - If attributeDescription or values was null.
      • LinkedAttribute

        public LinkedAttribute​(String attributeDescription)
        Creates a new attribute having the specified attribute description and no attribute values. The attribute description will be decoded using the default schema.
        Parameters:
        attributeDescription - The attribute description.
        Throws:
        LocalizedIllegalArgumentException - If attributeDescription could not be decoded using the default schema.
        NullPointerException - If attributeDescription was null.
      • LinkedAttribute

        public LinkedAttribute​(String attributeDescription,
                               Collection<?> values)
        Creates a new attribute having the specified attribute description and attribute values. The attribute description will be decoded using the default schema.

        Any attribute values which are not instances of ByteString will be converted using the ByteString.valueOfObject(Object) method.

        Parameters:
        attributeDescription - The attribute description.
        values - The attribute values.
        Throws:
        LocalizedIllegalArgumentException - If attributeDescription could not be decoded using the default schema.
        NullPointerException - If attributeDescription or values was null.
      • LinkedAttribute

        public LinkedAttribute​(String attributeDescription,
                               Object value)
        Creates a new attribute having the specified attribute description and single attribute value. The attribute description will be decoded using the default schema.

        If value is not an instance of ByteString then it will be converted using the ByteString.valueOfObject(Object) method.

        Parameters:
        attributeDescription - The attribute description.
        value - The single attribute value.
        Throws:
        LocalizedIllegalArgumentException - If attributeDescription could not be decoded using the default schema.
        NullPointerException - If attributeDescription or value was null .
      • LinkedAttribute

        public LinkedAttribute​(String attributeDescription,
                               Object... values)
        Creates a new attribute having the specified attribute description and attribute values. The attribute description will be decoded using the default schema.

        Any attribute values which are not instances of ByteString will be converted using the ByteString.valueOfObject(Object) method.

        Parameters:
        attributeDescription - The attribute description.
        values - The attribute values.
        Throws:
        LocalizedIllegalArgumentException - If attributeDescription could not be decoded using the default schema.
        NullPointerException - If attributeDescription or values was null.
    • Method Detail

      • newPreSizedLinkedAttribute

        public static LinkedAttribute newPreSizedLinkedAttribute​(AttributeDescription attributeDescription,
                                                                 int expectedValues)
        Creates a new attribute having the specified attribute description and expected number of values.
        Parameters:
        attributeDescription - The attribute description.
        expectedValues - The expected number of attribute values.
        Returns:
        Returns a pre-sized attribute.
        Throws:
        NullPointerException - If attributeDescription was null.
      • add

        public boolean add​(ByteString value)
        Description copied from interface: Attribute
        Adds value to this attribute if it is not already present (optional operation). If this attribute already contains value, the call leaves the attribute unchanged and returns false.
        Specified by:
        add in interface Attribute
        Specified by:
        add in interface Collection<ByteString>
        Specified by:
        add in interface Set<ByteString>
        Overrides:
        add in class AbstractCollection<ByteString>
        Parameters:
        value - The attribute value to be added to this attribute.
        Returns:
        true if this attribute changed as a result of this call.
      • forEachNormalizedValue

        public void forEachNormalizedValue​(BiConsumer<? super ByteString,​? super ByteString> action)
        Description copied from interface: Attribute
        Performs the provided action for each value and its associated normalized value in this attribute.
        Specified by:
        forEachNormalizedValue in interface Attribute
        Overrides:
        forEachNormalizedValue in class AbstractAttribute
        Parameters:
        action - The action to perform which will be passed the normalized value as the first parameter and the user provided value as the second parameter.
      • getAttributeDescription

        public AttributeDescription getAttributeDescription()
        Description copied from interface: Attribute
        Returns the attribute description of this attribute, which includes its attribute type and any options.
        Returns:
        The attribute description.
      • isVirtual

        public boolean isVirtual()
        Description copied from interface: Attribute
        Indicates whether this is a virtual attribute (dynamically computed) rather than a real attribute (persisted).
        Returns:
        true if this is a virtual attribute.
      • matchesAnyNormalizedValue

        public boolean matchesAnyNormalizedValue​(Map<ByteString,​ByteString> normalizedValues)
        Description copied from interface: Attribute
        Returns true if any values in this attribute match at least one of the values in the provided map. Returns false if this attribute is empty or if the provided map is empty. The map elements are mappings from normalized values to their corresponding values, where the normalized values must have been normalized according to this attribute's equality matching rule.

        NOTE: this method returns true if the intersection of the normalized values in this attribute and the normalized values of the provided map is not empty.

        Specified by:
        matchesAnyNormalizedValue in interface Attribute
        Overrides:
        matchesAnyNormalizedValue in class AbstractAttribute
        Parameters:
        normalizedValues - The map whose elements are mappings from normalized values to their corresponding values.
        Returns:
        true if any values in this attribute are contained in the provided map.
      • matchesAnyNormalizedValue

        public boolean matchesAnyNormalizedValue​(Predicate<? super ByteString> predicate)
        Description copied from interface: Attribute
        Returns true if any values in this attribute match the provided predicate. Returns false if this attribute is empty.
        Specified by:
        matchesAnyNormalizedValue in interface Attribute
        Overrides:
        matchesAnyNormalizedValue in class AbstractAttribute
        Parameters:
        predicate - The predicate which will be passed the normalized value as the first parameter and the user provided value as the second parameter.
        Returns:
        true if any values in this attribute match the provided predicate.
      • remove

        public boolean remove​(Object value)
        Description copied from interface: Attribute
        Removes value from this attribute if it is present (optional operation). If this attribute does not contain value, the call leaves the attribute unchanged and returns false.

        If value is not an instance of ByteString then it will be converted using the ByteString.valueOfObject(Object) method.

        Specified by:
        remove in interface Attribute
        Specified by:
        remove in interface Collection<ByteString>
        Specified by:
        remove in interface Set<ByteString>
        Overrides:
        remove in class AbstractCollection<ByteString>
        Parameters:
        value - The attribute value to be removed from this attribute.
        Returns:
        true if this attribute changed as a result of this call.
      • retainAll

        public <T> boolean retainAll​(Collection<T> values,
                                     Collection<? super T> missingValues)
        Description copied from interface: Attribute
        Retains only the attribute values in this attribute which are contained in values (optional operation). Any attribute values which are not already present will be added to missingValues if specified.

        Any attribute values which are not instances of ByteString will be converted using the ByteString.valueOfObject(Object) method.

        Specified by:
        retainAll in interface Attribute
        Overrides:
        retainAll in class AbstractAttribute
        Type Parameters:
        T - The type of the attribute value objects being retained.
        Parameters:
        values - The attribute values to be retained in this attribute.
        missingValues - A collection into which missing values will be added, or null if missing values should not be saved.
        Returns:
        true if this attribute changed as a result of this call.