Record Class Range

java.lang.Object
java.lang.Record
net.flectone.pulse.model.value.Range
Record Components:
value - the block radius, or the marker value of the named type
type - which of the two forms this range takes

public record Range(int value, Range.Type type) extends Record
How far a message travels, either a radius in blocks or one of the named scopes such as the whole server or the entire proxy network.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    The named scopes a range can take.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Range(int value)
    Creates a range covering the given radius in blocks.
    Range(int value, Range.Type type)
    Creates an instance of a Range record class.
    Creates a range for one of the named scopes.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    static Range
    fromJson(Object object)
    Reads a range from its config representation, accepting either a block count or a scope name.
    static Optional<Range>
    Parses a range, returning empty instead of throwing when the text is not a valid range.
    static Range
    get(int range)
    Returns a range covering the given radius in blocks.
    static Range
    Returns the shared instance for a named scope.
    final int
    Returns a hash code value for this object.
    boolean
    is(Range.Type type)
    Whether this range uses the given form.
    Writes this range back to its config representation, a number for block ranges and a name otherwise.
    final String
    Returns a string representation of this record class.
    Returns the value of the type record component.
    int
    Returns the value of the value record component.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Range

      public Range(int value, Range.Type type)
      Creates an instance of a Range record class.
      Parameters:
      value - the value for the value record component
      type - the value for the type record component
    • Range

      public Range(int value)
      Creates a range covering the given radius in blocks.
      Parameters:
      value - the radius in blocks, must not be negative
    • Range

      public Range(Range.Type type)
      Creates a range for one of the named scopes.
      Parameters:
      type - the named scope
  • Method Details

    • get

      public static Range get(int range)
      Returns a range covering the given radius in blocks.
      Parameters:
      range - the radius in blocks
      Returns:
      the block range
    • get

      public static Range get(Range.Type type)
      Returns the shared instance for a named scope.
      Parameters:
      type - the named scope, must not be Range.Type.BLOCKS
      Returns:
      the shared range for that scope
      Throws:
      IllegalArgumentException - if Range.Type.BLOCKS is passed, as it has no single default
    • fromJson

      public static Range fromJson(Object object)
      Reads a range from its config representation, accepting either a block count or a scope name.
      Parameters:
      object - the raw config value
      Returns:
      the parsed range
    • fromString

      public static Optional<Range> fromString(String string)
      Parses a range, returning empty instead of throwing when the text is not a valid range.
      Parameters:
      string - the text to parse
      Returns:
      the parsed range, or empty if the text is not recognised
    • toJson

      public Object toJson()
      Writes this range back to its config representation, a number for block ranges and a name otherwise.
      Returns:
      the config value
    • is

      public boolean is(Range.Type type)
      Whether this range uses the given form.
      Parameters:
      type - the form to test
      Returns:
      true if the types match
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • value

      public int value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component
    • type

      public Range.Type type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component