Class MutableAttributeImpl

java.lang.Object
com.vladsch.flexmark.util.html.MutableAttributeImpl
All Implemented Interfaces:
Attribute, MutableAttribute, Immutable<Attribute,MutableAttribute>, Mutable<MutableAttribute,Attribute>

public class MutableAttributeImpl extends Object implements MutableAttribute
  • Field Details

    • name

      private final String name
    • valueListDelimiter

      private final char valueListDelimiter
    • valueNameDelimiter

      private final char valueNameDelimiter
    • value

      private String value
    • values

      private LinkedHashMap<String,String> values
  • Constructor Details

    • MutableAttributeImpl

      private MutableAttributeImpl(CharSequence name, CharSequence value, char valueListDelimiter, char valueNameDelimiter)
  • Method Details

    • getValueListDelimiter

      public char getValueListDelimiter()
      Specified by:
      getValueListDelimiter in interface Attribute
    • getValueNameDelimiter

      public char getValueNameDelimiter()
      Specified by:
      getValueNameDelimiter in interface Attribute
    • toImmutable

      public Attribute toImmutable()
      Specified by:
      toImmutable in interface Mutable<MutableAttribute,Attribute>
    • toMutable

      public MutableAttribute toMutable()
      Specified by:
      toMutable in interface Immutable<Attribute,MutableAttribute>
    • copy

      public MutableAttribute copy()
      Specified by:
      copy in interface MutableAttribute
    • getName

      public String getName()
      Specified by:
      getName in interface Attribute
    • getValue

      public String getValue()
      Specified by:
      getValue in interface Attribute
    • resetToValuesMap

      public void resetToValuesMap()
    • getValueMap

      protected Map<String,String> getValueMap()
    • valueFromMap

      protected String valueFromMap()
      Return the attribute value string by splicing the values of the map using valueListDelimiter and valueNameDelimiter with replacements of the given name/value if provided. If the name is not empty and value is empty then this will be removed from the final string
      Returns:
      string for value of this attribute from map
    • isNonRendering

      public boolean isNonRendering()
      Specified by:
      isNonRendering in interface Attribute
    • replaceValue

      public MutableAttributeImpl replaceValue(CharSequence value)
      Description copied from interface: Attribute
      Replace the complete value of this attribute by a new value
      Specified by:
      replaceValue in interface Attribute
      Specified by:
      replaceValue in interface MutableAttribute
      Parameters:
      value - new value
      Returns:
      new attribute or same attribute if nothing changed or attribute is mutable
    • setValue

      public MutableAttributeImpl setValue(CharSequence value)
      Description copied from interface: Attribute
      Add a new value or values depending on list and name delimiter settings and value content

      If the attribute does not have a list delimiter then its value will be set to the given value.

      If the attribute has a list delimiter but not name delimiter then value will be split by list delimiter and all values will be added to the attribute's value list. New ones added at the end, old ones left as is.

      If the attribute has a list delimiter and a name delimiter then value will be split by list delimiter and the name portion of each value will be used to find duplicates whose value will be replaced. New ones added at the end, old ones left where they are but with a new value.

      Specified by:
      setValue in interface Attribute
      Specified by:
      setValue in interface MutableAttribute
      Parameters:
      value - value or list of values (if attribute has a list delimiter and name delimiter) to change
      Returns:
      new attribute or same attribute if nothing changed or attribute is mutable
    • forEachValue

      private void forEachValue(CharSequence value, BiConsumer<String,String> consumer)
    • removeValue

      public MutableAttributeImpl removeValue(CharSequence value)
      Description copied from interface: Attribute
      Add a new value or values depending on list and name delimiter settings and value content.

      If the attribute does not have a list delimiter and its value is equal to the given value then its value is set to empty

      If the attribute has a list delimiter but not name delimiter then value will be split by list delimiter and any values in attribute's value list will be removed

      If the attribute has a list delimiter and a name delimiter then value will be split by list delimiter and only the name portion of each value will be used for removal from the attribute's value list

      Specified by:
      removeValue in interface Attribute
      Specified by:
      removeValue in interface MutableAttribute
      Parameters:
      value - value or list of values (if attribute has a list delimiter and name delimiter) to remove
      Returns:
      new attribute or same attribute if nothing changed or attribute is mutable
    • containsValue

      public boolean containsValue(CharSequence value)
      Description copied from interface: Attribute
      See if the attribute contains the value (if attribute has list delimiter set) or is equal to the value if no list delimiter is set
      Specified by:
      containsValue in interface Attribute
      Specified by:
      containsValue in interface MutableAttribute
      Parameters:
      value - name part of the attribute value list or the value if the attribute does not have a value list delimiter
      Returns:
      true if the attribute contains the valueName
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • of

      public static MutableAttributeImpl of(Attribute other)
    • of

      public static MutableAttributeImpl of(CharSequence attrName)
    • of

      public static MutableAttributeImpl of(CharSequence attrName, CharSequence value)
    • of

      public static MutableAttributeImpl of(CharSequence attrName, CharSequence value, char valueListDelimiter)
    • of

      public static MutableAttributeImpl of(CharSequence attrName, CharSequence value, char valueListDelimiter, char valueNameDelimiter)