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 Details

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

    • 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.
    • clear

      public void clear()
      Description copied from interface: Attribute
      Removes all of the attribute values from this attribute (optional operation). This attribute will be empty after this call returns.
      Specified by:
      clear in interface Attribute
      Specified by:
      clear in interface Collection<ByteString>
      Specified by:
      clear in interface Set<ByteString>
      Overrides:
      clear in class AbstractCollection<ByteString>
    • contains

      public boolean contains(Object value)
      Description copied from interface: Attribute
      Returns true if this attribute contains value.

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

      Specified by:
      contains in interface Attribute
      Specified by:
      contains in interface Collection<ByteString>
      Specified by:
      contains in interface Set<ByteString>
      Overrides:
      contains in class AbstractAttribute
      Parameters:
      value - The attribute value whose presence in this attribute is to be tested.
      Returns:
      true if this attribute contains value, or false if not.
    • containsAll

      public boolean containsAll(Collection<?> values)
      Description copied from interface: Attribute
      Returns true if this attribute contains all of the attribute values contained in values.

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

      Specified by:
      containsAll in interface Attribute
      Specified by:
      containsAll in interface Collection<ByteString>
      Specified by:
      containsAll in interface Set<ByteString>
      Overrides:
      containsAll in class AbstractAttribute
      Parameters:
      values - The attribute values whose presence in this attribute is to be tested.
      Returns:
      true if this attribute contains all of the attribute values contained in values, or false if not.
    • firstValue

      public ByteString firstValue()
      Description copied from interface: Attribute
      Returns the first attribute value in this attribute.
      Specified by:
      firstValue in interface Attribute
      Overrides:
      firstValue in class AbstractAttribute
      Returns:
      The first attribute value in this attribute.
    • 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.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Attribute
      Returns true if this attribute contains no attribute values.
      Specified by:
      isEmpty in interface Attribute
      Specified by:
      isEmpty in interface Collection<ByteString>
      Specified by:
      isEmpty in interface Set<ByteString>
      Overrides:
      isEmpty in class AbstractAttribute
      Returns:
      true if this attribute contains no attribute values.
    • iterator

      public Iterator<ByteString> iterator()
      Description copied from interface: Attribute
      Returns an iterator over the attribute values in this attribute. The attribute values are returned in no particular order, unless the implementation of this attribute provides such a guarantee.
      Specified by:
      iterator in interface Attribute
      Specified by:
      iterator in interface Collection<ByteString>
      Specified by:
      iterator in interface Iterable<ByteString>
      Specified by:
      iterator in interface Set<ByteString>
      Specified by:
      iterator in class AbstractAttribute
      Returns:
      An iterator over the attribute values in this 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.
    • size

      public int size()
      Description copied from interface: Attribute
      Returns the number of attribute values in this attribute.
      Specified by:
      size in interface Attribute
      Specified by:
      size in interface Collection<ByteString>
      Specified by:
      size in interface Set<ByteString>
      Overrides:
      size in class AbstractAttribute
      Returns:
      The number of attribute values in this attribute.