Skip to content

[Use Case]: zero-based indexing #1447

@gavinking

Description

@gavinking

As a ...

  • Application user/user of the configuration itself
  • API user (application developer)
  • SPI user (container or runtime developer)
  • Specification implementer

I need to be able to ...

count from zero if I feel like it.

Which enables me to ...

pretend I'm Donald Knuth.

Additional information

Folks with CS degrees have a weird fetish for counting from 0 instead of from 1 like mathematicians and other normal people. This came up in #941.

Since Jakarta Data is an inclusive specification, we should consider catering to the needs of both nerds and normies. I would do this not by some 🤮global configuration property (as previously proposed), but rather by exposing both "page numbers" and "page indexes" in the PageRequest interface.

This would involve something the following additions:

    default long index() {
        return page() - 1;
    }

    default PageRequest index(long pageIndex) {
        return page(pageIndex + 1);
    }

    static PageRequest atIndex(long index) {
        return ofPage(index + 1);
    }

    static PageRequest atIndex(long index, int maxPageSize, boolean requestTotal) {
        return ofPage(index + 1, maxPageSize, requestTotal);
    }

Perhaps something similar should be done in Limit.

cc @FroMage

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions