Module bus.setting

Class AbstractElement

java.lang.Object
org.miaixz.bus.setting.metric.ini.AbstractElement
All Implemented Interfaces:
Serializable, CharSequence, IniElement
Direct Known Subclasses:
IniCommentService, IniPropertyService, IniSectionService

public abstract class AbstractElement extends Object implements IniElement
an abstract class for IniElement.
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Method Details

    • trim

      protected static String trim(String value)
      trim a value
      Parameters:
      value - char sequence value
      Returns:
      trimmed value
    • valueChanged

      protected abstract String valueChanged(String newValue)
      If the value changed, change the originalValue
      Parameters:
      newValue - when value changes, like setValue(String) or IniElement.setValue(java.util.function.Function)
      Returns:
      new originalValue
    • value

      public String value()

      this element's value. maybe a toString value like comment, a property's value like property or a title value like section .

      Specified by:
      value in interface IniElement
      Returns:
      some value
    • changeValue

      protected void changeValue(String newValue)
      change value.
      Parameters:
      newValue - a new value
    • setValue

      public String setValue(String newValue)
      change this element's value. if you want to DIY how to set value, Recommended to cover changeValue(String) instead of setValue(String)
      Specified by:
      setValue in interface IniElement
      Parameters:
      newValue - a new value
      Returns:
      old value
      See Also:
    • toString

      public String toString()
      Default is originalValue.toString()
      Specified by:
      toString in interface CharSequence
      Specified by:
      toString in interface IniElement
      Overrides:
      toString in class Object
      Returns:
      string value
    • getOriginalValue

      public String getOriginalValue()
      get the original string.
      Specified by:
      getOriginalValue in interface IniElement
      Returns:
      original string value.
    • setOriginalValue

      protected void setOriginalValue(String newOriginalValue)
    • getComment

      public IniComment getComment()
      Description copied from interface: IniElement
      there may be comments at the end of each element. or null. if this element is comment, return null. so, nullable, or see IniElement.getCommentOptional().
      Specified by:
      getComment in interface IniElement
      Returns:
      comment end of the element or null. if element, return null.
      See Also:
    • clearComment

      public void clearComment()
      clear comment (if exists).
      Specified by:
      clearComment in interface IniElement
    • toNoCommentString

      public String toNoCommentString()
      like toString(), without comment value(if exists).
      Specified by:
      toNoCommentString in interface IniElement
      Returns:
      to string value without comment value.
    • toCompleteString

      public String toCompleteString()
      Get complete information. Take sec as an example:section.toString() + all properties.toString() + comment.toString() In general, it is about the same as toString().
      Specified by:
      toCompleteString in interface IniElement
      Returns:
      the string
    • line

      public int line()
      the line number where you are.
      Specified by:
      line in interface IniElement
      Returns:
      line number.
    • length

      public int length()
      Returns the length of this character sequence. The length is the number of 16-bit chars in the sequence.
      Specified by:
      length in interface CharSequence
      Returns:
      the number of chars in this sequence
    • charAt

      public char charAt(int index)
      Returns the char value at the specified index. An index ranges from zero to length() - 1. The first char value of the sequence is at index zero, the next at index one, and so on, as for array indexing.

      If the char value specified by the index is a surrogate, the surrogate value is returned.

      Specified by:
      charAt in interface CharSequence
      Parameters:
      index - the index of the char value to be returned
      Returns:
      the specified char value
      Throws:
      IndexOutOfBoundsException - if the index argument is negative or not less than length()
    • subSequence

      public CharSequence subSequence(int start, int end)
      Returns a CharSequence that is a subsequence of this sequence. The subsequence starts with the char value at the specified index and ends with the char value at index end - 1. The length (in chars) of the returned sequence is end - start, so if start == end then an empty sequence is returned.
      Specified by:
      subSequence in interface CharSequence
      Parameters:
      start - the start index, inclusive
      end - the end index, exclusive
      Returns:
      the specified subsequence
      Throws:
      IndexOutOfBoundsException - if start or end are negative, if end is greater than length(), or if start is greater than end