-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add Quantity type #129
Add Quantity type #129
Conversation
Thanks for the PR! some small nits, but looks good to me. |
@@ -0,0 +1,56 @@ | |||
package io.kubernetes.client.custom; | |||
|
|||
public class BaseExponent { |
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.
JavaDoc?
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.
Happy to add JavaDoc - to clarify, this is an across the board ask rather than just for BaseExponent
?
private final int base; | ||
|
||
private final int exponent; | ||
|
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.
Line spacing is weird here. preference for:
private final int base;
private final int exponent;
...
public BaseExponent(...) {
...
|
||
BaseExponent that = (BaseExponent) o; | ||
|
||
if (base != that.base) return false; |
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.
nit: Preference for:
return base == that.base && exponent == that.exponent && format == that.format;
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.
Ironically, in its own auto-generated code, IntelliJ suggests this quick fix.
|
||
@Override | ||
public int hashCode() { | ||
int result = base; |
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.
This is funky, and I'm not entirely sure that it is correct. (or at least I don't understand why it is correct...
Why not:
this.toString().hashCode();
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 must confess that this was entirely auto-generated by IntelliJ, however, I don't see any error in it.
Given our use case, I think we can happily use this.toString().hashCode()
as the cost is not prohibitive to us and it will be more future proof in the case of adding or removing fields.
@@ -0,0 +1,20 @@ | |||
package io.kubernetes.client.custom; | |||
|
|||
public class Pair<L, R> { |
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.
We already depend on apache-commons, rev the version to 3.0 and use the Pair implementation from there?
this.format = format; | ||
} | ||
|
||
public BigDecimal getBigDecimal() { |
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.
nit: getNumber
?
LGTM, JavaDoc can wait (but yes, for all classes would be great, but I realized we haven't really done a good job of that in general, so don't want to hold this PR on that...) |
没有说明,根本不知道单位,建议加上java doc或者demo |
@@ -1,109 +1,109 @@ | |||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
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.
pom.xml is reformatted. hard to locate changes.
Adds an implementation of Kubernetes Quantity handling in the Java client.
This allows users to interact with
Quantity
s as their raw value without having to parse units (e.g.1024
instead of1Ki
,1000
instead of1e3
,0.001
instead of1m
). This is helpful for example when you submit a value like1024Mi
and the Kubernetes API will return1Gi
. You cannot reliably manipulate the string without parsing it.This
Quantity
implementation gives you an object containing itsBigDecimal
value and the format of the suffix (e.g.DECIMAL_SI
,BINARY_SI
, orDECIMAL_EXPONENT
) when parsed or the desired format to be written. Using this normalized form you can then manipulate theBigDecimal
representation and use theQuantity
implementation to re-serialize it in the appropriate notation.A PR will also be needed to
gen
to make the Swagger pre-processor not turnQuantity
into aString
but map it to this class.Quantities are complex, to say the least, in Kubernetes but thanks to some guidance from @lavalamp and a lot of time in the Go Debugger, I think this behaves pretty accurately.