com-pas/compas-sct

refactor getPrivateStream to allow multiple filter

Opened this issue · 0 comments

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();
    }