Here there is such a method that I use in order to make a pars immediately in the enam when I receive a response from the server
@JsonCreator public static eTaxCode getTaxCodeByIdOrDefault(int iTaxCode) { eTaxCode result = DEFAULT; for (eTaxCode tmp : eTaxCode.values()) { if (tmp.getTaxCodeId() == iTaxCode) { result = tmp; break; } } return result; } Everything is simple, I take the enam values ​​for each and if there is a match, then return this value if not, then return the default value.
Now I want to do the same with RxJava2 (I know that maybe this is not the case and that the standard approach is very cool, but it's interesting to understand how to do it)
I tried to do something like this (on the same example)
@JsonCreator public static eSingDetails getSingDetails(int iSignDtls) { eSingDetails result = DEFAULT; Observable.fromArray(eSingDetails.values())// .filter(iValue -> iValue.getSignDtls() == iSignDtls)// .isEmpty()// .subscribe(iIsEmpty -> { if (iIsEmpty) { } else { } }); return result; } But still not what it turns out ...
How to do it right?
eSingDetails, but an observable that is wrapped around it:Observable<eSingDetails>(or Flowable, Single, etc. depending on the task) so that you can use it further in the Rx chain , or just subscribe to the right place. But I would not do that. Any technology is only a tool, and they need to be used in the places intended for it. And the nails, as you know, can be hammered with a microscope. - eugeneek