class ArrayContextualPreferenceReducer implements ContextualPreferenceReducer {

    @Override
    public Optional<ContextualPreference> reduce(final List<ContextualPreference> preferences) {
        if (preferences.isEmpty()) {
            return Optional.empty();
        }
        final String mergedValue = preferences.stream()
                .map(ContextualPreference::getValue)
                .flatMap(instanceTypes -> Arrays.stream(instanceTypes.split(DELIMITER)))
                .distinct()
                .collect(Collectors.joining(DELIMITER));
        final ContextualPreference reducedPreference =
                preferences.get(0)
                        .withValue(mergedValue)
                        .withCreatedDate(null)
                        .withResource(null);
        return Optional.of(reducedPreference);
    }

}