Class Attributes


  • public final class Attributes
    extends Object
    This class contains various methods for manipulating Attributes as well as static factory methods for facilitating common Attribute construction use-cases.

    Of particular interest are the following three factory methods:

     empty(String);
    
     create(String, String);
    
     create(String, String, String...);
     
    These are provided in order to facilitate construction of empty, single-valued, and multi-valued attributes respectively, for example, in unit tests. The last factory method is not designed for performance critical functionality and, instead, an AttributeBuilder should be used in order to incrementally construct multi-valued attributes.
    • Constructor Detail

      • Attributes

        public Attributes()
    • Method Detail

      • create

        public static Attribute create​(AttributeType attributeType,
                                       ByteString value)
        Creates a new single-valued attribute with the specified attribute type and value.
        Parameters:
        attributeType - The attribute type to use.
        value - The attribute value.
        Returns:
        A new attribute with the attribute type and value.
      • createAsList

        public static List<Attribute> createAsList​(AttributeType attributeType,
                                                   ByteString value)
        Creates a new List with a single-valued attribute with the specified attribute type and value.
        Parameters:
        attributeType - The attribute type to use.
        value - The attribute value.
        Returns:
        A new List with a single-valued attribute with the attribute type and value.
      • create

        public static Attribute create​(AttributeType attributeType,
                                       String valueString)
        Creates a new single-valued attribute with the specified name and value.
        Parameters:
        attributeType - The attribute type to use.
        valueString - The String representation of the attribute value.
        Returns:
        A new attribute with the specified name and value.
      • createAsList

        public static List<Attribute> createAsList​(AttributeType attributeType,
                                                   String valueString)
        Creates a new List with a single-valued attribute with the specified name and value.
        Parameters:
        attributeType - The attribute type to use.
        valueString - The String representation of the attribute value.
        Returns:
        A new List with a attribute with the specified name and value.
      • create

        public static Attribute create​(AttributeType attributeType,
                                       String name,
                                       ByteString value)
        Creates a new single-valued attribute with the specified attribute type and value.
        Parameters:
        attributeType - The attribute type to use.
        name - The user-provided name for this attribute.
        value - The attribute value.
        Returns:
        A new attribute with the attribute type and value.
      • create

        public static Attribute create​(AttributeType attributeType,
                                       String name,
                                       String valueString)
        Creates a new single-valued attribute with the attribute type and value.
        Parameters:
        attributeType - The attribute type to use.
        name - The user-provided name for this attribute.
        valueString - The String representation of the attribute value.
        Returns:
        A new attribute with the attribute type and value.
      • createAsList

        public static List<Attribute> createAsList​(AttributeType attributeType,
                                                   String name,
                                                   String valueString)
        Creates a new List with a single-valued attribute with the attribute type and value.
        Parameters:
        attributeType - The attribute type to use.
        name - The user-provided name for this attribute.
        valueString - The String representation of the attribute value.
        Returns:
        A new List with a single-valued attribute with the attribute type and value.
      • create

        public static Attribute create​(String attributeName,
                                       String valueString)
        Creates a new single-valued attribute with the specified attribute name and attribute value.

        If the attribute name cannot be found in the schema, a new attribute type is created using the default attribute syntax.

        Parameters:
        attributeName - The name or OID of the attribute type for this attribute (can be mixed case).
        valueString - The String representation of the attribute value.
        Returns:
        A new attribute with the specified name and value.
      • create

        public static Attribute create​(String attributeName,
                                       String... valueStrings)
        Creates a new multi-valued attribute with the specified attribute name and attribute values.

        If the attribute name cannot be found in the schema, a new attribute type is created using the default attribute syntax.

        NOTE: this method is provided as a convenience and should typically be reserved for use in unit tests and places where performance is not an issue. In particular, this method will construct a temporary array containing the attribute's values. For performance critical purposes, incrementally construct an attribute using an AttributeBuilder.

        Parameters:
        attributeName - The name or OID of the attribute type for this attribute (can be mixed case).
        valueStrings - The string representation of the attribute values.
        Returns:
        A new attribute with the specified name and values.
      • empty

        public static Attribute empty​(Attribute attribute)
        Creates a new attribute which has the same attribute type and attribute options as the provided attribute but no attribute values.
        Parameters:
        attribute - The attribute to be copied.
        Returns:
        A new attribute which has the same attribute type and attribute options as the provided attribute but no attribute values.
      • empty

        public static Attribute empty​(AttributeType attributeType)
        Creates a new attribute with the provided attribute type and no values.
        Parameters:
        attributeType - The attribute type to use.
        Returns:
        A new attribute with the provided attribute type and no values.
      • empty

        public static Attribute empty​(AttributeType attributeType,
                                      String name)
        Creates a new attribute with the provided attribute type and no values.
        Parameters:
        attributeType - The attribute type to use.
        name - The user-provided name for this attribute.
        Returns:
        A new attribute with the provided attribute type and no values.
      • empty

        public static Attribute empty​(String attributeName)
        Creates a new attribute with the specified attribute name and no attribute values.

        If the attribute name cannot be found in the schema, a new attribute type is created using the default attribute syntax.

        Parameters:
        attributeName - The name or OID of the attribute type for this attribute (can be mixed case).
        Returns:
        A new attribute with the specified name and no values.
      • merge

        public static Attribute merge​(Attribute a1,
                                      Attribute a2)
        Creates a new attribute containing all the values from the two provided attributes. The returned attribute will use the name and options taken from the first attribute.

        This method is logically equivalent to:

         merge(a1, a2, null);
         
        Parameters:
        a1 - The first attribute.
        a2 - The second attribute.
        Returns:
        A new attribute containing all the values from the two provided attributes.
      • merge

        public static Attribute merge​(Attribute a1,
                                      Attribute a2,
                                      Collection<ByteString> duplicateValues)
        Creates a new attribute containing all the values from the two provided attributes and put any duplicate values into the provided collection. The returned attribute will use the name and options taken from the first attribute.
        Parameters:
        a1 - The first attribute.
        a2 - The second attribute.
        duplicateValues - A collection which will be used to store any duplicate values, or null if duplicate values should not be stored.
        Returns:
        A new attribute containing all the values from the two provided attributes.
      • subtract

        public static Attribute subtract​(Attribute a1,
                                         Attribute a2)
        Creates a new attribute containing the values from the first attribute which are not in the second attribute. The returned attribute will use the name and options taken from the first attribute.

        This method is logically equivalent to:

         subtract(a1, a2, null);
         
        Parameters:
        a1 - The first attribute.
        a2 - The second attribute.
        Returns:
        A new attribute containing the values from the first attribute which are not in the second attribute.
      • subtract

        public static Attribute subtract​(Attribute a1,
                                         Attribute a2,
                                         Collection<ByteString> missingValues)
        Creates a new attribute containing the values from the first attribute which are not in the second attribute. Any values which were present in the second attribute but which were not present in the first attribute will be put into the provided collection. The returned attribute will use the name and options taken from the first attribute.
        Parameters:
        a1 - The first attribute.
        a2 - The second attribute.
        missingValues - A collection which will be used to store any missing values, or null if missing values should not be stored.
        Returns:
        A new attribute containing the values from the first attribute which are not in the second attribute.