Parsing RxJava string with type change

Question:

We take a string from the queue, parse it and check if it meets the requirements. If it matches, then we send it to the corresponding method for processing, but it is no longer a string that needs to be returned, but an array of strings that was obtained as a result of parsing .split

We take from the queue and parse .. ((filterLog) underlined in red)

Observable<String> logObservable =
        Observable.from(sQueueOfUnprocessedLogs).filter(filterLog);

filter

 Func1<String, String[]> filterLog = new Func1<String, String[]>() {

    @Override
    public String[] call(String str) {
        String[] parsedLog = str.split("\\|");
            if (mDebugType.contains(parsedLog[VALIDATION])) {
                return parsedLog;
            }
        return null;
    }
};

Observer

 Observer<String[]> observer = new Observer<String[]>() {
    @Override
    public void onCompleted() {

    }

    @Override
    public void onError(Throwable e) {

    }

    @Override
    public void onNext(String[] parsedLog) {
        formingPOJO(parsedLog);
    }
};

You need to get an array, not a string

Answer:

add at the end of .toList() to get it

Observable<String> logObservable = Observable.from(sQueueOfUnprocessedLogs)
    .filter(filterLog)
    .toList();

then the result will be an array of strings

Scroll to Top
AllEscort