2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.http.internal.transform;
15 import java.util.Arrays;
16 import java.util.List;
17 import java.util.Optional;
18 import java.util.function.Function;
19 import java.util.stream.Collectors;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.core.transform.TransformationService;
26 * The {@link CascadedValueTransformationImpl} implements {@link ValueTransformation for a cascaded set of
29 * @author Jan N. Klug - Initial contribution
32 public class CascadedValueTransformationImpl implements ValueTransformation {
33 private final List<ValueTransformation> transformations;
35 public CascadedValueTransformationImpl(String transformationString,
36 Function<String, @Nullable TransformationService> transformationServiceSupplier) {
37 transformations = Arrays.stream(transformationString.split("∩")).filter(s -> !s.isEmpty())
38 .map(transformation -> new SingleValueTransformation(transformation, transformationServiceSupplier))
39 .collect(Collectors.toList());
43 public Optional<String> apply(String value) {
44 Optional<String> valueOptional = Optional.of(value);
46 // process all transformations
47 for (ValueTransformation transformation : transformations) {
48 valueOptional = valueOptional.flatMap(transformation::apply);