Class Attribute

  • All Implemented Interfaces:
    java.io.Serializable

    @NotMutable
    @ThreadSafety(level=COMPLETELY_THREADSAFE)
    public final class Attribute
    extends java.lang.Object
    implements java.io.Serializable
    This class provides a data structure for holding information about an LDAP attribute, which includes an attribute name (which may include a set of attribute options) and zero or more values. Attribute objects are immutable and cannot be altered. However, if an attribute is included in an Entry object, then it is possible to add and remove attribute values from the entry (which will actually create new Attribute object instances), although this is not allowed for instances of ReadOnlyEntry and its subclasses.

    This class uses the term "attribute name" as an equivalent of what the LDAP specification refers to as an "attribute description". An attribute description consists of an attribute type name or object identifier (which this class refers to as the "base name") followed by zero or more attribute options, each of which should be prefixed by a semicolon. Attribute options may be used to provide additional metadata for the attribute and/or its values, or to indicate special handling for the values. For example, RFC 3866 describes the use of attribute options to indicate that a value may be associated with a particular language (e.g., "cn;lang-en-US" indicates that the values of that cn attribute should be treated as U.S. English values), and RFC 4522 describes a binary encoding option that indicates that the server should only attempt to interact with the values as binary data (e.g., "userCertificate;binary") and should not treat them as strings. An attribute name (which is technically referred to as an "attribute description" in the protocol specification) may have zero, one, or multiple attribute options. If there are any attribute options, then a semicolon is used to separate the first option from the base attribute name, and to separate each subsequent attribute option from the previous option.

    Attribute values can be treated as either strings or byte arrays. In LDAP, they are always transferred using a binary encoding, but applications frequently treat them as strings and it is often more convenient to do so. However, for some kinds of data (e.g., certificates, images, audio clips, and other "blobs") it may be desirable to only treat them as binary data and only interact with the values as byte arrays. If you do intend to interact with string values as byte arrays, then it is important to ensure that you use a UTF-8 representation for those values unless you are confident that the directory server will not attempt to treat the value as a string.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      Attribute​(java.lang.String name)
      Creates a new LDAP attribute with the specified name and no values.
      Attribute​(java.lang.String name, byte[] value)
      Creates a new LDAP attribute with the specified name and value.
      Attribute​(java.lang.String name, byte[]... values)
      Creates a new LDAP attribute with the specified name and set of values.
      Attribute​(java.lang.String name, ASN1OctetString... values)
      Creates a new LDAP attribute with the specified name and set of values.
      Attribute​(java.lang.String name, MatchingRule matchingRule)
      Creates a new LDAP attribute with the specified name and no values.
      Attribute​(java.lang.String name, MatchingRule matchingRule, byte[] value)
      Creates a new LDAP attribute with the specified name and value.
      Attribute​(java.lang.String name, MatchingRule matchingRule, byte[]... values)
      Creates a new LDAP attribute with the specified name and set of values.
      Attribute​(java.lang.String name, MatchingRule matchingRule, ASN1OctetString[] values)
      Creates a new LDAP attribute with the specified name and set of values.
      Attribute​(java.lang.String name, MatchingRule matchingRule, java.lang.String value)
      Creates a new LDAP attribute with the specified name and value.
      Attribute​(java.lang.String name, MatchingRule matchingRule, java.lang.String... values)
      Creates a new LDAP attribute with the specified name and set of values.
      Attribute​(java.lang.String name, MatchingRule matchingRule, java.util.Collection<java.lang.String> values)
      Creates a new LDAP attribute with the specified name and set of values.
      Attribute​(java.lang.String name, Schema schema, byte[]... values)
      Creates a new LDAP attribute with the specified name and set of values.
      Attribute​(java.lang.String name, Schema schema, ASN1OctetString[] values)
      Creates a new LDAP attribute with the specified name and set of values.
      Attribute​(java.lang.String name, Schema schema, java.lang.String... values)
      Creates a new LDAP attribute with the specified name and set of values.
      Attribute​(java.lang.String name, Schema schema, java.util.Collection<java.lang.String> values)
      Creates a new LDAP attribute with the specified name and set of values.
      Attribute​(java.lang.String name, java.lang.String value)
      Creates a new LDAP attribute with the specified name and value.
      Attribute​(java.lang.String name, java.lang.String... values)
      Creates a new LDAP attribute with the specified name and set of values.
      Attribute​(java.lang.String name, java.util.Collection<java.lang.String> values)
      Creates a new LDAP attribute with the specified name and set of values.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Attribute decode​(ASN1Sequence encodedAttribute)
      Decodes the provided ASN.1 sequence as an LDAP attribute.
      ASN1Sequence encode()
      Encodes this attribute into a form suitable for use in the LDAP protocol.
      boolean equals​(java.lang.Object o)
      Indicates whether the provided object is equal to this LDAP attribute.
      java.lang.String getBaseName()
      Retrieves the base name for this attribute, which is the name or OID of the attribute type, without any attribute options.
      static java.lang.String getBaseName​(java.lang.String name)
      Retrieves the base name for an attribute with the given name, which will be the provided name without any attribute options.
      MatchingRule getMatchingRule()
      Retrieves the matching rule instance used by this attribute.
      java.lang.String getName()
      Retrieves the name for this attribute (i.e., the attribute description), which may include zero or more attribute options.
      java.util.Set<java.lang.String> getOptions()
      Retrieves the set of options for this attribute.
      static java.util.Set<java.lang.String> getOptions​(java.lang.String name)
      Retrieves the set of options for the provided attribute name.
      ASN1OctetString[] getRawValues()
      Retrieves the set of values for this attribute as an array of ASN.1 octet strings.
      java.lang.String getValue()
      Retrieves the value for this attribute as a string.
      java.lang.Boolean getValueAsBoolean()
      Retrieves the value for this attribute as a Boolean.
      java.util.Date getValueAsDate()
      Retrieves the value for this attribute as a Date, formatted using the generalized time syntax.
      DN getValueAsDN()
      Retrieves the value for this attribute as a DN.
      java.lang.Integer getValueAsInteger()
      Retrieves the value for this attribute as an Integer.
      java.lang.Long getValueAsLong()
      Retrieves the value for this attribute as a Long.
      byte[] getValueByteArray()
      Retrieves the value for this attribute as a byte array.
      byte[][] getValueByteArrays()
      Retrieves the set of values for this attribute as byte arrays.
      java.lang.String[] getValues()
      Retrieves the set of values for this attribute as strings.
      int hashCode()
      Generates a hash code for this LDAP attribute.
      boolean hasOption​(java.lang.String option)
      Indicates whether this attribute has the specified attribute option.
      static boolean hasOption​(java.lang.String name, java.lang.String option)
      Indicates whether the provided attribute name has the specified attribute option.
      boolean hasOptions()
      Indicates whether this attribute has any attribute options.
      static boolean hasOptions​(java.lang.String name)
      Indicates whether the provided attribute name contains any options.
      boolean hasValue()
      Indicates whether this attribute contains at least one value.
      boolean hasValue​(byte[] value)
      Indicates whether this attribute contains the specified value.
      boolean hasValue​(byte[] value, MatchingRule matchingRule)
      Indicates whether this attribute contains the specified value.
      boolean hasValue​(java.lang.String value)
      Indicates whether this attribute contains the specified value.
      boolean hasValue​(java.lang.String value, MatchingRule matchingRule)
      Indicates whether this attribute contains the specified value.
      static Attribute mergeAttributes​(Attribute attr1, Attribute attr2)
      Creates a new attribute containing the merged values of the provided attributes.
      static Attribute mergeAttributes​(Attribute attr1, Attribute attr2, MatchingRule matchingRule)
      Creates a new attribute containing the merged values of the provided attributes.
      boolean nameIsValid()
      Indicates whether the name of this attribute is valid as per RFC 4512.
      static boolean nameIsValid​(java.lang.String s)
      Indicates whether the provided string represents a valid attribute name as per RFC 4512.
      static boolean nameIsValid​(java.lang.String s, boolean allowOptions)
      Indicates whether the provided string represents a valid attribute name as per RFC 4512.
      boolean needsBase64Encoding()
      Indicates whether any of the values of this attribute need to be base64-encoded when represented as LDIF.
      static boolean needsBase64Encoding​(byte[] v)
      Indicates whether the provided value needs to be base64-encoded when represented as LDIF.
      static boolean needsBase64Encoding​(java.lang.String v)
      Indicates whether the provided value needs to be base64-encoded when represented as LDIF.
      static Attribute readFrom​(ASN1StreamReader reader)
      Reads and decodes an attribute from the provided ASN.1 stream reader.
      static Attribute readFrom​(ASN1StreamReader reader, Schema schema)
      Reads and decodes an attribute from the provided ASN.1 stream reader.
      static Attribute removeValues​(Attribute attr1, Attribute attr2)
      Creates a new attribute containing all of the values of the first attribute that are not contained in the second attribute.
      static Attribute removeValues​(Attribute attr1, Attribute attr2, MatchingRule matchingRule)
      Creates a new attribute containing all of the values of the first attribute that are not contained in the second attribute.
      int size()
      Retrieves the number of values for this attribute.
      java.lang.String toString()
      Retrieves a string representation of this LDAP attribute.
      void toString​(java.lang.StringBuilder buffer)
      Appends a string representation of this LDAP attribute to the provided buffer.
      void writeTo​(ASN1Buffer buffer)
      Writes an ASN.1-encoded representation of this attribute to the provided ASN.1 buffer.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name)
        Creates a new LDAP attribute with the specified name and no values.
        Parameters:
        name - The name for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @NotNull
                         java.lang.String value)
        Creates a new LDAP attribute with the specified name and value.
        Parameters:
        name - The name for this attribute. It must not be null.
        value - The value for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @NotNull
                         byte[] value)
        Creates a new LDAP attribute with the specified name and value.
        Parameters:
        name - The name for this attribute. It must not be null.
        value - The value for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @NotNull
                         java.lang.String... values)
        Creates a new LDAP attribute with the specified name and set of values.
        Parameters:
        name - The name for this attribute. It must not be null.
        values - The set of values for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @NotNull
                         byte[]... values)
        Creates a new LDAP attribute with the specified name and set of values.
        Parameters:
        name - The name for this attribute. It must not be null.
        values - The set of values for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @NotNull
                         ASN1OctetString... values)
        Creates a new LDAP attribute with the specified name and set of values.
        Parameters:
        name - The name for this attribute. It must not be null.
        values - The set of raw values for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @NotNull
                         java.util.Collection<java.lang.String> values)
        Creates a new LDAP attribute with the specified name and set of values.
        Parameters:
        name - The name for this attribute. It must not be null.
        values - The set of values for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @NotNull
                         MatchingRule matchingRule)
        Creates a new LDAP attribute with the specified name and no values.
        Parameters:
        name - The name for this attribute. It must not be null.
        matchingRule - The matching rule to use when comparing values. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @NotNull
                         MatchingRule matchingRule,
                         @NotNull
                         java.lang.String value)
        Creates a new LDAP attribute with the specified name and value.
        Parameters:
        name - The name for this attribute. It must not be null.
        matchingRule - The matching rule to use when comparing values. It must not be null.
        value - The value for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @NotNull
                         MatchingRule matchingRule,
                         @NotNull
                         byte[] value)
        Creates a new LDAP attribute with the specified name and value.
        Parameters:
        name - The name for this attribute. It must not be null.
        matchingRule - The matching rule to use when comparing values. It must not be null.
        value - The value for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @NotNull
                         MatchingRule matchingRule,
                         @NotNull
                         java.lang.String... values)
        Creates a new LDAP attribute with the specified name and set of values.
        Parameters:
        name - The name for this attribute. It must not be null.
        matchingRule - The matching rule to use when comparing values. It must not be null.
        values - The set of values for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @NotNull
                         MatchingRule matchingRule,
                         @NotNull
                         byte[]... values)
        Creates a new LDAP attribute with the specified name and set of values.
        Parameters:
        name - The name for this attribute. It must not be null.
        matchingRule - The matching rule to use when comparing values. It must not be null.
        values - The set of values for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @NotNull
                         MatchingRule matchingRule,
                         @NotNull
                         java.util.Collection<java.lang.String> values)
        Creates a new LDAP attribute with the specified name and set of values.
        Parameters:
        name - The name for this attribute. It must not be null.
        matchingRule - The matching rule to use when comparing values. It must not be null.
        values - The set of values for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @NotNull
                         MatchingRule matchingRule,
                         @NotNull
                         ASN1OctetString[] values)
        Creates a new LDAP attribute with the specified name and set of values.
        Parameters:
        name - The name for this attribute.
        matchingRule - The matching rule for this attribute.
        values - The set of values for this attribute.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @Nullable
                         Schema schema,
                         @NotNull
                         java.lang.String... values)
        Creates a new LDAP attribute with the specified name and set of values.
        Parameters:
        name - The name for this attribute. It must not be null.
        schema - The schema to use to select the matching rule for this attribute. It may be null if the default matching rule should be used.
        values - The set of values for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @Nullable
                         Schema schema,
                         @NotNull
                         byte[]... values)
        Creates a new LDAP attribute with the specified name and set of values.
        Parameters:
        name - The name for this attribute. It must not be null.
        schema - The schema to use to select the matching rule for this attribute. It may be null if the default matching rule should be used.
        values - The set of values for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @Nullable
                         Schema schema,
                         @NotNull
                         java.util.Collection<java.lang.String> values)
        Creates a new LDAP attribute with the specified name and set of values.
        Parameters:
        name - The name for this attribute. It must not be null.
        schema - The schema to use to select the matching rule for this attribute. It may be null if the default matching rule should be used.
        values - The set of values for this attribute. It must not be null.
      • Attribute

        public Attribute​(@NotNull
                         java.lang.String name,
                         @Nullable
                         Schema schema,
                         @NotNull
                         ASN1OctetString[] values)
        Creates a new LDAP attribute with the specified name and set of values.
        Parameters:
        name - The name for this attribute. It must not be null.
        schema - The schema to use to select the matching rule for this attribute. It may be null if the default matching rule should be used.
        values - The set of values for this attribute. It must not be null.
    • Method Detail

      • mergeAttributes

        @NotNull
        public static Attribute mergeAttributes​(@NotNull
                                                Attribute attr1,
                                                @NotNull
                                                Attribute attr2)
        Creates a new attribute containing the merged values of the provided attributes. Any duplicate values will only be present once in the resulting attribute. The names of the provided attributes must be the same.
        Parameters:
        attr1 - The first attribute containing the values to merge. It must not be null.
        attr2 - The second attribute containing the values to merge. It must not be null.
        Returns:
        The new attribute containing the values of both of the provided attributes.
      • mergeAttributes

        @NotNull
        public static Attribute mergeAttributes​(@NotNull
                                                Attribute attr1,
                                                @NotNull
                                                Attribute attr2,
                                                @Nullable
                                                MatchingRule matchingRule)
        Creates a new attribute containing the merged values of the provided attributes. Any duplicate values will only be present once in the resulting attribute. The names of the provided attributes must be the same.
        Parameters:
        attr1 - The first attribute containing the values to merge. It must not be null.
        attr2 - The second attribute containing the values to merge. It must not be null.
        matchingRule - The matching rule to use to locate matching values. It may be null if the matching rule associated with the first attribute should be used.
        Returns:
        The new attribute containing the values of both of the provided attributes.
      • removeValues

        @NotNull
        public static Attribute removeValues​(@NotNull
                                             Attribute attr1,
                                             @NotNull
                                             Attribute attr2)
        Creates a new attribute containing all of the values of the first attribute that are not contained in the second attribute. Any values contained in the second attribute that are not contained in the first will be ignored. The names of the provided attributes must be the same.
        Parameters:
        attr1 - The attribute from which to remove the values. It must not be null.
        attr2 - The attribute containing the values to remove. It must not be null.
        Returns:
        A new attribute containing all of the values of the first attribute not contained in the second. It may contain zero values if all the values of the first attribute were also contained in the second.
      • removeValues

        @NotNull
        public static Attribute removeValues​(@NotNull
                                             Attribute attr1,
                                             @NotNull
                                             Attribute attr2,
                                             @Nullable
                                             MatchingRule matchingRule)
        Creates a new attribute containing all of the values of the first attribute that are not contained in the second attribute. Any values contained in the second attribute that are not contained in the first will be ignored. The names of the provided attributes must be the same.
        Parameters:
        attr1 - The attribute from which to remove the values. It must not be null.
        attr2 - The attribute containing the values to remove. It must not be null.
        matchingRule - The matching rule to use to locate matching values. It may be null if the matching rule associated with the first attribute should be used.
        Returns:
        A new attribute containing all of the values of the first attribute not contained in the second. It may contain zero values if all the values of the first attribute were also contained in the second.
      • getName

        @NotNull
        public java.lang.String getName()
        Retrieves the name for this attribute (i.e., the attribute description), which may include zero or more attribute options.
        Returns:
        The name for this attribute.
      • getBaseName

        @NotNull
        public java.lang.String getBaseName()
        Retrieves the base name for this attribute, which is the name or OID of the attribute type, without any attribute options. For an attribute without any options, the value returned by this method will be identical the value returned by the getName() method.
        Returns:
        The base name for this attribute.
      • getBaseName

        @NotNull
        public static java.lang.String getBaseName​(@NotNull
                                                   java.lang.String name)
        Retrieves the base name for an attribute with the given name, which will be the provided name without any attribute options. If the given name does not include any attribute options, then it will be returned unaltered. If it does contain one or more attribute options, then the name will be returned without those options.
        Parameters:
        name - The name to be processed.
        Returns:
        The base name determined from the provided attribute name.
      • nameIsValid

        public boolean nameIsValid()
        Indicates whether the name of this attribute is valid as per RFC 4512. The name will be considered valid only if it starts with an ASCII alphabetic character ('a' through 'z', or 'A' through 'Z'), and contains only ASCII alphabetic characters, ASCII numeric digits ('0' through '9'), and the ASCII hyphen character ('-'). It will also be allowed to include zero or more attribute options, in which the option must be separate from the base name by a semicolon and has the same naming constraints as the base name.
        Returns:
        true if this attribute has a valid name, or false if not.
      • nameIsValid

        public static boolean nameIsValid​(@NotNull
                                          java.lang.String s)
        Indicates whether the provided string represents a valid attribute name as per RFC 4512. It will be considered valid only if it starts with an ASCII alphabetic character ('a' through 'z', or 'A' through 'Z'), and contains only ASCII alphabetic characters, ASCII numeric digits ('0' through '9'), and the ASCII hyphen character ('-'). It will also be allowed to include zero or more attribute options, in which the option must be separate from the base name by a semicolon and has the same naming constraints as the base name.
        Parameters:
        s - The name for which to make the determination.
        Returns:
        true if this attribute has a valid name, or false if not.
      • nameIsValid

        public static boolean nameIsValid​(@NotNull
                                          java.lang.String s,
                                          boolean allowOptions)
        Indicates whether the provided string represents a valid attribute name as per RFC 4512. It will be considered valid only if it starts with an ASCII alphabetic character ('a' through 'z', or 'A' through 'Z'), and contains only ASCII alphabetic characters, ASCII numeric digits ('0' through '9'), and the ASCII hyphen character ('-'). It may optionally be allowed to include zero or more attribute options, in which the option must be separate from the base name by a semicolon and has the same naming constraints as the base name.
        Parameters:
        s - The name for which to make the determination.
        allowOptions - Indicates whether the provided name will be allowed to contain attribute options.
        Returns:
        true if this attribute has a valid name, or false if not.
      • hasOptions

        public boolean hasOptions()
        Indicates whether this attribute has any attribute options.
        Returns:
        true if this attribute has at least one attribute option, or false if not.
      • hasOptions

        public static boolean hasOptions​(@NotNull
                                         java.lang.String name)
        Indicates whether the provided attribute name contains any options.
        Parameters:
        name - The name for which to make the determination.
        Returns:
        true if the provided attribute name has at least one attribute option, or false if not.
      • hasOption

        public boolean hasOption​(@NotNull
                                 java.lang.String option)
        Indicates whether this attribute has the specified attribute option.
        Parameters:
        option - The attribute option for which to make the determination.
        Returns:
        true if this attribute has the specified attribute option, or false if not.
      • hasOption

        public static boolean hasOption​(@NotNull
                                        java.lang.String name,
                                        @NotNull
                                        java.lang.String option)
        Indicates whether the provided attribute name has the specified attribute option.
        Parameters:
        name - The name to be examined.
        option - The attribute option for which to make the determination.
        Returns:
        true if the provided attribute name has the specified attribute option, or false if not.
      • getOptions

        @NotNull
        public java.util.Set<java.lang.String> getOptions()
        Retrieves the set of options for this attribute.
        Returns:
        The set of options for this attribute, or an empty set if there are none.
      • getOptions

        @NotNull
        public static java.util.Set<java.lang.String> getOptions​(@NotNull
                                                                 java.lang.String name)
        Retrieves the set of options for the provided attribute name.
        Parameters:
        name - The name to be examined.
        Returns:
        The set of options for the provided attribute name, or an empty set if there are none.
      • getMatchingRule

        @NotNull
        public MatchingRule getMatchingRule()
        Retrieves the matching rule instance used by this attribute.
        Returns:
        The matching rule instance used by this attribute.
      • getValue

        @Nullable
        public java.lang.String getValue()
        Retrieves the value for this attribute as a string. If this attribute has multiple values, then the first value will be returned.
        Returns:
        The value for this attribute, or null if this attribute does not have any values.
      • getValueByteArray

        @Nullable
        public byte[] getValueByteArray()
        Retrieves the value for this attribute as a byte array. If this attribute has multiple values, then the first value will be returned. The returned array must not be altered by the caller.
        Returns:
        The value for this attribute, or null if this attribute does not have any values.
      • getValueAsBoolean

        @Nullable
        public java.lang.Boolean getValueAsBoolean()
        Retrieves the value for this attribute as a Boolean. If this attribute has multiple values, then the first value will be examined. Values of "true", "t", "yes", "y", "on", and "1" will be interpreted as TRUE. Values of "false", "f", "no", "n", "off", and "0" will be interpreted as FALSE.
        Returns:
        The Boolean value for this attribute, or null if this attribute does not have any values or the value cannot be parsed as a Boolean.
      • getValueAsDate

        @Nullable
        public java.util.Date getValueAsDate()
        Retrieves the value for this attribute as a Date, formatted using the generalized time syntax. If this attribute has multiple values, then the first value will be examined.
        Returns:
        The Date value for this attribute, or null if this attribute does not have any values or the value cannot be parsed as a Date.
      • getValueAsDN

        @Nullable
        public DN getValueAsDN()
        Retrieves the value for this attribute as a DN. If this attribute has multiple values, then the first value will be examined.
        Returns:
        The DN value for this attribute, or null if this attribute does not have any values or the value cannot be parsed as a DN.
      • getValueAsInteger

        @Nullable
        public java.lang.Integer getValueAsInteger()
        Retrieves the value for this attribute as an Integer. If this attribute has multiple values, then the first value will be examined.
        Returns:
        The Integer value for this attribute, or null if this attribute does not have any values or the value cannot be parsed as an Integer.
      • getValueAsLong

        @Nullable
        public java.lang.Long getValueAsLong()
        Retrieves the value for this attribute as a Long. If this attribute has multiple values, then the first value will be examined.
        Returns:
        The Long value for this attribute, or null if this attribute does not have any values or the value cannot be parsed as a Long.
      • getValues

        @NotNull
        public java.lang.String[] getValues()
        Retrieves the set of values for this attribute as strings. The returned array must not be altered by the caller.
        Returns:
        The set of values for this attribute, or an empty array if it does not have any values.
      • getValueByteArrays

        @NotNull
        public byte[][] getValueByteArrays()
        Retrieves the set of values for this attribute as byte arrays. The returned array must not be altered by the caller.
        Returns:
        The set of values for this attribute, or an empty array if it does not have any values.
      • getRawValues

        @NotNull
        public ASN1OctetString[] getRawValues()
        Retrieves the set of values for this attribute as an array of ASN.1 octet strings. The returned array must not be altered by the caller.
        Returns:
        The set of values for this attribute as an array of ASN.1 octet strings.
      • hasValue

        public boolean hasValue()
        Indicates whether this attribute contains at least one value.
        Returns:
        true if this attribute has at least one value, or false if not.
      • hasValue

        public boolean hasValue​(@NotNull
                                java.lang.String value)
        Indicates whether this attribute contains the specified value.
        Parameters:
        value - The value for which to make the determination. It must not be null.
        Returns:
        true if this attribute has the specified value, or false if not.
      • hasValue

        public boolean hasValue​(@NotNull
                                java.lang.String value,
                                @NotNull
                                MatchingRule matchingRule)
        Indicates whether this attribute contains the specified value.
        Parameters:
        value - The value for which to make the determination. It must not be null.
        matchingRule - The matching rule to use when making the determination. It must not be null.
        Returns:
        true if this attribute has the specified value, or false if not.
      • hasValue

        public boolean hasValue​(@NotNull
                                byte[] value)
        Indicates whether this attribute contains the specified value.
        Parameters:
        value - The value for which to make the determination. It must not be null.
        Returns:
        true if this attribute has the specified value, or false if not.
      • hasValue

        public boolean hasValue​(@NotNull
                                byte[] value,
                                @NotNull
                                MatchingRule matchingRule)
        Indicates whether this attribute contains the specified value.
        Parameters:
        value - The value for which to make the determination. It must not be null.
        matchingRule - The matching rule to use when making the determination. It must not be null.
        Returns:
        true if this attribute has the specified value, or false if not.
      • size

        public int size()
        Retrieves the number of values for this attribute.
        Returns:
        The number of values for this attribute.
      • writeTo

        public void writeTo​(@NotNull
                            ASN1Buffer buffer)
        Writes an ASN.1-encoded representation of this attribute to the provided ASN.1 buffer.
        Parameters:
        buffer - The ASN.1 buffer to which the encoded representation should be written.
      • encode

        @NotNull
        public ASN1Sequence encode()
        Encodes this attribute into a form suitable for use in the LDAP protocol. It will be encoded as a sequence containing the attribute name (as an octet string) and a set of values.
        Returns:
        An ASN.1 sequence containing the encoded attribute.
      • readFrom

        @NotNull
        public static Attribute readFrom​(@NotNull
                                         ASN1StreamReader reader)
                                  throws LDAPException
        Reads and decodes an attribute from the provided ASN.1 stream reader.
        Parameters:
        reader - The ASN.1 stream reader from which to read the attribute.
        Returns:
        The decoded attribute.
        Throws:
        LDAPException - If a problem occurs while trying to read or decode the attribute.
      • readFrom

        @NotNull
        public static Attribute readFrom​(@NotNull
                                         ASN1StreamReader reader,
                                         @Nullable
                                         Schema schema)
                                  throws LDAPException
        Reads and decodes an attribute from the provided ASN.1 stream reader.
        Parameters:
        reader - The ASN.1 stream reader from which to read the attribute.
        schema - The schema to use to select the appropriate matching rule for this attribute. It may be null if the default matching rule should be selected.
        Returns:
        The decoded attribute.
        Throws:
        LDAPException - If a problem occurs while trying to read or decode the attribute.
      • decode

        @NotNull
        public static Attribute decode​(@NotNull
                                       ASN1Sequence encodedAttribute)
                                throws LDAPException
        Decodes the provided ASN.1 sequence as an LDAP attribute.
        Parameters:
        encodedAttribute - The ASN.1 sequence to be decoded as an LDAP attribute. It must not be null.
        Returns:
        The decoded LDAP attribute.
        Throws:
        LDAPException - If a problem occurs while attempting to decode the provided ASN.1 sequence as an LDAP attribute.
      • needsBase64Encoding

        public boolean needsBase64Encoding()
        Indicates whether any of the values of this attribute need to be base64-encoded when represented as LDIF.
        Returns:
        true if any of the values of this attribute need to be base64-encoded when represented as LDIF, or false if not.
      • needsBase64Encoding

        public static boolean needsBase64Encoding​(@NotNull
                                                  java.lang.String v)
        Indicates whether the provided value needs to be base64-encoded when represented as LDIF.
        Parameters:
        v - The value for which to make the determination. It must not be null.
        Returns:
        true if the provided value needs to be base64-encoded when represented as LDIF, or false if not.
      • needsBase64Encoding

        public static boolean needsBase64Encoding​(@NotNull
                                                  byte[] v)
        Indicates whether the provided value needs to be base64-encoded when represented as LDIF.
        Parameters:
        v - The value for which to make the determination. It must not be null.
        Returns:
        true if the provided value needs to be base64-encoded when represented as LDIF, or false if not.
      • hashCode

        public int hashCode()
        Generates a hash code for this LDAP attribute. It will be the sum of the hash codes for the lowercase attribute name and the normalized values.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        The generated hash code for this LDAP attribute.
      • equals

        public boolean equals​(@Nullable
                              java.lang.Object o)
        Indicates whether the provided object is equal to this LDAP attribute. The object will be considered equal to this LDAP attribute only if it is an LDAP attribute with the same name and set of values.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - The object for which to make the determination.
        Returns:
        true if the provided object may be considered equal to this LDAP attribute, or false if not.
      • toString

        @NotNull
        public java.lang.String toString()
        Retrieves a string representation of this LDAP attribute.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of this LDAP attribute.
      • toString

        public void toString​(@NotNull
                             java.lang.StringBuilder buffer)
        Appends a string representation of this LDAP attribute to the provided buffer.
        Parameters:
        buffer - The buffer to which the string representation of this LDAP attribute should be appended.