Class Property

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

public class Property extends Object implements DefaultValueGetter
Represents a property with a key and a value.
The key and the value are both strings.
The value can be parsed to different types using the methods provided by this class.
  • Field Details

    • key

      private final String key
      The key of the property.
    • value

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

    • Property

      protected Property(@NotNull @NotNull String key, @NotNull @NotNull String value)
      Constructs a new property with the given key and value.
      Parameters:
      key - The key of the property
      value - The value of the property
      Throws:
      NullPointerException - If the key or the value is null
  • Method Details

    • of

      @NotNull public static @NotNull Property of(@NotNull @NotNull String key, @NotNull @NotNull String value)
      Creates a new property with the given key and value.
      Parameters:
      key - The key of the property
      value - The value of the property
      Returns:
      A new property
      Throws:
      NullPointerException - If the key or the value is null
    • getKey

      @NotNull public @NotNull String getKey()
      Returns the key of the property as a string.
      Returns:
      The key of the property
    • getRawValue

      @NotNull public @NotNull String getRawValue()
      Returns the value of the property as a string.
      Returns:
      The value of the property
    • getAsString

      @NotNull public @NotNull String getAsString()
      Returns the value which is hold by this object as a string.
      This method is equivalent to getRawValue().
      Specified by:
      getAsString in interface ValueGetter
      Returns:
      The value of the property
    • isPartOfGroup

      public boolean isPartOfGroup(@Nullable @Nullable String group)
      Returns whether the key of the property is part of the given group.
      A group is a string that ends optionally with a dot.
      If the group is empty, the key is always part of the group.
      Null will be treated as an empty string.

      Examples:

      
       Property property = Property.of("this.is.an.example.key", "value");
       property.isPartOfGroup(null); // true
       property.isPartOfGroup(""); // true
       property.isPartOfGroup("this"); // true
       property.isPartOfGroup("this.is"); // true
       property.isPartOfGroup("this.is.an.example.key"); // false -> 'key' is not part of the group, it is the key itself
       property.isPartOfGroup("some.other.group"); // false
       
      Parameters:
      group - The group to check
      Returns:
      Whether the key is part of the group or not
      Throws:
      IllegalArgumentException - If the group is blank or starts with a dot
    • equals

      public boolean equals(Object object)
      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(@NotNull @NotNull PropertyConfig config)
      Returns the property as a string with the given configuration.
      Parameters:
      config - The configuration to use
      Returns:
      The property as a string
      Throws:
      NullPointerException - If the configuration is null