Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ New PositiveInteger type #661

Open
8 tasks
Tracked by #638 ...
LVMVRQUXL opened this issue May 18, 2024 · 1 comment
Open
8 tasks
Tracked by #638 ...

✨ New PositiveInteger type #661

LVMVRQUXL opened this issue May 18, 2024 · 1 comment
Labels
common Item related to all platforms. feature New feature or request.

Comments

@LVMVRQUXL
Copy link
Contributor

LVMVRQUXL commented May 18, 2024

πŸ“ Description

We want to introduce the PositiveInteger experimental type, in the org.kotools.types package of the types subproject, for representing an integer that is greater than zero, with the following Application Programming Interface (API):

interface PositiveInteger {
    override fun equals(other: Any?): Boolean
    override fun hashCode(): Int
    override fun toString(): String
    companion object {
        const val PATTERN: String
        fun orNull(number: Any): PositiveInteger?
        fun orThrow(number: Any): PositiveInteger
        fun random(): PositiveInteger
    }
}

This type should be available for all Kotlin platforms and Java.

The pattern used for validating inputs should be: ^\+?[1-9]\d*$.
Here's the explanation associated to each symbol used in this pattern:

  • ^ Beginning. Matches the beginning of the string, or the beginning of a line if the multiline flag (m) is enabled.
  • \+ Escaped character. Matches a "+" character (char code 43).
  • ? Quantifier. Match between 0 and 1 of the preceding token.
  • [] Character set. Matches any character in the set.
  • 1-9 Range. Matches a character in the range "1" to "9" (char code 49 to 57). Case sensitive.
  • \d Digit. Matches any digit character (0-9).
  • * Quantifier. Match 0 or more of the preceding token.
  • $ End. Matches the end of the string, or the end of a line if the multiline flag (m) is enabled.

βœ… Checklist

  • ✨ Add the type with documentation.
  • ✨ Add the PATTERN property with tests, documentation and samples.
  • ✨ Add the orThrow(Any) function with tests, documentation and samples.
  • ✨ Add the orNull(Any) function with tests, documentation and samples.
  • ✨ Add the random() function with tests, documentation and samples.
  • ✨ Add the structural equality operations (equals(Any?) and hashCode() functions) with tests, documentation and samples.
  • ✨ Add the toString() function with tests, documentation and samples.
  • πŸ“ Update the unreleased changelog for this issue.
@LVMVRQUXL LVMVRQUXL added feature New feature or request. common Item related to all platforms. labels May 18, 2024
@LVMVRQUXL LVMVRQUXL modified the milestone: 4.6.0 May 21, 2024
@LVMVRQUXL LVMVRQUXL added this to the 4.6.0 milestone Jun 7, 2024
@LVMVRQUXL LVMVRQUXL assigned LVMVRQUXL and unassigned LVMVRQUXL Jun 7, 2024
@LVMVRQUXL LVMVRQUXL assigned LVMVRQUXL and unassigned LVMVRQUXL Jun 11, 2024
@LVMVRQUXL LVMVRQUXL removed this from the 4.6.0 milestone Jun 20, 2024
@LVMVRQUXL LVMVRQUXL added this to the 4.5.3 milestone Jul 8, 2024
@LVMVRQUXL
Copy link
Contributor Author

The PositiveInteger.Companion.random() function should use the widest range available, like the Long type's range, for producing a random value.

@LVMVRQUXL LVMVRQUXL modified the milestones: 4.5.3, 4.5.5, 4.5.6 Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Item related to all platforms. feature New feature or request.
Projects
None yet
Development

No branches or pull requests

1 participant