Class XmlAttribute

java.lang.Object
net.luis.utils.io.data.xml.XmlAttribute
All Implemented Interfaces:
DefaultValueGetter, ValueGetter

public class XmlAttribute extends Object implements DefaultValueGetter
Represents an xml attribute.
An xml attribute consists of a name and a value.
The name and the value are both strings.
  • Field Details

    • name

      private final String name
      The name of the attribute.
    • value

      private final String value
      The value of the attribute.
  • Constructor Details

    • XmlAttribute

      public XmlAttribute(@NotNull @NotNull String name, boolean value)
      Constructs a new xml attribute with the given name and boolean value.
      Parameters:
      name - The name of the attribute
      value - The boolean value of the attribute
      Throws:
      IllegalArgumentException - If the name is invalid (e.g. empty, blank, or does not match the pattern XmlHelper.XML_ATTRIBUTE_NAME_PATTERN)
    • XmlAttribute

      public XmlAttribute(@NotNull @NotNull String name, @Nullable @Nullable Number value)
      Constructs a new xml attribute with the given name and number value.
      Parameters:
      name - The name of the attribute
      value - The number value of the attribute
      Throws:
      IllegalArgumentException - If the name is invalid (e.g. empty, blank, or does not match the pattern XmlHelper.XML_ATTRIBUTE_NAME_PATTERN)
    • XmlAttribute

      public XmlAttribute(@NotNull @NotNull String name, @Nullable @Nullable String value)
      Constructs a new xml attribute with the given name and string value.
      The value will be xml-escaped automatically.
      Parameters:
      name - The name of the attribute
      value - The string value of the attribute
      Throws:
      IllegalArgumentException - If the name is invalid (e.g. empty, blank, or does not match the pattern XmlHelper.XML_ATTRIBUTE_NAME_PATTERN)
  • Method Details

    • getName

      @NotNull public @NotNull String getName()
      Returns the name of the attribute.
      Returns:
      The name
    • getRawValue

      @NotNull public @NotNull String getRawValue()
      Returns the raw unescaped value of the attribute.
      Returns:
      The raw value
    • getUnescapedValue

      @NotNull public @NotNull String getUnescapedValue()
      Returns the unescaped value of the attribute.
      Returns:
      The unescaped value
    • getAsString

      @NotNull public @NotNull String getAsString()
      Returns the value which is hold by this object as a string.
      This method is equivalent to getUnescapedValue().
      Specified by:
      getAsString in interface ValueGetter
      Returns:
      The value as a string
    • 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
    • toString

      @NotNull public @NotNull String toString(@Nullable @Nullable XmlConfig config)
      Returns the string representation of the attribute.
      The string representation is in the form of name="value".
      Parameters:
      config - The xml config to use for the string representation (unused)
      Returns:
      The string representation