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

add BigIntegerConverter #308

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

add BigIntegerConverter #308

wants to merge 4 commits into from

Conversation

arnzel
Copy link

@arnzel arnzel commented Nov 16, 2018

Add Converter for BigInteger

@zapodot
Copy link
Collaborator

zapodot commented Nov 20, 2018

@arnzel Thank you for your contribution. As we try to improve our test coverage we require all PR-s to include tests. Can you please add some and update this PR?

@arnzel
Copy link
Author

arnzel commented Nov 20, 2018

yes sure

@arnzel
Copy link
Author

arnzel commented Nov 21, 2018

@zapodot : i added some tests and library assertJ for better failing errors

@zapodot
Copy link
Collaborator

zapodot commented Nov 21, 2018

@arnzel I see from your commit that you have added a dependency on AssertJ. Any chance you could use the basic JUnit assertions instead? Thanks again for you contribution 👍


import java.math.BigInteger;

public class BigIntegerConverterTest {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test where you try to convert a null value?

@arnzel
Copy link
Author

arnzel commented Nov 21, 2018

@arnzel I see from your commit that you have added a dependency on AssertJ. Any chance you could use the basic JUnit assertions instead? Thanks again for you contribution

well i can do it,but i dont like JUNIt Assertions like "assertEquals" and "assertTrue". they only tell you somethig like "expected true but was false".AssertJ gives you much more information and is better maintained like other matching libraries like hamcrest

@zapodot
Copy link
Collaborator

zapodot commented Nov 21, 2018 via email

@arnzel
Copy link
Author

arnzel commented Nov 22, 2018

@zapodot okay i removed assertJ and use hamcrest matchers. also i added converting null values

@arnzel
Copy link
Author

arnzel commented Nov 22, 2018

@zapodot : i dont understand travic ci test error, is it related to my change ?

@zapodot
Copy link
Collaborator

zapodot commented Nov 23, 2018

@arnzel we are experiencing some weird behaviour in our builds right now. Will await merge before until we have a green master branch. Good job!

Copy link

@nryanov nryanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that in cases when we want to get BigInteger instance from Number or String we need to use number.longValue() or Long.parseLong(str) to save precision, otherwise, if number exceeds the MAX_INT then after conversion we'll lose initial value

Thank you for your work!

return (BigInteger)number;
}
else{
return BigInteger.valueOf(number.intValue());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is seems that number.longValue() would be better than number.intValue(). Otherwise you can lost precision.
Also, it's more native to use long than int when you want to get BigInteger

@Override
protected BigInteger convertStringValue(String string) {
if(null != string) {
return BigInteger.valueOf(Integer.parseInt(string));
Copy link

@nryanov nryanov Jan 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Long.parseLong(...) would be better or, maybe, there is another even better option?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants