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

refactor getPrivateStream to allow multiple filter #331

Open
gleizesDor opened this issue Oct 5, 2023 · 0 comments
Open

refactor getPrivateStream to allow multiple filter #331

gleizesDor opened this issue Oct 5, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@gleizesDor
Copy link
Contributor

gleizesDor commented Oct 5, 2023

give predicate as a parameter :

public static Stream<Object> getPrivateStream(List<TPrivate> privates, Predicate<TPrivate> predicate) {
        return privates
                .stream()
                .filter(predicate)
                .map(TAnyContentFromOtherNamespace::getContent)
                .flatMap(List::stream)
                .filter(JAXBElement.class::isInstance)
                .map(JAXBElement.class::cast)
                .filter(Predicate.not(JAXBElement::isNil))
                .map(JAXBElement::getValue);
    }

Refactor all calls to other "getPrivateStream" method

Here is the test :

@Test
    void getPrivate_should_filter() {
        //Given
        Predicate<TPrivate> icdHeaderPredicate = tPrivate -> "COMPAS-SclFileType".equals(tPrivate.getType());
        Predicate<TPrivate> systemVersionPredicate = tPrivate -> "COMPAS-SystemVersion".equals(tPrivate.getType());
        Predicate<TPrivate> predicate = icdHeaderPredicate.or(systemVersionPredicate);

        //When
        Stream<Object> privateStream = PrivateUtils.getPrivateStream(List.of(privateSCD, privateICD), predicate);
        
        //Then
        assertThat(privateStream.toList()).isNotEmpty();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: To do
Development

No branches or pull requests

1 participant