/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 nl.armatiek.xslweb.pipeline;

import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

import javax.servlet.http.HttpServletRequest;

public class PipelineStepIterator<T> implements Iterator<PipelineStep> {
  
  private List<PipelineStep> pipelineSteps;
  private HttpServletRequest request;
  private int index = 0;
  
  public PipelineStepIterator(final List<PipelineStep> pipelineSteps, final HttpServletRequest request) {
    this.pipelineSteps = pipelineSteps;
    this.request = request;
  }

  @Override
  public boolean hasNext() {
    return pipelineSteps.size() > index;
  }

  @Override
  public PipelineStep next() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    PipelineStep nextPipelineStep = pipelineSteps.get(index);
    if (nextPipelineStep instanceof ConditionalPipelineStep) {
      List<PipelineStep> evaluatedSteps = ((ConditionalPipelineStep) nextPipelineStep).evaluatePipelineSteps(request); 
      pipelineSteps.remove(index);
      pipelineSteps.addAll(index, evaluatedSteps);
      return pipelineSteps.get(index++);
    } else {
      index++;
      return nextPipelineStep;
    }
  }
  
} /*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 nl.armatiek.xslweb.pipeline;

import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

import javax.servlet.http.HttpServletRequest;

public class PipelineStepIterator implements Iterator<PipelineStep> {
  
  private List<PipelineStep> pipelineSteps;
  private HttpServletRequest request;
  private int index = 0;
  
  public PipelineStepIterator(final List<PipelineStep> pipelineSteps, final HttpServletRequest request) {
    this.pipelineSteps = pipelineSteps;
    this.request = request;
  }

  @Override
  public boolean hasNext() {
    return pipelineSteps.size() > index;
  }

  @Override
  public PipelineStep next() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    PipelineStep nextPipelineStep = pipelineSteps.get(index);
    if (nextPipelineStep instanceof ConditionalPipelineStep) {
      List<PipelineStep> evaluatedSteps = ((ConditionalPipelineStep) nextPipelineStep).evaluatePipelineSteps(request); 
      pipelineSteps.remove(index);
      pipelineSteps.addAll(index, evaluatedSteps);
      return pipelineSteps.get(index++);
    } else {
      index++;
      return nextPipelineStep;
    }
  }
  
} 
@@ -1,1994 +1,4 @@
-/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage nl.armatiek.xslweb.pipeline;%0A%0Aimport java.util.Iterator;%0Aimport java.util.List;%0Aimport java.util.NoSuchElementException;%0A%0Aimport javax.servlet.http.HttpServletRequest;%0A%0Apublic class PipelineStepIterator%3CT%3E implements Iterator%3CPipelineStep%3E %7B%0A  %0A  private List%3CPipelineStep%3E pipelineSteps;%0A  private HttpServletRequest request;%0A  private int index = 0;%0A  %0A  public PipelineStepIterator(final List%3CPipelineStep%3E pipelineSteps, final HttpServletRequest request) %7B%0A    this.pipelineSteps = pipelineSteps;%0A    this.request = request;%0A  %7D%0A%0A  @Override%0A  public boolean hasNext() %7B%0A    return pipelineSteps.size() %3E index;%0A  %7D%0A%0A  @Override%0A  public PipelineStep next() %7B%0A    if (!hasNext()) %7B%0A      throw new NoSuchElementException();%0A    %7D%0A    PipelineStep nextPipelineStep = pipelineSteps.get(index);%0A    if (nextPipelineStep instanceof ConditionalPipelineStep) %7B%0A      List%3CPipelineStep%3E evaluatedSteps = ((ConditionalPipelineStep) nextPipelineStep).evaluatePipelineSteps(request); %0A      pipelineSteps.remove(index);%0A      pipelineSteps.addAll(index, evaluatedSteps);%0A      return pipelineSteps.get(index++);%0A    %7D else %7B%0A      index++;%0A      return nextPipelineStep;%0A    %7D%0A  %7D%0A  %0A%7D 
 /*%0A 

Repair after merge conflict