arturmkrtchyan / iban4j

A Java library for generation and validation of the International Bank Account Numbers (IBAN ISO_13616) and Business Identifier Codes (BIC ISO_9362).
http://iban4j.org
Apache License 2.0
270 stars 124 forks source link

IBAN Validation return value #101

Closed guimar86 closed 1 year ago

guimar86 commented 1 year ago

I think this is more of discussion than an issue but could it be possible for the methods of iban validation to return something other than exceptions?

FrankHossfeld commented 1 year ago

Are you talking about the two validate-methods inside the IbanUtils-class? Something like a isValid-method returning a boolean?

guimar86 commented 1 year ago

Yes exactly. As a library it would be best to have method overloads to those validation methods that return either a boolean or a complex object.

FrankHossfeld commented 1 year ago

I like the idea. for me, throwing and catching exceptions is ok, but I prefer validation methods with boolean value. But this is my personal opinion:

I'll open an issue in my repo (which was a fork a long time ago) and will do some coding. I'll leave the existing methods untouched (due to force no one to refactor their code) and create new methods beside. IIRC, the validation class is the same as in this repo. So we can create here a PR later.

guimar86 commented 1 year ago

Thanks

FrankHossfeld commented 1 year ago

I spent some time on a draft. Without change, it behave in the same way as it does today.

In case you prefer a boolean as return value, you need to set:

Iban4gConfig.INSTANCE.setReturnMethod(Iban4gConfig.ReturnMethod.RETURN_VALUE);

This needs to be done once, at the start of the application. Now, it is possible to validate this way (without throwing an exception):

boolean valid = IbanUtil.validate("AT611904300234573201", IbanFormat.Default);

Not sure, if this is the best implementation, but it works.

Note, some exception will continue throwing. F.e.: calculateCheckDigit.

ghost commented 1 year ago

Hi Frank, Thanks for the quick feedback, I will test and feedback asap.

FrankHossfeld commented 1 year ago

@guillenmartins Please, keep in mind, I'll implemented the draft here: https://github.com/NaluKit/iban4g

ghost commented 1 year ago

Okay, I will pull it from there

FrankHossfeld commented 1 year ago

May be it is easier to copy the IbanUtil- and Iban4gConfig-class to a fork of iban4j, fix the package and test that build.

arturmkrtchyan commented 1 year ago

@FrankHossfeld thanks for your help here! I'm really not managing to do anything helpful here. Would you be open to become a collaborator on the project and lead those changes/efforts ?

FrankHossfeld commented 1 year ago

@arturmkrtchyan iban4j is an awesome lib and thanks for offering to become a collaborator. In general, I'll be open becoming a collaborator.

I created iban4g to get iban4j work with Java and GWT/J2CL. I need to replace a few code lines (which are not part of the emulation library) and add a few files. The API itself is unchanged! In a normal Java application there is no change, except that the sources are part of the lib and a XML-file is added to the artifact.Inside a pure Java application iban4g can be used in the same way as iban4j. Also I need add GWT and J2CL Maven test modules to ensure it will work with J2CL and GWT.

iban4g has a lot of fixes and added PRs that are missing in iban4j.

I have only a limited free time to support Open Source and as you can imagine, I don't want to maintain two libraries which does at least the same.

The questions are:

I'll think, that it also question that should be discussed with the users of iban4j.

@arturmkrtchyan Feel free to PM me here: https://gitter.im/Nalukit42/Lobby (using 'chat privately') to discuss further

FrankHossfeld commented 1 year ago

@arturmkrtchyan I suggest to open a discussion here. What do you think?

hajk1 commented 1 year ago

Feature merged onto master and will be released soon