Class DataEntry
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NonNull DataEntryClears the line number and returns a new objectboolean@NonNull CommentDataGets the comments presentgetComments(@NonNull CommentLocation location) Gets the comments present on this entry at the specified location.@Nullable IntegerGets the line number if present@NonNull ObjectgetValue()Gets the value.inthashCode()toString()static booleanvalidateValue(@Nullable Object value) Checks whether the given object is valid as a value.@NonNull DataEntrywithComments(@NonNull CommentData comments) Sets the comments and returns a new object@NonNull DataEntrywithComments(@NonNull CommentLocation location, @NonNull List<@NonNull String> lines) Sets comments at the given location and returns a new object.@NonNull DataEntrywithLineNumber(int lineNumber) Sets the line number and returns a new object@NonNull DataEntrySets the value and returns a new object
-
Constructor Details
-
DataEntry
Creates from a nonnull value.The value must conform to
validateValue(Object). I.e., it must be of a primitive type,String,DataList, orDataTree. Null values are not valid.- Parameters:
value- the value- Throws:
IllegalArgumentException- if the value is not of the canonical types
-
-
Method Details
-
getValue
Gets the value. Guaranteed to be one of the canonical types (seevalidateValue(Object))- Returns:
- the config value
-
withValue
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
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
Clears the line number and returns a new object- Returns:
- a new data entry with no line number set
-
getLineNumber
Gets the line number if present- Returns:
- the line number
-
withComments
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 situatedlines- the comment lines to specify at this location- Returns:
- a new data entry with the comments set
-
getComments
Gets the comments present- Returns:
- the comments
-
getComments
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
-
hashCode
public int hashCode() -
toString
-
validateValue
Checks whether the given object is valid as a value.Values must be one of primitive,
String,DataList, orDataTree. Null values are not valid.- Parameters:
value- the value- Returns:
- true if a valid canonical value, false if not
-