Record Class Selector.Slice

java.lang.Object
java.lang.Record
ca.marcusdunn.jsonlens.path.core.query.Selector.Slice
Record Components:
start - the start, if the query gives it
end - the end, if the query gives it
step - the step, if the query gives it
All Implemented Interfaces:
Selector
Enclosing interface:
Selector

public static record Selector.Slice(Maybe<Long> start, Maybe<Long> end, Maybe<Long> step) extends Record implements Selector

An array slice selector: start:end:step (Section 2.3.4). It selects the elements from start up to, but not including, end, in increments of step.

Slice Elements of ["a", "b", "c", "d", "e"]
1:3 "b", "c"
:2 "a", "b"
-2: "d", "e"
::2 "a", "c", "e"
::-1 "e", "d", "c", "b", "a"
::0 nothing

The default step is 1. The default start and end depend on the sign of the step.

  • Constructor Details

    • Slice

      public Slice(Maybe<Long> start, Maybe<Long> end, Maybe<Long> step)
      Creates an instance of a Slice record class.
      Parameters:
      start - the value for the start record component
      end - the value for the end record component
      step - the value for the step record component
  • Method Details

    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • start

      public Maybe<Long> start()
      Returns the value of the start record component.
      Returns:
      the value of the start record component
    • end

      public Maybe<Long> end()
      Returns the value of the end record component.
      Returns:
      the value of the end record component
    • step

      public Maybe<Long> step()
      Returns the value of the step record component.
      Returns:
      the value of the step record component