-
Notifications
You must be signed in to change notification settings - Fork 35
Integer representation specification #182
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
Changes from all commits
d6d09da
a0fd6a7
ac4128c
d2be9ba
b98e2ae
c8d4cf8
bdc72d2
22d517b
bd96c63
374a877
47249bb
a02d37b
f02f57d
fba4cc5
3bdb545
d288bb8
a259562
64aa206
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package com.helger.jcodemodel.literals; | ||
|
|
||
| import org.jspecify.annotations.NonNull; | ||
|
|
||
| /// Something that has an IntegerRepresentation to update, in practice only JAtomInt and JAtomLong | ||
| /// | ||
| /// Its abstract because it's just a tooling class to extend. | ||
| /// | ||
| /// @param T must be declaring class, eg `class A extends AIntegerRepresented<A>` | ||
| public abstract class AIntegerRepresented <T extends AIntegerRepresented <T>> | ||
| { | ||
|
|
||
| @NonNull | ||
| protected IntegerRepresentation representation = IntegerRepresentation.DEFAULT; | ||
|
|
||
| @SuppressWarnings ("unchecked") | ||
| protected T self () | ||
| { | ||
| return (T) this; | ||
| } | ||
|
|
||
| @NonNull | ||
| public IntegerRepresentation representation () | ||
| { | ||
| return representation; | ||
| } | ||
|
|
||
| /// change the internal representation to the provided one | ||
| /// | ||
| /// @return this | ||
| /// @param representation if null, nothing changes. | ||
| public @NonNull T representation (IntegerRepresentation representation) | ||
| { | ||
| if (representation != null) | ||
| this.representation = representation; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, representation is
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then I'd prefer a "if (null) throw" with the parameter - to make sure the contract of the method is clear |
||
| return self (); | ||
| } | ||
|
|
||
| /// change the internal representation to show positive sign | ||
| /// | ||
| /// @return this | ||
| public @NonNull T positiveSign (boolean positiveSign) | ||
| { | ||
| return representation (representation.positiveSign (positiveSign)); | ||
| } | ||
|
|
||
| /// change the internal representation to use binary base | ||
| /// | ||
| /// @return this | ||
| public @NonNull T binary () | ||
| { | ||
| return representation (representation.base (EIntegerBase.BINARY)); | ||
| } | ||
|
|
||
| /// change the internal representation to use decimal base | ||
| /// | ||
| /// @return this | ||
| public @NonNull T decimal () | ||
| { | ||
| return representation (representation.base (EIntegerBase.DECIMAL)); | ||
| } | ||
|
|
||
| /// change the internal representation to use hexadecimal base | ||
| /// | ||
| /// @return this | ||
| public @NonNull T hexadecimal () | ||
| { | ||
| return representation (representation.base (EIntegerBase.HEXADECIMAL)); | ||
| } | ||
|
|
||
| /// change the internal representation to use octal base | ||
| /// | ||
| /// @return this | ||
| public @NonNull T octal () | ||
| { | ||
| return representation (representation.base (EIntegerBase.OCTAL)); | ||
| } | ||
|
|
||
| /// change the internal representation to use a fixed separator size (the number of character | ||
| /// BETWEEN | ||
| /// each separated group), used only when **NO** separator format is provided | ||
| /// | ||
| /// @return this | ||
| public @NonNull T separatorSize (int size) | ||
| { | ||
| return representation (representation.separatorSize (size)); | ||
| } | ||
|
|
||
| /// change the internal representation to use a fixed separator distance (the maximum number of | ||
| /// character IN | ||
| /// a separated group), used only when **NO** separator format is provided | ||
| /// | ||
| /// @return this | ||
| public @NonNull T separateEvery (int every) | ||
| { | ||
| return representation (representation.separateEvery (every)); | ||
| } | ||
|
|
||
| /// change the internal representation to use a padding value. The padding is not used for decimal | ||
| /// base, since leading "0" makes an octal. | ||
| /// | ||
| /// @return this | ||
| public @NonNull T padding (int padding) | ||
| { | ||
| return representation (representation.padding (padding)); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer the annotations on the method return types and method parameters. If not, then not
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean add
@NonNullon the return ? Sure. Can you do it, or I do it ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is too cumbersome for you, let me know