Class Value

  • All Implemented Interfaces:
    Externalizable, Serializable, Cloneable, Comparable<Value>

    public class Value
    extends Object
    implements Cloneable, Externalizable, Comparable<Value>
    A Class for wrapping attribute values stored into an Entry Attribute, or a AVA. We keep the value as byte[] unless we need to convert them to a String (if we have a HR Value). The serialized Value will be stored as :
      +---------+
      | boolean | isHR flag
      +---------+
      | boolean | TRUE if the value is not null, FALSE otherwise
      +---------+
     [|   int   |]  If the previous flag is TRUE, the length of the value
     [+---------+]
     [| byte[]  |] The value itself
     [+---------+]
      | boolean | TRUE if we have a prepared String
      +---------+
     [| String  |] The prepared String if we have it
     [+---------+]
     
    Author:
    Apache Directory Project
    See Also:
    Serialized Form
    • Constructor Detail

      • Value

        public Value​(String upValue)
        Creates a Value with an initial user provided String value.
        Parameters:
        upValue - the value to wrap. It can be null
      • Value

        public Value​(byte[] value)
        Creates a Value with an initial user provided binary value.
        Parameters:
        value - the binary value to wrap which may be null, or a zero length byte array
    • Method Detail

      • createValue

        public static Value createValue​(AttributeType attributeType)
        Create a Value with an AttributeType. It will not contain anything and will only be used by the deserializer.
        Parameters:
        attributeType - The ATttributeType to use
        Returns:
        An instance of value.
      • clone

        public Value clone()
        Clone a Value
        Returns:
        A cloned value
      • isNull

        public boolean isNull()
        Check if the contained value is null or not
        Returns:
        true if the inner value is null.
      • isInstanceOf

        public boolean isInstanceOf​(AttributeType attributeType)
        Check if the value is stored into an instance of the given AttributeType, or one of its ascendant. For instance, if the Value is associated with a CommonName, checking for Name will match.
        Parameters:
        attributeType - The AttributeType we are looking at
        Returns:
        true if the value is associated with the given attributeType or one of its ascendant
      • getEscaped

        public String getEscaped()
        Returns:
        The value as an escaped String
      • getString

        public String getString()
        Get the User Provided value. If the value is Human Readable, it will return the stored String, otherwise it will returns a String based on the bytes - which may be invalid if the value is a pure binary -.
        Returns:
        The user provided value
      • getBytes

        public byte[] getBytes()
        Get the wrapped value as a byte[], if and only if the Value is binary, otherwise returns null.
        Returns:
        the wrapped value as a byte[]
      • isSchemaAware

        public boolean isSchemaAware()
        Tells if the value is schema aware or not.
        Returns:
        true if the value is sxhema aware
      • isHumanReadable

        public boolean isHumanReadable()
        Tells if the current value is Human Readable
        Returns:
        true if the value is a String, false otherwise
      • length

        public int length()
        Returns:
        The length of the interned value
      • serialize

        public int serialize​(byte[] buffer,
                             int pos)
        Serialize the Value into a buffer at the given position.
        Parameters:
        buffer - The buffer which will contain the serialized StringValue
        pos - The position in the buffer for the serialized value
        Returns:
        The new position in the buffer
      • compareTo

        public int compareTo​(String other)
        Compare the current value with a String.
        Parameters:
        other - the String we want to compare the current value with
        Returns:
        a positive value if the current value is above the provided String, a negative value if it's below, 0 if they are equal.
        Throws:
        IllegalStateException - on failures to extract the comparator, or the normalizers needed to perform the required comparisons based on the schema
      • compareTo

        public int compareTo​(byte[] other)
        Compare two values. We compare the stored bytes
        Parameters:
        other - the byte[] we want to compare the current value with
        Returns:
        a positive value if the current value is above the provided byte[], a negative value if it's below, 0 if they are equal.
        Throws:
        IllegalStateException - on failures to extract the comparator, or the normalizers needed to perform the required comparisons based on the schema
      • compareTo

        public int compareTo​(Value other)
        Compare two values. We either compare the stored bytes, or we use the AttributeType Comparator, if we have an Ordered MatchingRule.
        Specified by:
        compareTo in interface Comparable<Value>
        Parameters:
        other - The other Value we want to compare the current value with
        Returns:
        a positive value if the current value is above the provided value, a negative value if it's below, 0 if they are equal.
        Throws:
        IllegalStateException - on failures to extract the comparator, or the normalizers needed to perform the required comparisons based on the schema