/*
 * Copyright 2015 52°North Initiative for Geospatial Open Source
 * Software GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.n52.iceland.util.action;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



/**
 * @param <A>
 * @author <a href="mailto:c.autermann@52north.org">Christian Autermann</a>
 * @author <a href="mailto:shane@axiomalaska.com">Shane StClair</a>
 * @since 1.0.0
 *
 */
public abstract class CompositeSerialAction<A extends Action> extends CompositeAction<A> {
    private static final Logger LOGGER = LoggerFactory.getLogger(CompositeSerialAction.class);

    @SafeVarargs
    public CompositeSerialAction(A... actions) {
        super(actions);
    }

    @Override
    public void execute() {
        Optional.ofNullable(getActions())
                .map(List::stream)
                .orElseGet(Stream::empty)
                .forEach(action -> {
                    pre(action);
                    LOGGER.debug("Running {}.", action);
                    action.execute();
                    post(action);
                });
    }
}

@@ -727,16 +727,52 @@
 tional;%0A
+import java.util.function.Consumer;%0A
 import j
@@ -1515,72 +1515,71 @@
 ach(
-action -%3E %7B%0A                    pre(action);%0A                   
+((Consumer%3CA%3E) this::pre)%0A                        .andThen(a -%3E
  LOG
@@ -1604,23 +1604,18 @@
  %7B%7D.%22, a
-ction);
+))
 %0A       
@@ -1631,25 +1631,32 @@
     
-action.
+    .andThen(A::
 execute
-();
+)
 %0A   
@@ -1676,39 +1676,32 @@
     
-post(action);%0A                %7D
+    .andThen(this::post)
 );%0A 

use chained consumer