Class DataEntry

java.lang.Object
space.arim.dazzleconf.backend.DataEntry

public final class DataEntry extends Object
A data value, with associated metadata as interoperable with backend formats.

Values must conform to the canonical requirements. That means String, primitives, DataTree, or DataList. Although a DataEntry itself is immutable, its contents may not be, and mutable data lists and mutable data trees are permitted to be the value.

Equality is defined for an entry based on its value. Comments and line numbers are not counted in equality comparisons and hash code. Note that because of the equality properties of float and double, code which checks for equality may not function as expected after data is written and read from an external source.

  • Constructor Details

    • DataEntry

      public DataEntry(@NonNull Object value)
      Creates from a nonnull value.

      The value must conform to validateValue(Object). I.e., it must be of a primitive type, String, DataList, or DataTree. Null values are not valid.

      Parameters:
      value - the value
      Throws:
      IllegalArgumentException - if the value is not of the canonical types
  • Method Details

    • getValue

      @Pure public @NonNull Object getValue()
      Gets the value. Guaranteed to be one of the canonical types (see validateValue(Object))
      Returns:
      the config value
    • withValue

      public @NonNull DataEntry withValue(@NonNull Object value)
      Sets the value and returns a new object
      Parameters:
      value - the value
      Returns:
      a new data entry with the value set
      Throws:
      IllegalArgumentException - if the value is not of the canonical types
    • withLineNumber

      public @NonNull DataEntry withLineNumber(int lineNumber)
      Sets the line number and returns a new object
      Parameters:
      lineNumber - the line number
      Returns:
      a new data entry with the line number set
    • clearLineNumber

      public @NonNull DataEntry clearLineNumber()
      Clears the line number and returns a new object
      Returns:
      a new data entry with no line number set
    • getLineNumber

      @Pure public @Nullable Integer getLineNumber()
      Gets the line number if present
      Returns:
      the line number
    • withComments

      public @NonNull DataEntry withComments(@NonNull CommentData comments)
      Sets the comments and returns a new object
      Parameters:
      comments - the comments
      Returns:
      a new data entry with the comments set
    • withComments

      public @NonNull DataEntry withComments(@NonNull CommentLocation location, @NonNull List<@NonNull String> lines)
      Sets comments at the given location and returns a new object.

      If an empty list is specified, this function will clear the comments at the specified location.

      Parameters:
      location - where the comments are situated
      lines - the comment lines to specify at this location
      Returns:
      a new data entry with the comments set
    • getComments

      @Pure public @NonNull CommentData getComments()
      Gets the comments present
      Returns:
      the comments
    • getComments

      public @NonNull List<@NonNull String> getComments(@NonNull CommentLocation location)
      Gets the comments present on this entry at the specified location.

      The returned value may be immutable, or it may be a mutable copy.

      Parameters:
      location - the location
      Returns:
      the comment lines, or an empty list if none exist
    • equals

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

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

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

      public static boolean validateValue(@Nullable Object value)
      Checks whether the given object is valid as a value.

      Values must be one of primitive, String, DataList, or DataTree. Null values are not valid.

      Parameters:
      value - the value
      Returns:
      true if a valid canonical value, false if not