Interface MemberCursor<N>

Type Parameters:
N - the node type of the model

public interface MemberCursor<N>

Walks the members of one object, in order: the result of JsonModel.memberCursor(Object).

A cursor is for one walk, by one thread. It makes no list of the members and no Property for each member, so a walk of a large object allocates almost nothing:

for (MemberCursor<N> cursor = model.memberCursor(object); cursor.next(); ) {
    use(cursor.name(), cursor.value());
}
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the name of the current member.
    boolean
    Moves to the next member.
    static <N> MemberCursor<N>
    of(Iterable<Property<N>> properties)
    Returns a cursor over a sequence of properties.
    Returns the value of the current member.
  • Method Details

    • next

      boolean next()
      Moves to the next member.
      Returns:
      true if the cursor is on a member; false at the end, and for each later call
    • name

      JsonString name()

      Returns the name of the current member. Call it only after next() returned true.

      The caller can keep the name after the cursor moves, for example in a Normalized Path, so a model must not change a name that it gave.

      Returns:
      the member name
    • value

      N value()
      Returns the value of the current member. Call it only after next() returned true.
      Returns:
      the member value
    • of

      static <N> MemberCursor<N> of(Iterable<Property<N>> properties)

      Returns a cursor over a sequence of properties.

      Use it for a model whose objects are few or small, for example in a test. A model of large objects walks its own representation instead, so that a walk makes no Property for each member.

      Type Parameters:
      N - the node type of the model
      Parameters:
      properties - the members, in order
      Returns:
      a new cursor before the first property